From 59e50a84b6aa0dc57fb1c211a11b3e3de4e58170 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Sun, 30 May 2021 20:18:52 -0500 Subject: [PATCH 1/5] Generic pico_promote_common_scope_vars to promote the variables from a list --- CMakeLists.txt | 4 ++++ pico_sdk_init.cmake | 24 +++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b65d8bf31..c270649c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,5 +50,9 @@ if (NOT TARGET _pico_sdk_inclusion_marker) # add docs at the end, as we gather documentation dirs as we go add_subdirectory(docs) + + if (NOT PICO_SDK_TOP_LEVEL_PROJECT) + pico_promote_common_scope_vars() + endif() endif() diff --git a/pico_sdk_init.cmake b/pico_sdk_init.cmake index c291a504d..2d2787d62 100644 --- a/pico_sdk_init.cmake +++ b/pico_sdk_init.cmake @@ -44,6 +44,7 @@ if (NOT TARGET _pico_sdk_pre_init_marker) message(WARNING "pico_sdk_init() should be called after the project is created (and languages added)") endif() add_subdirectory(${PICO_SDK_PATH} pico-sdk) + pico_is_top_level_project(ISTOP) endmacro() macro(add_sub_list_dirs var) @@ -61,11 +62,24 @@ if (NOT TARGET _pico_sdk_pre_init_marker) endforeach() endmacro() + macro(pico_register_common_scope_var NAME) + if (NOT ${NAME} IN_LIST PICO_PROMOTE_COMMON_SCOPE_VARS) + list(APPEND PICO_PROMOTE_COMMON_SCOPE_VARS ${NAME}) + endif() + endmacro() + + set(PICO_PROMOTE_COMMON_SCOPE_VARS + PICO_INCLUDE_DIRS + PICO_SDK_POST_LIST_DIRS + PICO_SDK_POST_LIST_FILES + PICO_CONFIG_HEADER_FILES + PICO_RP2040_CONFIG_HEADER_FILES + ) + macro(pico_promote_common_scope_vars) - set(PICO_INCLUDE_DIRS ${PICO_INCLUDE_DIRS} PARENT_SCOPE) - set(PICO_SDK_POST_LIST_DIRS ${PICO_SDK_POST_LIST_DIRS} PARENT_SCOPE) - set(PICO_SDK_POST_LIST_FILES ${PICO_SDK_POST_LIST_FILES} PARENT_SCOPE) - set(PICO_CONFIG_HEADER_FILES ${PICO_CONFIG_HEADER_FILES} PARENT_SCOPE) - set(PICO_RP2040_CONFIG_HEADER_FILES ${PICO_RP2040_CONFIG_HEADER_FILES} PARENT_SCOPE) + set(PICO_PROMOTE_COMMON_SCOPE_VARS ${PICO_PROMOTE_COMMON_SCOPE_VARS} PARENT_SCOPE) + foreach(VAR IN LISTS PICO_PROMOTE_COMMON_SCOPE_VARS) + SET(${VAR} ${${VAR}} PARENT_SCOPE) + endforeach() endmacro() endif() From 707d1c20cba2eb0ae791ab469520aa24df44a6e6 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Sun, 30 May 2021 20:19:28 -0500 Subject: [PATCH 2/5] Fixup for tinyusb-0.9.0+ changes and bump tinyusb ref to pico-0.10.0 --- lib/tinyusb | 2 +- src/rp2_common/hardware_uart/include/hardware/uart.h | 6 ++++++ src/rp2_common/pico_stdio_usb/reset_interface.c | 12 +++++------- src/rp2_common/tinyusb/CMakeLists.txt | 11 +++++++++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/tinyusb b/lib/tinyusb index 11c23f88b..f5572e24b 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 11c23f88bf42f64ce14b8a7b0b2a4e207dc4dd12 +Subproject commit f5572e24b25800c133b2f9fd4eae02e0934cd935 diff --git a/src/rp2_common/hardware_uart/include/hardware/uart.h b/src/rp2_common/hardware_uart/include/hardware/uart.h index d37c1b786..02fdd1fb9 100644 --- a/src/rp2_common/hardware_uart/include/hardware/uart.h +++ b/src/rp2_common/hardware_uart/include/hardware/uart.h @@ -101,6 +101,12 @@ static inline uint uart_get_index(uart_inst_t *uart) { return uart == uart1 ? 1 : 0; } +static inline uart_inst_t *uart_get_instance(uint instance) { + static_assert(NUM_UARTS == 2, ""); + invalid_params_if(UART, instance >= NUM_UARTS); + return instance ? uart1 : uart0; +} + static inline uart_hw_t *uart_get_hw(uart_inst_t *uart) { uart_get_index(uart); // check it is a hw uart return (uart_hw_t *)uart; diff --git a/src/rp2_common/pico_stdio_usb/reset_interface.c b/src/rp2_common/pico_stdio_usb/reset_interface.c index ccd5758ce..2f2e72b19 100644 --- a/src/rp2_common/pico_stdio_usb/reset_interface.c +++ b/src/rp2_common/pico_stdio_usb/reset_interface.c @@ -38,7 +38,10 @@ static uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const } // Support for parameterized reset via vendor interface control request -static bool resetd_control_request_cb(uint8_t __unused rhport, tusb_control_request_t const *request) { +static bool resetd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request) { + // nothing to do with DATA & ACK stage + if (stage != CONTROL_STAGE_SETUP) return true; + if (request->wIndex == itf_num) { #if PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL @@ -69,10 +72,6 @@ static bool resetd_control_request_cb(uint8_t __unused rhport, tusb_control_requ return false; } -static bool resetd_control_complete_cb(uint8_t __unused rhport, tusb_control_request_t __unused const *request) { - return true; -} - static bool resetd_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes) { return true; } @@ -85,8 +84,7 @@ static usbd_class_driver_t const _resetd_driver = .init = resetd_init, .reset = resetd_reset, .open = resetd_open, - .control_request = resetd_control_request_cb, - .control_complete = resetd_control_complete_cb, + .control_xfer_cb = resetd_control_xfer_cb, .xfer_cb = resetd_xfer_cb, .sof = NULL }; diff --git a/src/rp2_common/tinyusb/CMakeLists.txt b/src/rp2_common/tinyusb/CMakeLists.txt index f4dea1cfe..adcf558a4 100644 --- a/src/rp2_common/tinyusb/CMakeLists.txt +++ b/src/rp2_common/tinyusb/CMakeLists.txt @@ -17,6 +17,10 @@ endif() if (EXISTS ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH}) message("TinyUSB available at ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH}; adding USB support.") + # todo some of this functionality now overlaps tinyusb/hw/bsp/rp2040/family.cmake and some of this + # should be moved there in the future + + pico_register_common_scope_var(PICO_TINYUSB_PATH) add_library(tinyusb_common INTERFACE) target_link_libraries(tinyusb_common INTERFACE hardware_structs @@ -56,6 +60,7 @@ if (EXISTS ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH}) ${PICO_TINYUSB_PATH}/src/device/usbd_control.c ${PICO_TINYUSB_PATH}/src/class/audio/audio_device.c ${PICO_TINYUSB_PATH}/src/class/cdc/cdc_device.c + ${PICO_TINYUSB_PATH}/src/class/dfu/dfu_device.c ${PICO_TINYUSB_PATH}/src/class/dfu/dfu_rt_device.c ${PICO_TINYUSB_PATH}/src/class/hid/hid_device.c ${PICO_TINYUSB_PATH}/src/class/midi/midi_device.c @@ -102,8 +107,10 @@ if (EXISTS ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH}) pico_add_impl_library(tinyusb_board) target_sources(tinyusb_board INTERFACE - ${PICO_TINYUSB_PATH}/hw/bsp/raspberry_pi_pico/board_raspberry_pi_pico.c + ${PICO_TINYUSB_PATH}/hw/bsp/rp2040/family.c ) -endif() + target_include_directories(tinyusb_board INTERFACE ${PICO_TINYUSB_PATH}/hw/bsp/rp2040/boards/sdk_selected) + pico_promote_common_scope_vars() +endif() From 45b1a6939cbd67960b9e90db03078a2594d1b35c Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 1 Jun 2021 19:51:36 -0500 Subject: [PATCH 3/5] fix tinyusb revision --- lib/tinyusb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tinyusb b/lib/tinyusb index f5572e24b..109d02531 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit f5572e24b25800c133b2f9fd4eae02e0934cd935 +Subproject commit 109d02531e3ba208627b4dfab29d29df3d8a4565 From aad159a42db5a64dfcf99b028b6aa8a53e6c9fde Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Wed, 2 Jun 2021 08:32:52 -0500 Subject: [PATCH 4/5] Move tinyusb source and include definitions into tinyusb/hw/bsp/rp2040/family.cmake --- lib/tinyusb | 2 +- src/rp2_common/tinyusb/CMakeLists.txt | 84 +++------------------------ 2 files changed, 9 insertions(+), 77 deletions(-) diff --git a/lib/tinyusb b/lib/tinyusb index 109d02531..5b24bc3e1 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 109d02531e3ba208627b4dfab29d29df3d8a4565 +Subproject commit 5b24bc3e1b96f731082835aa4e5bc608a871a6ac diff --git a/src/rp2_common/tinyusb/CMakeLists.txt b/src/rp2_common/tinyusb/CMakeLists.txt index adcf558a4..c4d238d09 100644 --- a/src/rp2_common/tinyusb/CMakeLists.txt +++ b/src/rp2_common/tinyusb/CMakeLists.txt @@ -17,100 +17,32 @@ endif() if (EXISTS ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH}) message("TinyUSB available at ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH}; adding USB support.") - # todo some of this functionality now overlaps tinyusb/hw/bsp/rp2040/family.cmake and some of this - # should be moved there in the future - pico_register_common_scope_var(PICO_TINYUSB_PATH) - add_library(tinyusb_common INTERFACE) - target_link_libraries(tinyusb_common INTERFACE - hardware_structs - hardware_irq - hardware_resets - pico_sync - ) - - target_sources(tinyusb_common INTERFACE - ${PICO_TINYUSB_PATH}/src/tusb.c - ${PICO_TINYUSB_PATH}/src/common/tusb_fifo.c - ) - - set(TINYUSB_DEBUG_LEVEL 0) - if (CMAKE_BUILD_TYPE STREQUAL "Debug") - message("Compiling TinyUSB with CFG_TUSB_DEBUG=1") - set(TINYUSB_DEBUG_LEVEL 1) - endif () - target_compile_definitions(tinyusb_common INTERFACE - CFG_TUSB_MCU=OPT_MCU_RP2040 - CFG_TUSB_OS=OPT_OS_PICO #seems examples are hard coded to OPT_OS_NONE - CFG_TUSB_DEBUG=${TINYUSB_DEBUG_LEVEL} - ) + set(BOARD pico_sdk) + include(${PICO_TINYUSB_PATH}/hw/bsp/rp2040/family.cmake) - target_include_directories(tinyusb_common INTERFACE - ${PICO_TINYUSB_PATH}/src - ${PICO_TINYUSB_PATH}/src/common - ${PICO_TINYUSB_PATH}/hw - ) + add_library(tinyusb_common INTERFACE) + target_link_libraries(tinyusb_common INTERFACE tinyusb_common_base) add_library(tinyusb_device_unmarked INTERFACE) - target_sources(tinyusb_device_unmarked INTERFACE - ${PICO_TINYUSB_PATH}/src/portable/raspberrypi/rp2040/dcd_rp2040.c - ${PICO_TINYUSB_PATH}/src/portable/raspberrypi/rp2040/rp2040_usb.c - ${PICO_TINYUSB_PATH}/src/device/usbd.c - ${PICO_TINYUSB_PATH}/src/device/usbd_control.c - ${PICO_TINYUSB_PATH}/src/class/audio/audio_device.c - ${PICO_TINYUSB_PATH}/src/class/cdc/cdc_device.c - ${PICO_TINYUSB_PATH}/src/class/dfu/dfu_device.c - ${PICO_TINYUSB_PATH}/src/class/dfu/dfu_rt_device.c - ${PICO_TINYUSB_PATH}/src/class/hid/hid_device.c - ${PICO_TINYUSB_PATH}/src/class/midi/midi_device.c - ${PICO_TINYUSB_PATH}/src/class/msc/msc_device.c - ${PICO_TINYUSB_PATH}/src/class/net/net_device.c - ${PICO_TINYUSB_PATH}/src/class/usbtmc/usbtmc_device.c - ${PICO_TINYUSB_PATH}/src/class/vendor/vendor_device.c - ) - + target_link_libraries(tinyusb_device_unmarked INTERFACE tinyusb_device_base) target_compile_definitions(tinyusb_device_unmarked INTERFACE # off by default note TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX defaults from PICO_RP2040_USB_DEVICE_ENUMERATION_FIX # TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX=1 ) # unmarked version used by stdio USB - target_link_libraries(tinyusb_device_unmarked INTERFACE tinyusb_common pico_fix_rp2040_usb_device_enumeration) + target_link_libraries(tinyusb_device_unmarked INTERFACE tinyusb_common pico_fix_rp2040_usb_device_enumeration tinyusb_device_base) pico_add_impl_library(tinyusb_device) target_link_libraries(tinyusb_device INTERFACE tinyusb_device_unmarked) - target_compile_definitions(tinyusb_device INTERFACE - RP2040_USB_DEVICE_MODE=1 #define is used by tinyusb still - ) pico_add_impl_library(tinyusb_host) - target_sources(tinyusb_host INTERFACE - ${PICO_TINYUSB_PATH}/src/portable/raspberrypi/rp2040/hcd_rp2040.c - ${PICO_TINYUSB_PATH}/src/portable/raspberrypi/rp2040/rp2040_usb.c - ${PICO_TINYUSB_PATH}/src/host/usbh.c - ${PICO_TINYUSB_PATH}/src/host/usbh_control.c - ${PICO_TINYUSB_PATH}/src/host/hub.c - ${PICO_TINYUSB_PATH}/src/class/cdc/cdc_host.c - ${PICO_TINYUSB_PATH}/src/class/hid/hid_host.c - ${PICO_TINYUSB_PATH}/src/class/msc/msc_host.c - ${PICO_TINYUSB_PATH}/src/class/vendor/vendor_host.c - ) - - # Sometimes have to do host specific actions in mostly - # common functions - target_compile_definitions(tinyusb_host INTERFACE - RP2040_USB_HOST_MODE=1 #define is used by tinyusb still - ) - - target_link_libraries(tinyusb_host INTERFACE tinyusb_common) + target_link_libraries(tinyusb_host INTERFACE tinyusb_host_base tinyusb_common) pico_add_impl_library(tinyusb_board) - target_sources(tinyusb_board INTERFACE - ${PICO_TINYUSB_PATH}/hw/bsp/rp2040/family.c - ) - - target_include_directories(tinyusb_board INTERFACE ${PICO_TINYUSB_PATH}/hw/bsp/rp2040/boards/sdk_selected) + target_link_libraries(tinyusb_board INTERFACE tinyusb_bsp) pico_promote_common_scope_vars() endif() From 8db61695dc810b7d3a6ae44e42c78d7f3820ef89 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Wed, 2 Jun 2021 09:49:16 -0500 Subject: [PATCH 5/5] update tinyusb submodule --- lib/tinyusb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tinyusb b/lib/tinyusb index 5b24bc3e1..fea5cbaf7 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 5b24bc3e1b96f731082835aa4e5bc608a871a6ac +Subproject commit fea5cbaf74a033d3f0c462b6bf2d334a67f6a732