Skip to content

Commit

Permalink
feat(cherryusb): add cherryusb library
Browse files Browse the repository at this point in the history
Signed-off-by: sakumisu <1203593632@qq.com>
  • Loading branch information
sakumisu committed Jan 26, 2025
1 parent 95ea6ac commit 4fb2ab5
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions lib/cherryusb
Submodule cherryusb added at d3aafb
1 change: 1 addition & 0 deletions src/cmake/rp2_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
48 changes: 48 additions & 0 deletions src/rp2_common/cherryusb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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_include_directories(cherryusb_device_headers SYSTEM INTERFACE ${PICO_CHERRYUSB_PATH}/demo)
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_include_directories(cherryusb_host_headers SYSTEM INTERFACE ${PICO_CHERRYUSB_PATH}/demo)
target_sources(cherryusb_host INTERFACE ${cherryusb_srcs})

pico_promote_common_scope_vars()
endif()
6 changes: 6 additions & 0 deletions src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/rp2_common/pico_crt0/rp2040/memmap_copy_to_ram.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = .;
Expand Down
6 changes: 6 additions & 0 deletions src/rp2_common/pico_crt0/rp2040/memmap_default.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4fb2ab5

Please sign in to comment.