Skip to content

Commit

Permalink
update cherryusb to v1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sakumisu committed Jan 14, 2025
1 parent 7e7c539 commit e8c779f
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 917 deletions.
26 changes: 7 additions & 19 deletions examples/cherryusb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,16 @@ include(proj.conf)

find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE})

sdk_add_compile_definitions(-DCONFIG_USBHOST_PLATFORM_CDC_ECM)
sdk_add_compile_definitions(-DCONFIG_USBHOST_PLATFORM_CDC_NCM)
sdk_add_compile_definitions(-DCONFIG_USBHOST_PLATFORM_CDC_RNDIS)
sdk_add_compile_definitions(-DCONFIG_USBHOST_PLATFORM_ASIX)
sdk_add_compile_definitions(-DCONFIG_USBHOST_PLATFORM_RTL8152)
sdk_add_include_directories(.)

set(CONFIG_CHERRYUSB_HOST 1)
set(CONFIG_CHERRYUSB_HOST_CDC_ACM 1)
set(CONFIG_CHERRYUSB_HOST_CDC_ECM 1)
set(CONFIG_CHERRYUSB_HOST_CDC_NCM 1)
set(CONFIG_CHERRYUSB_HOST_HID 1)
set(CONFIG_CHERRYUSB_HOST_MSC 1)
set(CONFIG_CHERRYUSB_HOST_VIDEO 1)
set(CONFIG_CHERRYUSB_HOST_AUDIO 1)
set(CONFIG_CHERRYUSB_HOST_CDC_RNDIS 1)
set(CONFIG_CHERRYUSB_HOST_BLUETOOTH 1)
set(CONFIG_CHERRYUSB_HOST_ASIX 1)
set(CONFIG_CHERRYUSB_HOST_RTL8152 1)
set(CONFIG_CHERRYUSB_OSAL "freertos")
set(CONFIG_CHERRYUSB_HOST_HCD "ehci_bouffalo")
target_sources(app PRIVATE usb_host.c cherryusb/demo/video_static_mjpeg_template.c)

include(cherryusb/cherryusb.cmake)
target_sources(app PRIVATE ${cherryusb_srcs})
sdk_add_include_directories(${cherryusb_incs})

target_sources(app PRIVATE usb_host.c)
add_subdirectory(cherryusb)
sdk_set_main_file(main.c)
sdk_set_linker_script(bl616_flash.ld)
project(cherryusb)
5 changes: 3 additions & 2 deletions examples/cherryusb/bl616_flash.ld
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ SECTIONS
__nocache_noinit_ram_data_end__ = .;
} > ram_nocache

/* Skip the nocache region */
/* Skip the nocache region */
.ram_skip_nocache_region (NOLOAD) :
{
. += (__nocache_noinit_ram_data_end__ - ORIGIN(ram_nocache));
Expand All @@ -171,6 +171,7 @@ SECTIONS
. = ALIGN(4);
__tcm_code_start__ = .;

*(.fast*)
*(.tcm_code.*)
*(.tcm_const.*)
*(.sclock_rlt_code.*)
Expand Down Expand Up @@ -345,7 +346,7 @@ SECTIONS

__psram_limit = ORIGIN(ram_psram) + LENGTH(ram_psram);
ASSERT(__psram_limit - __psram_heap_base >= psram_heap_min_size, "psram heap region overflow")

.wifibss (NOLOAD) :
{
PROVIDE( __wifi_bss_start = ADDR(.wifibss) );
Expand Down
2 changes: 1 addition & 1 deletion examples/cherryusb/cherryusb
Submodule cherryusb updated 369 files
11 changes: 6 additions & 5 deletions examples/cherryusb/lwipopts_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@
/* Controls if TCP should queue segments that arrive out of
order. Define to 0 if your device is low on memory
*/
#define TCP_QUEUE_OOSEQ 0
#define TCP_QUEUE_OOSEQ 1

/* TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work.
*/
#define TCP_SND_QUEUELEN (4* TCP_SND_BUF/TCP_MSS)

/* TCP receive window. */
#define TCP_WND (2*TCP_MSS)
#define TCP_WND (16*TCP_MSS)

/*
* -----------------------------------
Expand Down Expand Up @@ -181,18 +181,19 @@
* ---------------------------------
*/

#define TCPIP_THREAD_NAME "TCP/IP"
#define TCPIP_THREAD_NAME "tcpip"
#define TCPIP_THREAD_STACKSIZE 1500
#define TCPIP_MBOX_SIZE 64
#define DEFAULT_RAW_RECVMBOX_SIZE 1000
#define DEFAULT_UDP_RECVMBOX_SIZE 100
#define DEFAULT_TCP_RECVMBOX_SIZE 100
#define DEFAULT_ACCEPTMBOX_SIZE 1500
#define DEFAULT_THREAD_STACKSIZE 500
#define TCPIP_THREAD_PRIO 0
#define TCPIP_THREAD_PRIO 31
#define LWIP_SINGLE_NETIF 1
#define LWIP_COMPAT_MUTEX 0

#define LWIP_TCPIP_CORE_LOCKING_INPUT 1
#define LWIP_TCPIP_CORE_LOCKING 1

#endif /* __LWIPOPTS_H__ */
#endif /* __LWIPOPTS_H__ */
21 changes: 19 additions & 2 deletions examples/cherryusb/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "bflb_uart.h"
#include "board.h"
#include "shell.h"
#include "lwip/tcpip.h"

extern void usbh_class_test(void);

Expand All @@ -18,9 +19,11 @@ int main(void)
uart0 = bflb_device_get_by_name("uart0");
shell_init_with_task(uart0);

/* Initialize the LwIP stack */
tcpip_init(NULL, NULL);

printf("Starting usb host task...\r\n");
usbh_initialize(0, 0x20072000);
usbh_class_test();

vTaskStartScheduler();

Expand Down Expand Up @@ -49,4 +52,18 @@ SHELL_CMD_EXPORT_ALIAS(lsusb, lsusb, ls usb);

extern int bluetooth_demo_init(int argc, char **argv);

SHELL_CMD_EXPORT_ALIAS(bluetooth_demo_init, bluetooth_demo_init, ls usb);
SHELL_CMD_EXPORT_ALIAS(bluetooth_demo_init, bluetooth_demo_init, ls usb);
int uvcinit(int argc, char **argv)
{
video_init(0, 0x20072000);
return 0;
}
SHELL_CMD_EXPORT_ALIAS(uvcinit, uvcinit, uvcinit);

int uvcsend(int argc, char **argv)
{
extern void video_test(uint8_t busid);
video_test(0);
return 0;
}
SHELL_CMD_EXPORT_ALIAS(uvcsend, uvcsend, uvcsend);
5 changes: 4 additions & 1 deletion examples/cherryusb/proj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ set(CONFIG_FREERTOS 1)
#set(CONFIG_CHERRYUSB_HOST 1)
#set(CONFIG_CHERRYUSB_HOST_ECM 1)

set(CONFIG_PSRAM 1)
set(CONFIG_FATFS 1)
set(CONFIG_FATFS_USBH 1)

set(CONFIG_LWIP 1)
set(CONFIG_PING 1)
set(CONFIG_SHELL 1)
#set(CONFIG_IPERF 1)
set(CONFIG_IPERF 0)
set(CONFIG_CHERRYMP 1)
set(CONFIG_CHERRYRB 1)
138 changes: 119 additions & 19 deletions examples/cherryusb/usb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@
#ifndef CHERRYUSB_CONFIG_H
#define CHERRYUSB_CONFIG_H

#define CHERRYUSB_VERSION 0x010100
#define CHERRYUSB_VERSION_STR "v1.1.0"

/* ================ USB common Configuration ================ */

#define CONFIG_USB_PRINTF(...) printf(__VA_ARGS__)

#define usb_malloc(size) malloc(size)
#define usb_free(ptr) free(ptr)

#ifndef CONFIG_USB_DBG_LEVEL
#define CONFIG_USB_DBG_LEVEL USB_DBG_INFO
#endif
Expand All @@ -33,14 +27,19 @@

/* ================= USB Device Stack Configuration ================ */

#define CONFIG_USBDEV_MAX_BUS 1 // for now, bus num must be 1 except hpm ip

/* Ep0 max transfer buffer, specially for receiving data from ep0 out */
#define CONFIG_USBDEV_REQUEST_BUFFER_LEN 256
/* Ep0 in and out transfer buffer */
#ifndef CONFIG_USBDEV_REQUEST_BUFFER_LEN
#define CONFIG_USBDEV_REQUEST_BUFFER_LEN 512
#endif

/* Setup packet log for debug */
// #define CONFIG_USBDEV_SETUP_LOG_PRINT

/* Send ep0 in data from user buffer instead of copying into ep0 reqdata
* Please note that user buffer must be aligned with CONFIG_USB_ALIGN_SIZE
*/
// #define CONFIG_USBDEV_EP0_INDATA_NO_COPY

/* Check if the input descriptor is correct */
// #define CONFIG_USBDEV_DESC_CHECK

Expand Down Expand Up @@ -81,8 +80,9 @@
#define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
#endif

/* rndis transfer buffer size, must be a multiple of (1536 + 44)*/
#ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
#define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1536
#define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1580
#endif

#ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
Expand All @@ -97,12 +97,11 @@

/* ================ USB HOST Stack Configuration ================== */

#define CONFIG_USBHOST_MAX_BUS 1
#define CONFIG_USBHOST_MAX_RHPORTS 1
#define CONFIG_USBHOST_MAX_EXTHUBS 1
#define CONFIG_USBHOST_MAX_EHPORTS 4
#define CONFIG_USBHOST_MAX_INTERFACES 8
#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8
#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1
#define CONFIG_USBHOST_MAX_ENDPOINTS 4

#define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
Expand All @@ -123,10 +122,14 @@
//#define CONFIG_USBHOST_GET_STRING_DESC

// #define CONFIG_USBHOST_MSOS_ENABLE
#ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE
#define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
#endif

/* Ep0 max transfer buffer */
#define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
#ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN
#define CONFIG_USBHOST_REQUEST_BUFFER_LEN 2048
#endif

#ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
#define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
Expand All @@ -136,6 +139,51 @@
#define CONFIG_USBHOST_MSC_TIMEOUT 5000
#endif

/* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
* you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
*/
#ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE
#define CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE (16*1024)
#endif

/* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
#ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE
#define CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE (2048)
#endif

/* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
* you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
*/
#ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE
#define CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE (16*1024)
#endif
/* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
#ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE
#define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048)
#endif

/* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
* you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
*/
#ifndef CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE
#define CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE (2048)
#endif
/* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
#ifndef CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE
#define CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE (2048)
#endif

/* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
* you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
*/
#ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE
#define CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE (16*1024)
#endif
/* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
#ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE
#define CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE (2048)
#endif

#define CONFIG_USBHOST_BLUETOOTH_HCI_H4
// #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG

Expand All @@ -148,22 +196,74 @@

/* ================ USB Device Port Configuration ================*/

#ifndef CONFIG_USBDEV_MAX_BUS
#define CONFIG_USBDEV_MAX_BUS 1 // for now, bus num must be 1 except hpm ip
#endif

#ifndef CONFIG_USBDEV_EP_NUM
#define CONFIG_USBDEV_EP_NUM 4
#define CONFIG_USBDEV_EP_NUM 8
#endif

/* ---------------- FSDEV Configuration ---------------- */
//#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 // maybe 1 or 2, many chips may have a difference

/* ---------------- DWC2 Configuration ---------------- */
// #define CONFIG_USB_DWC2_RXALL_FIFO_SIZE (320)
// #define CONFIG_USB_DWC2_TX0_FIFO_SIZE (64 / 4)
// #define CONFIG_USB_DWC2_TX1_FIFO_SIZE (512 / 4)
// #define CONFIG_USB_DWC2_TX2_FIFO_SIZE (64 / 4)
// #define CONFIG_USB_DWC2_TX3_FIFO_SIZE (64 / 4)
// #define CONFIG_USB_DWC2_TX4_FIFO_SIZE (0 / 4)
// #define CONFIG_USB_DWC2_TX5_FIFO_SIZE (0 / 4)
// #define CONFIG_USB_DWC2_TX6_FIFO_SIZE (0 / 4)
// #define CONFIG_USB_DWC2_TX7_FIFO_SIZE (0 / 4)
// #define CONFIG_USB_DWC2_TX8_FIFO_SIZE (0 / 4)

/* ---------------- MUSB Configuration ---------------- */
// #define CONFIG_USB_MUSB_SUNXI

/* ================ USB Host Port Configuration ==================*/
#ifndef CONFIG_USBHOST_MAX_BUS
#define CONFIG_USBHOST_MAX_BUS 1
#endif

#ifndef CONFIG_USBHOST_PIPE_NUM
#define CONFIG_USBHOST_PIPE_NUM 10
#endif

/* ================ EHCI Configuration ================ */
/* ---------------- EHCI Configuration ---------------- */

#define CONFIG_USB_EHCI_HCCR_OFFSET (0x0)
#define CONFIG_USB_EHCI_HCOR_OFFSET (0x10)
#define CONFIG_USB_EHCI_FRAME_LIST_SIZE 1024
#define CONFIG_USB_EHCI_QH_NUM CONFIG_USBHOST_PIPE_NUM
#define CONFIG_USB_EHCI_QTD_NUM 3
#define CONFIG_USB_EHCI_ITD_NUM 5
#define CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE
// #define CONFIG_USB_EHCI_CONFIGFLAG
// #define CONFIG_USB_EHCI_PORT_POWER
// #define CONFIG_USB_EHCI_PRINT_HW_PARAM
// #define CONFIG_USB_EHCI_ISO
// #define CONFIG_USB_EHCI_WITH_OHCI

/* ---------------- OHCI Configuration ---------------- */
#define CONFIG_USB_OHCI_HCOR_OFFSET (0x0)

/* ---------------- XHCI Configuration ---------------- */
#define CONFIG_USB_XHCI_HCCR_OFFSET (0x0)

/* ---------------- DWC2 Configuration ---------------- */
/* largest non-periodic USB packet used / 4 */
// #define CONFIG_USB_DWC2_NPTX_FIFO_SIZE (512 / 4)
/* largest periodic USB packet used / 4 */
// #define CONFIG_USB_DWC2_PTX_FIFO_SIZE (1024 / 4)
/*
* (largest USB packet used / 4) + 1 for status information + 1 transfer complete +
* 1 location each for Bulk/Control endpoint for handling NAK/NYET scenario
*/
// #define CONFIG_USB_DWC2_RX_FIFO_SIZE ((1012 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE) / 4)

/* ---------------- MUSB Configuration ---------------- */
// #define CONFIG_USB_MUSB_SUNXI

#define CONFIG_USB_HS
#define ATTR_FAST_RAM_SECTION __attribute__((section(".fast")))

#endif
Loading

0 comments on commit e8c779f

Please sign in to comment.