diff options
| author | hathach <[email protected]> | 2026-04-14 10:51:20 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2026-04-14 10:51:20 +0700 |
| commit | 44b0ee05390b0f97d006a016b25fa513699e0a96 (patch) | |
| tree | 93decf8946c6eacabcae6d063fb5d576c99e5d86 | |
| parent | 7c3f5979ff9be05b7938f10dbaa6e55daaf8bdc1 (diff) | |
get freertos working with rp2040
| -rw-r--r-- | .idea/cmake.xml | 6 | ||||
| -rw-r--r-- | examples/device/audio_4_channel_mic_freertos/skip.txt | 1 | ||||
| -rw-r--r-- | examples/device/audio_4_channel_mic_freertos/src/main.c | 2 | ||||
| -rw-r--r-- | examples/device/audio_test_freertos/skip.txt | 1 | ||||
| -rw-r--r-- | examples/device/cdc_msc_freertos/skip.txt | 1 | ||||
| -rw-r--r-- | examples/device/cdc_msc_freertos/src/msc_disk.c | 2 | ||||
| -rw-r--r-- | examples/device/hid_composite_freertos/skip.txt | 1 | ||||
| -rw-r--r-- | examples/device/midi_test_freertos/skip.txt | 1 | ||||
| -rw-r--r-- | examples/host/cdc_msc_hid_freertos/skip.txt | 1 | ||||
| -rw-r--r-- | hw/bsp/family_support.cmake | 71 | ||||
| -rw-r--r-- | hw/bsp/rp2040/family.c | 14 | ||||
| -rw-r--r-- | hw/bsp/rp2040/family.cmake | 48 | ||||
| -rwxr-xr-x | test/hil/hil_test.py | 2 | ||||
| -rwxr-xr-x | tools/get_deps.py | 5 |
14 files changed, 106 insertions, 50 deletions
diff --git a/.idea/cmake.xml b/.idea/cmake.xml index 6f87e2a29..14dbdfe66 100644 --- a/.idea/cmake.xml +++ b/.idea/cmake.xml @@ -5,9 +5,9 @@ <configuration PROFILE_NAME="raspberrypi_zero" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=raspberrypi_zero -DLOG=1" /> <configuration PROFILE_NAME="raspberrypi_zero2" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=raspberrypi_zero2 -DLOG=1" /> <configuration PROFILE_NAME="raspberrypi_cm4" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=raspberrypi_cm4 -DLOG=1" /> - <configuration PROFILE_NAME="raspberry_pi_pico" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=raspberry_pi_pico -DLOG=1" /> + <configuration PROFILE_NAME="raspberry_pi_pico" ENABLED="true" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=raspberry_pi_pico -DLOG=1" /> <configuration PROFILE_NAME="raspberry_pi_pico-pio_host" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=raspberry_pi_pico -DLOG=1 -DCFLAGS_CLI="-DCFG_TUH_RPI_PIO_USB=1"" /> - <configuration PROFILE_NAME="raspberry_pi_pico2" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=raspberry_pi_pico2 -DLOG=1" /> + <configuration PROFILE_NAME="raspberry_pi_pico2" ENABLED="true" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=raspberry_pi_pico2 -DLOG=1" /> <configuration PROFILE_NAME="raspberry_pi_pico2-pio_host" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=raspberry_pi_pico2 -DLOG=1 -DCFLAGS_CLI="-DCFG_TUH_RPI_PIO_USB=1"" /> <configuration PROFILE_NAME="feather_rp2040" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=pico_sdk -DPICO_BOARD=adafruit_feather_rp2040 -DLOG=1" /> <configuration PROFILE_NAME="feather_rp2040_max3421" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=feather_rp2040_max3421 -DLOG=1" /> @@ -101,6 +101,8 @@ <configuration PROFILE_NAME="nrf52840dk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=nrf52840dk -DLOG=1 -DLOGGER=RTT -DTRACE_ETM=1" /> <configuration PROFILE_NAME="nrf52840dk-zephyr" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=nrf52840dk -DLOG=1 -DTRACE_ETM=1 -DRTOS=zephyr" BUILD_OPTIONS="-v" /> <configuration PROFILE_NAME="nrf5340dk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=nrf5340dk -DLOG=1 -DLOGGER=RTT -DTRACE_ETM=1" /> + <configuration PROFILE_NAME="nrf54h20dk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=nrf54h20dk -DLOG=1 -DLOGGER=RTT -DTRACE_ETM=1" /> + <configuration PROFILE_NAME="nrf54lm20dk" ENABLED="false" CONFIG_NAME="MinSizeRel" GENERATION_OPTIONS="-DBOARD=nrf54lm20dk -DLOG=0 -DLOGGER=RTT -DTRACE_ETM=1" /> <configuration PROFILE_NAME="metro m7 1011 sd" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=metro_m7_1011_sd -DLOG=1 -DLOGGER=RTT -DTRACE_ETM=1" /> <configuration PROFILE_NAME="metro_m7_1011" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=metro_m7_1011 -DLOG=1 -DLOGGER=RTT" /> <configuration PROFILE_NAME="rt1010 evk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=mimxrt1010_evk -DLOG=1 -DLOGGER=RTT" /> diff --git a/examples/device/audio_4_channel_mic_freertos/skip.txt b/examples/device/audio_4_channel_mic_freertos/skip.txt index be44cb2c0..61a7b0605 100644 --- a/examples/device/audio_4_channel_mic_freertos/skip.txt +++ b/examples/device/audio_4_channel_mic_freertos/skip.txt @@ -9,7 +9,6 @@ mcu:MCXA15 mcu:MKL25ZXX mcu:MSP430x5xx mcu:FT90X -mcu:RP2040 mcu:SAMD11 mcu:VALENTYUSB_EPTRI mcu:RAXXX diff --git a/examples/device/audio_4_channel_mic_freertos/src/main.c b/examples/device/audio_4_channel_mic_freertos/src/main.c index 4572bbb3c..eac66a4ef 100644 --- a/examples/device/audio_4_channel_mic_freertos/src/main.c +++ b/examples/device/audio_4_channel_mic_freertos/src/main.c @@ -310,7 +310,7 @@ bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p // Request uses format layout 2 TU_VERIFY(p_request->wLength == sizeof(audio20_control_cur_2_t)); - volume[channelNum] = ((audio20_control_cur_2_t *) pBuff)->bCur; + volume[channelNum] = (uint16_t) ((audio20_control_cur_2_t *) pBuff)->bCur; TU_LOG1(" Set Volume: %d dB of channel: %u\r\n", volume[channelNum], channelNum); return true; diff --git a/examples/device/audio_test_freertos/skip.txt b/examples/device/audio_test_freertos/skip.txt index 007fece53..386a0cdfb 100644 --- a/examples/device/audio_test_freertos/skip.txt +++ b/examples/device/audio_test_freertos/skip.txt @@ -9,7 +9,6 @@ mcu:MCXA15 mcu:MKL25ZXX mcu:MSP430x5xx mcu:FT90X -mcu:RP2040 mcu:SAMD11 mcu:VALENTYUSB_EPTRI mcu:RAXXX diff --git a/examples/device/cdc_msc_freertos/skip.txt b/examples/device/cdc_msc_freertos/skip.txt index 31d808d8e..429c62d93 100644 --- a/examples/device/cdc_msc_freertos/skip.txt +++ b/examples/device/cdc_msc_freertos/skip.txt @@ -9,7 +9,6 @@ mcu:MCXA15 mcu:MKL25ZXX mcu:MSP430x5xx mcu:FT90X -mcu:RP2040 mcu:SAMD11 mcu:VALENTYUSB_EPTRI mcu:RAXXX diff --git a/examples/device/cdc_msc_freertos/src/msc_disk.c b/examples/device/cdc_msc_freertos/src/msc_disk.c index ff918205e..ab551c288 100644 --- a/examples/device/cdc_msc_freertos/src/msc_disk.c +++ b/examples/device/cdc_msc_freertos/src/msc_disk.c @@ -168,7 +168,7 @@ static void io_task(void *params) { while (1) { if (xQueueReceive(io_queue, &io_ops, portMAX_DELAY)) { uint8_t* addr = (uint8_t*) (uintptr_t) (msc_disk[io_ops.lba] + io_ops.offset); - int32_t nbytes = io_ops.bufsize; + int32_t nbytes = (int32_t) io_ops.bufsize; if (io_ops.is_read) { memcpy(io_ops.buffer, addr, io_ops.bufsize); } else { diff --git a/examples/device/hid_composite_freertos/skip.txt b/examples/device/hid_composite_freertos/skip.txt index 8ae238584..d2ee8d636 100644 --- a/examples/device/hid_composite_freertos/skip.txt +++ b/examples/device/hid_composite_freertos/skip.txt @@ -9,7 +9,6 @@ mcu:MCXA15 mcu:MKL25ZXX mcu:MSP430x5xx mcu:FT90X -mcu:RP2040 mcu:SAMD11 mcu:VALENTYUSB_EPTRI mcu:RAXXX diff --git a/examples/device/midi_test_freertos/skip.txt b/examples/device/midi_test_freertos/skip.txt index 8ae238584..d2ee8d636 100644 --- a/examples/device/midi_test_freertos/skip.txt +++ b/examples/device/midi_test_freertos/skip.txt @@ -9,7 +9,6 @@ mcu:MCXA15 mcu:MKL25ZXX mcu:MSP430x5xx mcu:FT90X -mcu:RP2040 mcu:SAMD11 mcu:VALENTYUSB_EPTRI mcu:RAXXX diff --git a/examples/host/cdc_msc_hid_freertos/skip.txt b/examples/host/cdc_msc_hid_freertos/skip.txt index bb62547a6..f0be07d25 100644 --- a/examples/host/cdc_msc_hid_freertos/skip.txt +++ b/examples/host/cdc_msc_hid_freertos/skip.txt @@ -1,4 +1,3 @@ mcu:CH32F20X -mcu:RP2040 board:lpcxpresso54114 mcu:FT90X diff --git a/hw/bsp/family_support.cmake b/hw/bsp/family_support.cmake index 2274515e4..d69884407 100644 --- a/hw/bsp/family_support.cmake +++ b/hw/bsp/family_support.cmake @@ -367,24 +367,66 @@ endfunction() # Most families use these settings except rp2040 and espressif #------------------------------------------------------------- function(family_add_board BOARD_TARGET) - # empty function, should be redefined in FAMILY/family.cmake + # empty function, should be overridden in FAMILY/family.cmake endfunction() # Add RTOS to example function(family_add_rtos TARGET RTOS) if (RTOS STREQUAL "freertos") - if (NOT TARGET freertos_config) - add_library(freertos_config INTERFACE) - target_include_directories(freertos_config INTERFACE ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${FAMILY}/FreeRTOSConfig) - # add board definition to freertos_config mostly for SystemCoreClock - target_link_libraries(freertos_config INTERFACE board_${BOARD}) + # RP2040 family uses Raspberry Pi's FreeRTOS-Kernel fork with platform-specific SMP port + if (FAMILY STREQUAL "rp2040") + if (NOT TARGET FreeRTOS-Kernel) + set(FREERTOS_KERNEL_PATH ${TOP}/hw/mcu/raspberry_pi/FreeRTOS-Kernel) + set(FREERTOS_CONFIG_FILE_DIRECTORY ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${FAMILY}/FreeRTOSConfig) + if (PICO_PLATFORM STREQUAL "rp2040") + set(FREERTOS_PORT_PATH ${FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040) + else() + set(FREERTOS_PORT_PATH ${FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2350_ARM_NTZ) + endif() + include(${FREERTOS_PORT_PATH}/library.cmake) + endif() + target_link_libraries(${TARGET} PUBLIC FreeRTOS-Kernel-Static) + + # Suppress warnings in FreeRTOS kernel port sources + foreach(_ft IN ITEMS FreeRTOS-Kernel FreeRTOS-Kernel-Core FreeRTOS-Kernel-Static) + get_target_property(_srcs ${_ft} INTERFACE_SOURCES) + if (_srcs) + set_source_files_properties(${_srcs} PROPERTIES COMPILE_OPTIONS "-w") + endif() + endforeach() + + # FreeRTOS headers use undefined macros in #if (triggers -Wundef/-Werror). + # Convert all FreeRTOS include dirs to SYSTEM to suppress warnings. + foreach(_ft IN ITEMS FreeRTOS-Kernel FreeRTOS-Kernel-Core) + get_target_property(_incs ${_ft} INTERFACE_INCLUDE_DIRECTORIES) + if (_incs) + set_target_properties(${_ft} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + target_include_directories(${_ft} SYSTEM INTERFACE ${_incs}) + endif() + endforeach() + else() + # All other families: use upstream FreeRTOS-Kernel with add_subdirectory + if (NOT TARGET freertos_config) + add_library(freertos_config INTERFACE) + target_include_directories(freertos_config INTERFACE + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${FAMILY}/FreeRTOSConfig) + target_link_libraries(freertos_config INTERFACE board_${BOARD}) + endif() + + if (NOT TARGET freertos_kernel) + add_subdirectory(${TOP}/lib/FreeRTOS-Kernel ${CMAKE_BINARY_DIR}/lib/freertos_kernel) + endif () + + target_link_libraries(${TARGET} PUBLIC freertos_kernel) endif() - if (NOT TARGET freertos_kernel) - add_subdirectory(${TOP}/lib/FreeRTOS-Kernel ${CMAKE_BINARY_DIR}/lib/freertos_kernel) - endif () + # RP2040: remove CFG_TUSB_OS=OPT_OS_PICO from tinyusb_common_base to avoid redefinition + if (FAMILY STREQUAL "rp2040" AND TARGET tinyusb_common_base) + get_target_property(_defs tinyusb_common_base INTERFACE_COMPILE_DEFINITIONS) + list(REMOVE_ITEM _defs "CFG_TUSB_OS=${TINYUSB_OPT_OS}") + set_property(TARGET tinyusb_common_base PROPERTY INTERFACE_COMPILE_DEFINITIONS ${_defs}) + endif() - target_link_libraries(${TARGET} PUBLIC freertos_kernel) target_compile_definitions(${TARGET} PUBLIC CFG_TUSB_OS=OPT_OS_FREERTOS) elseif (RTOS STREQUAL "threadx") if (NOT TARGET threadx) @@ -465,7 +507,10 @@ function(family_configure_common TARGET RTOS) target_compile_definitions(${TARGET} PUBLIC LOGGER_UART) endif () - if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") + # rp2040 family handles warnings and linker map in its own family_configure_example + if (FAMILY STREQUAL "rp2040") + # skip - handled by rp2040_family_configure_example_warnings + elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") target_compile_options(${TARGET} PRIVATE ${WARN_FLAGS_${CMAKE_C_COMPILER_ID}}) target_link_options(${TARGET} PUBLIC "LINKER:-Map=$<TARGET_FILE:${TARGET}>.map") if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0 @@ -557,11 +602,11 @@ endfunction() #------------------------------------------------------- # Example Target Configure (Default rule) -# These function can be redefined in FAMILY/family.cmake +# These function can be overridden in FAMILY/family.cmake #-------------------------------------------------------- function(family_configure_example TARGET RTOS) - # empty function, should be redefined in FAMILY/family.cmake + # empty function, should be overridden in FAMILY/family.cmake endfunction() # Configure device example with RTOS diff --git a/hw/bsp/rp2040/family.c b/hw/bsp/rp2040/family.c index b5a1375a2..a4642face 100644 --- a/hw/bsp/rp2040/family.c +++ b/hw/bsp/rp2040/family.c @@ -298,6 +298,20 @@ void board_init_after_tusb(void) { // nothing to do } +//--------------------------------------------------------------------+ +// FreeRTOS hooks +//--------------------------------------------------------------------+ +#if CFG_TUSB_OS == OPT_OS_FREERTOS +#include "FreeRTOS.h" +#include "task.h" + +void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName) { + (void) xTask; + (void) pcTaskName; + panic("FreeRTOS stack overflow: %s", pcTaskName); +} +#endif + void board_reset_to_bootloader(void) { // not implemented } diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index 2e2cd436a..f125caafe 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -231,36 +231,32 @@ function(family_add_default_example_warnings TARGET) endif() endfunction() +function(family_add_board BOARD_TARGET) + add_library(${BOARD_TARGET} INTERFACE) +endfunction() -# TODO merge with family_configure_common from family_support.cmake -function(family_configure_target TARGET RTOS) - if (RTOS STREQUAL noos OR RTOS STREQUAL "") - set(RTOS_SUFFIX "") - else() - set(RTOS_SUFFIX _${RTOS}) - endif() - # export RTOS_SUFFIX to parent scope - set(RTOS_SUFFIX ${RTOS_SUFFIX} PARENT_SCOPE) - # compile define from command line - if(DEFINED CFLAGS_CLI) - separate_arguments(CFLAGS_CLI) - target_compile_options(${TARGET} PUBLIC ${CFLAGS_CLI}) +function(family_configure_example TARGET RTOS) + # Set OS per-target: FreeRTOS or Pico SDK + if (NOT DEFINED RTOS) + set(RTOS noos CACHE STRING "RTOS") + endif () + + family_configure_common(${TARGET} ${RTOS}) + + # Set OS for non-RTOS targets (RTOS targets get it from family_add_rtos) + if (NOT RTOS STREQUAL "freertos") + target_compile_definitions(${TARGET} PUBLIC CFG_TUSB_OS=${TINYUSB_OPT_OS}) endif() pico_add_extra_outputs(${TARGET}) pico_enable_stdio_uart(${TARGET} 1) - target_link_options(${TARGET} PUBLIC "LINKER:-Map=$<TARGET_FILE:${TARGET}>.map") - target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_board${RTOS_SUFFIX} tinyusb_additions) + target_link_options(${TARGET} PUBLIC "LINKER:-Map=$<TARGET_FILE:${TARGET}>.map") + target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_board tinyusb_additions) - family_flash_openocd(${TARGET}) + family_flash_openocd(${TARGET}) family_flash_jlink(${TARGET}) - - # Generate linkermap target and post build. LINKERMAP_OPTION can be set with -D to change default options - family_add_bloaty(${TARGET}) - family_add_linkermap(${TARGET}) - family_add_membrowse(${TARGET}) endfunction() @@ -276,8 +272,8 @@ endfunction() function(family_configure_device_example TARGET RTOS) - family_configure_target(${TARGET} ${RTOS}) - target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_device${RTOS_SUFFIX}) + family_configure_example(${TARGET} ${RTOS}) + target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_device) rp2040_family_configure_example_warnings(${TARGET}) endfunction() @@ -298,8 +294,8 @@ function(is_compiler_supported_by_pico_pio_usb OUTVAR) endfunction() function(family_configure_host_example TARGET RTOS) - family_configure_target(${TARGET} ${RTOS}) - target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_host${RTOS_SUFFIX}) + family_configure_example(${TARGET} ${RTOS}) + target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_host) rp2040_family_configure_example_warnings(${TARGET}) # For rp2040 enable pico-pio-usb @@ -319,7 +315,7 @@ endfunction() function(family_configure_dual_usb_example TARGET RTOS) - family_configure_target(${TARGET} ${RTOS}) + family_configure_example(${TARGET} ${RTOS}) # require tinyusb_pico_pio_usb target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_device tinyusb_host tinyusb_pico_pio_usb ) rp2040_family_configure_example_warnings(${TARGET}) diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py index f23e2fc22..d50a60894 100755 --- a/test/hil/hil_test.py +++ b/test/hil/hil_test.py @@ -102,6 +102,8 @@ def get_serial_dev(id, vendor_str, product_str, ifnum): # just use id: mostly for cp210x/ftdi flasher pattern = f'/dev/serial/by-id/usb-*_{id}-if*' port_list = glob.glob(pattern) + if len(port_list) == 0: + raise RuntimeError(f'No serial device found for {pattern}') return port_list[0] diff --git a/tools/get_deps.py b/tools/get_deps.py index 23f015c0d..eb87abf6e 100755 --- a/tools/get_deps.py +++ b/tools/get_deps.py @@ -12,7 +12,7 @@ deps_mandatory = { '30ca13c62615df0d2e9104ab41256985b96590c1', 'all'], 'lib/FreeRTOS-Kernel': ['https://github.com/FreeRTOS/FreeRTOS-Kernel.git', - 'cc0e0707c0c748713485b870bb980852b210877f', + '9b777ae5c5b8e9e456065a00294d1e5f5f9facf5', 'all'], 'lib/lwip': ['https://github.com/lwip-tcpip/lwip.git', '159e31b689577dbf69cf0683bbaffbd71fa5ee10', @@ -82,6 +82,9 @@ deps_optional = { 'hw/mcu/nxp/mcux-devices-rt': ['https://github.com/nxp-mcuxpresso/mcux-devices-rt', 'dba2b523c9df61f3330bd186242f8210a8e47c45', 'imxrt'], + 'hw/mcu/raspberry_pi/FreeRTOS-Kernel': ['https://github.com/raspberrypi/FreeRTOS-Kernel.git', + '4f7299d6ea746b27a9dd19e87af568e34bd65b15', + 'rp2040'], 'hw/mcu/raspberry_pi/Pico-PIO-USB': ['https://github.com/sekigon-gonnoc/Pico-PIO-USB.git', '675543bcc9baa8170f868ab7ba316d418dbcf41f', 'rp2040'], |
