diff --git a/.gitmodules b/.gitmodules index 7c382da67..d65780c18 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "lib/btstack"] path = lib/btstack url = https://github.com/bluekitchen/btstack.git +[submodule "lib/cherryusb"] + path = lib/cherryusb + url = https://github.com/cherry-embedded/CherryUSB.git diff --git a/lib/cherryusb b/lib/cherryusb new file mode 160000 index 000000000..127cccfb4 --- /dev/null +++ b/lib/cherryusb @@ -0,0 +1 @@ +Subproject commit 127cccfb4c53dface4d2e897c702a8d986a58ce0 diff --git a/src/cmake/rp2_common.cmake b/src/cmake/rp2_common.cmake index 726bab933..82c1772b4 100644 --- a/src/cmake/rp2_common.cmake +++ b/src/cmake/rp2_common.cmake @@ -119,6 +119,7 @@ if (NOT PICO_BARE_METAL) pico_add_subdirectory(rp2_common/cmsis) endif() pico_add_subdirectory(rp2_common/tinyusb) + pico_add_subdirectory(rp2_common/cherryusb) pico_add_subdirectory(rp2_common/pico_stdio_usb) pico_add_subdirectory(rp2_common/pico_i2c_slave) diff --git a/src/rp2_common/cherryusb/CMakeLists.txt b/src/rp2_common/cherryusb/CMakeLists.txt new file mode 100644 index 000000000..9f5aa5ec1 --- /dev/null +++ b/src/rp2_common/cherryusb/CMakeLists.txt @@ -0,0 +1,46 @@ +if (DEFINED ENV{PICO_CHERRYUSB_PATH} AND (NOT PICO_CHERRYUSB_PATH)) + set(PICO_CHERRYUSB_PATH $ENV{PICO_CHERRYUSB_PATH}) + message("Using PICO_CHERRYUSB_PATH from environment ('${PICO_CHERRYUSB_PATH}')") +endif () + +set(CHERRYUSB_TEST_PATH "port/rp2040") +if (NOT PICO_CHERRYUSB_PATH) + set(PICO_CHERRYUSB_PATH ${PROJECT_SOURCE_DIR}/lib/cherryusb) + if (NOT EXISTS ${PICO_CHERRYUSB_PATH}/${CHERRYUSB_TEST_PATH}) + message(WARNING "CherryUSB submodule has not been initialized; USB support will be unavailable +hint: try 'git submodule update --init' from your SDK directory (${PICO_SDK_PATH}).") + endif() +elseif (NOT EXISTS ${PICO_CHERRYUSB_PATH}/${CHERRYUSB_TEST_PATH}) + message(WARNING "PICO_CHERRYUSB_PATH specified but content not present.") +endif() + +if (EXISTS ${PICO_CHERRYUSB_PATH}/${CHERRYUSB_TEST_PATH}) + message("CherryUSB available at ${PICO_CHERRYUSB_PATH}; enabling build support for USB.") + pico_register_common_scope_var(PICO_CHERRYUSB_PATH) + + set(CONFIG_CHERRYUSB_DEVICE 1) + set(CONFIG_CHERRYUSB_DEVICE_CDC_ACM 1) + set(CONFIG_CHERRYUSB_DEVICE_HID 1) + set(CONFIG_CHERRYUSB_DEVICE_MSC 1) + set(CONFIG_CHERRYUSB_DEVICE_AUDIO 1) + set(CONFIG_CHERRYUSB_DEVICE_VIDEO 1) + set(CONFIG_CHERRYUSB_DEVICE_DCD "rp2040") + include(${PICO_CHERRYUSB_PATH}/cherryusb.cmake) + pico_add_library(cherryusb_device NOFLAG) + target_include_directories(cherryusb_device_headers SYSTEM INTERFACE ${cherryusb_incs}) + target_sources(cherryusb_device INTERFACE ${cherryusb_srcs}) + + set(CONFIG_CHERRYUSB_HOST 1) + set(CONFIG_CHERRYUSB_HOST_CDC_ACM 1) + set(CONFIG_CHERRYUSB_HOST_HID 1) + set(CONFIG_CHERRYUSB_HOST_MSC 1) + set(CONFIG_CHERRYUSB_OSAL "freertos") + set(CONFIG_CHERRYUSB_HOST_HCD "rp2040") + + include(${PICO_CHERRYUSB_PATH}/cherryusb.cmake) + pico_add_library(cherryusb_host NOFLAG) + target_include_directories(cherryusb_host_headers SYSTEM INTERFACE ${cherryusb_incs}) + target_sources(cherryusb_host INTERFACE ${cherryusb_srcs}) + + pico_promote_common_scope_vars() +endif() diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld b/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld index 6f5000566..e9813734a 100644 --- a/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld +++ b/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld @@ -106,6 +106,12 @@ SECTIONS *(.fini_array) PROVIDE_HIDDEN (__fini_array_end = .); + /* section information for usbh class */ + . = ALIGN(4); + __usbh_class_info_start__ = .; + KEEP(*(.usbh_class_info)) + __usbh_class_info_end__ = .; + *(.eh_frame*) . = ALIGN(4); } > FLASH diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_copy_to_ram.ld b/src/rp2_common/pico_crt0/rp2040/memmap_copy_to_ram.ld index 842ebfd3c..66a3d78d8 100644 --- a/src/rp2_common/pico_crt0/rp2040/memmap_copy_to_ram.ld +++ b/src/rp2_common/pico_crt0/rp2040/memmap_copy_to_ram.ld @@ -125,6 +125,12 @@ SECTIONS *(SORT(.dtors.*)) *(.dtors) + /* section information for usbh class */ + . = ALIGN(4); + __usbh_class_info_start__ = .; + KEEP(*(.usbh_class_info)) + __usbh_class_info_end__ = .; + *(.eh_frame*) . = ALIGN(4); __ram_text_end__ = .; diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_default.ld b/src/rp2_common/pico_crt0/rp2040/memmap_default.ld index 51254012d..427270710 100644 --- a/src/rp2_common/pico_crt0/rp2040/memmap_default.ld +++ b/src/rp2_common/pico_crt0/rp2040/memmap_default.ld @@ -106,6 +106,12 @@ SECTIONS *(.fini_array) PROVIDE_HIDDEN (__fini_array_end = .); + /* section information for usbh class */ + . = ALIGN(4); + __usbh_class_info_start__ = .; + KEEP(*(.usbh_class_info)) + __usbh_class_info_end__ = .; + *(.eh_frame*) . = ALIGN(4); } > FLASH diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_no_flash.ld b/src/rp2_common/pico_crt0/rp2040/memmap_no_flash.ld index dbf006a8c..ae13487c8 100644 --- a/src/rp2_common/pico_crt0/rp2040/memmap_no_flash.ld +++ b/src/rp2_common/pico_crt0/rp2040/memmap_no_flash.ld @@ -68,6 +68,12 @@ SECTIONS *(SORT(.dtors.*)) *(.dtors) + /* section information for usbh class */ + . = ALIGN(4); + __usbh_class_info_start__ = .; + KEEP(*(.usbh_class_info)) + __usbh_class_info_end__ = .; + *(.eh_frame*) } > RAM diff --git a/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld b/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld index 89d63a9f0..200c5ae89 100644 --- a/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld +++ b/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld @@ -141,6 +141,12 @@ SECTIONS *(SORT(.dtors.*)) *(.dtors) + /* section information for usbh class */ + . = ALIGN(4); + __usbh_class_info_start__ = .; + KEEP(*(.usbh_class_info)) + __usbh_class_info_end__ = .; + *(.eh_frame*) . = ALIGN(4); __ram_text_end__ = .; diff --git a/src/rp2_common/pico_crt0/rp2350/memmap_default.ld b/src/rp2_common/pico_crt0/rp2350/memmap_default.ld index bce316d14..a22dc50f0 100644 --- a/src/rp2_common/pico_crt0/rp2350/memmap_default.ld +++ b/src/rp2_common/pico_crt0/rp2350/memmap_default.ld @@ -96,6 +96,12 @@ SECTIONS *(.fini_array) PROVIDE_HIDDEN (__fini_array_end = .); + /* section information for usbh class */ + . = ALIGN(4); + __usbh_class_info_start__ = .; + KEEP(*(.usbh_class_info)) + __usbh_class_info_end__ = .; + *(.eh_frame*) . = ALIGN(4); } > FLASH diff --git a/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld b/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld index 98088cdfc..075478160 100644 --- a/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld +++ b/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld @@ -69,6 +69,12 @@ SECTIONS *(SORT(.dtors.*)) *(.dtors) + /* section information for usbh class */ + . = ALIGN(4); + __usbh_class_info_start__ = .; + KEEP(*(.usbh_class_info)) + __usbh_class_info_end__ = .; + *(.eh_frame*) } > RAM