From 44b0ee05390b0f97d006a016b25fa513699e0a96 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 14 Apr 2026 10:51:20 +0700 Subject: get freertos working with rp2040 --- .idea/cmake.xml | 6 +- .../device/audio_4_channel_mic_freertos/skip.txt | 1 - .../device/audio_4_channel_mic_freertos/src/main.c | 2 +- examples/device/audio_test_freertos/skip.txt | 1 - examples/device/cdc_msc_freertos/skip.txt | 1 - examples/device/cdc_msc_freertos/src/msc_disk.c | 2 +- examples/device/hid_composite_freertos/skip.txt | 1 - examples/device/midi_test_freertos/skip.txt | 1 - examples/host/cdc_msc_hid_freertos/skip.txt | 1 - hw/bsp/family_support.cmake | 71 ++++++++++++++++++---- hw/bsp/rp2040/family.c | 14 +++++ hw/bsp/rp2040/family.cmake | 48 +++++++-------- test/hil/hil_test.py | 2 + 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 @@ - + - + @@ -101,6 +101,8 @@ + + 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=$.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=$.map") - target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_board${RTOS_SUFFIX} tinyusb_additions) + target_link_options(${TARGET} PUBLIC "LINKER:-Map=$.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'], -- cgit v1.3.1 From b55786e43af764397ebadf96609d77826d38bffe Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 14 Apr 2026 13:17:12 +0700 Subject: refactor rp2040 family.cmake to use family_configure_example() and apply WARN_FLAGS to tinyusb sources and examples sources only (skip 3rd party library and mcu vendor) --- examples/host/msc_file_explorer/CMakeLists.txt | 14 +-- hw/bsp/family_support.cmake | 38 +------ hw/bsp/rp2040/FreeRTOSConfig/FreeRTOSConfig.h | 144 +++++++++++++++++++++++++ hw/bsp/rp2040/family.cmake | 117 ++++---------------- 4 files changed, 177 insertions(+), 136 deletions(-) create mode 100644 hw/bsp/rp2040/FreeRTOSConfig/FreeRTOSConfig.h diff --git a/examples/host/msc_file_explorer/CMakeLists.txt b/examples/host/msc_file_explorer/CMakeLists.txt index 21703030c..3c6d3352a 100644 --- a/examples/host/msc_file_explorer/CMakeLists.txt +++ b/examples/host/msc_file_explorer/CMakeLists.txt @@ -23,13 +23,6 @@ target_sources(${PROJECT_NAME} PUBLIC ${TOP}/lib/fatfs/source/ffunicode.c ) -# Suppress warnings on fatfs -if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") - set_source_files_properties(${TOP}/lib/fatfs/source/ff.c PROPERTIES - COMPILE_FLAGS "-Wno-conversion -Wno-cast-qual" - ) -endif () - # Example include target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src @@ -40,3 +33,10 @@ target_include_directories(${PROJECT_NAME} PUBLIC # Configure compilation flags and libraries for the example without RTOS. # See the corresponding function in hw/bsp/FAMILY/family.cmake for details. family_configure_host_example(${PROJECT_NAME} noos) + +# Suppress warnings on fatfs +if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") + set_source_files_properties(${TOP}/lib/fatfs/source/ff.c PROPERTIES + COMPILE_OPTIONS "-Wno-conversion -Wno-cast-qual" + ) +endif () diff --git a/hw/bsp/family_support.cmake b/hw/bsp/family_support.cmake index d69884407..cb8ec6cf8 100644 --- a/hw/bsp/family_support.cmake +++ b/hw/bsp/family_support.cmake @@ -378,32 +378,10 @@ function(family_add_rtos TARGET RTOS) 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) + # FreeRTOS_Kernel_import.cmake auto-selects RP2040/RP2350/RISC-V port based on PICO_PLATFORM + include(${FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.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) @@ -420,13 +398,6 @@ function(family_add_rtos TARGET RTOS) target_link_libraries(${TARGET} PUBLIC 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_compile_definitions(${TARGET} PUBLIC CFG_TUSB_OS=OPT_OS_FREERTOS) elseif (RTOS STREQUAL "threadx") if (NOT TARGET threadx) @@ -507,9 +478,10 @@ function(family_configure_common TARGET RTOS) target_compile_definitions(${TARGET} PUBLIC LOGGER_UART) endif () - # 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 + # RP2040: apply warnings per-source-file (not per-target) since Pico SDK sources + # are INTERFACE and would not inherit target-level warnings correctly + family_add_default_example_warnings(${TARGET}) 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=$.map") diff --git a/hw/bsp/rp2040/FreeRTOSConfig/FreeRTOSConfig.h b/hw/bsp/rp2040/FreeRTOSConfig/FreeRTOSConfig.h new file mode 100644 index 000000000..fe030e6dc --- /dev/null +++ b/hw/bsp/rp2040/FreeRTOSConfig/FreeRTOSConfig.h @@ -0,0 +1,144 @@ +/* + * FreeRTOS V202111.00 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/* Scheduler Related */ +#define configUSE_PREEMPTION 1 +#define configUSE_TICKLESS_IDLE 0 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) +#define configMAX_PRIORITIES 5 +#define configMINIMAL_STACK_SIZE ( configSTACK_DEPTH_TYPE ) 128 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 + +/* Synchronization Related */ +#define configUSE_MUTEXES 1 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configQUEUE_REGISTRY_SIZE 4 +#define configUSE_QUEUE_SETS 0 +#define configUSE_TIME_SLICING 0 +#define configUSE_NEWLIB_REENTRANT 0 +#define configENABLE_BACKWARD_COMPATIBILITY 1 +#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5 + +/* System */ +#define configSTACK_DEPTH_TYPE uint32_t +#define configMESSAGE_BUFFER_LENGTH_TYPE size_t + +/* Memory allocation related definitions. */ +#define configSUPPORT_STATIC_ALLOCATION 1 +#define configSUPPORT_DYNAMIC_ALLOCATION 0 +#define configTOTAL_HEAP_SIZE ( configSUPPORT_DYNAMIC_ALLOCATION * 4 * 1024 ) +#define configAPPLICATION_ALLOCATED_HEAP 0 + +/* Hook function related definitions. */ +#define configCHECK_FOR_STACK_OVERFLOW 2 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_DAEMON_TASK_STARTUP_HOOK 0 +#define configCHECK_HANDLER_INSTALLATION 0 + +/* Run time and task stats gathering related definitions. */ +#define configGENERATE_RUN_TIME_STATS 0 +#define configRECORD_STACK_HIGH_ADDRESS 1 +#define configUSE_TRACE_FACILITY 1 +#define configUSE_STATS_FORMATTING_FUNCTIONS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES 2 + +/* Software timer related definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 2 ) +#define configTIMER_QUEUE_LENGTH 32 +#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE + +/* SMP port configuration (set by the RP2xxx SMP port of FreeRTOS) */ +#if FREE_RTOS_KERNEL_SMP +#ifndef configNUMBER_OF_CORES +#define configNUMBER_OF_CORES 1 +#endif +#define configNUM_CORES configNUMBER_OF_CORES +#define configTICK_CORE 0 +#define configRUN_MULTIPLE_PRIORITIES 1 +#if configNUMBER_OF_CORES > 1 +#define configUSE_CORE_AFFINITY 1 +#endif +#define configUSE_PASSIVE_IDLE_HOOK 0 +#endif + +/* RP2040/RP2350 specific */ +#define configSUPPORT_PICO_SYNC_INTEROP 1 +#define configSUPPORT_PICO_TIME_INTEROP 1 +#define configUSE_DYNAMIC_EXCEPTION_HANDLERS 0 + +/* Macros used in #if without #ifdef guards in port headers, + * must be explicitly defined to avoid -Wundef warnings. */ +#ifndef PICO_DIVIDER_DISABLE_INTERRUPTS +#define PICO_DIVIDER_DISABLE_INTERRUPTS 0 +#endif +#define portARMV8M_MINOR_VERSION 0 + +#if defined(PICO_RP2350) && PICO_RP2350 +/* Cortex-M33 port configuration (RP2350). */ +#define configENABLE_MPU 0 +#define configENABLE_FPU 1 +#define configENABLE_MVE 0 +#define configENABLE_TRUSTZONE 0 +#define configRUN_FREERTOS_SECURE_ONLY 1 +#define configMAX_SYSCALL_INTERRUPT_PRIORITY 16 +#endif + +#include +#define configASSERT(x) assert(x) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 0 +#define INCLUDE_uxTaskPriorityGet 0 +#define INCLUDE_vTaskDelete 0 +#define INCLUDE_vTaskSuspend 1 // required for portMAX_DELAY +#define INCLUDE_xResumeFromISR 0 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 0 +#define INCLUDE_xTaskGetCurrentTaskHandle 1 +#define INCLUDE_uxTaskGetStackHighWaterMark 0 +#define INCLUDE_xTaskGetIdleTaskHandle 0 +#define INCLUDE_xTimerGetTimerDaemonTaskHandle 0 +#define INCLUDE_pcTaskGetTaskName 0 +#define INCLUDE_eTaskGetState 0 +#define INCLUDE_xEventGroupSetBitFromISR 1 +#define INCLUDE_xTimerPendFunctionCall 1 + +#endif /* FREERTOS_CONFIG_H */ diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index f125caafe..1e49c7194 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -194,41 +194,27 @@ endif() # Functions #------------------------------------ function(family_add_default_example_warnings TARGET) + if (DEFINED PICO_TINYUSB_NO_EXAMPLE_WARNINGS) + return() + endif () + # Apply warnings to all TinyUSB interface library sources as well as examples sources # we cannot set compile options for target since it will not propagate to INTERFACE sources then picosdk files + get_target_property(EXAMPLE_SOURCES ${TARGET} SOURCES) + set_source_files_properties(${EXAMPLE_SOURCES} PROPERTIES COMPILE_OPTIONS "${WARN_FLAGS_${CMAKE_C_COMPILER_ID}}") + foreach(TINYUSB_TARGET IN ITEMS tinyusb_common_base tinyusb_device_base tinyusb_host_base tinyusb_host_max3421 tinyusb_bsp) get_target_property(TINYUSB_SOURCES ${TINYUSB_TARGET} INTERFACE_SOURCES) set_source_files_properties(${TINYUSB_SOURCES} PROPERTIES COMPILE_OPTIONS "${WARN_FLAGS_${CMAKE_C_COMPILER_ID}}") - endforeach() - - # Also apply to example sources, but filter out any source files from lib/ (e.g. fatfs) - get_target_property(EXAMPLE_SOURCES ${TARGET} SOURCES) - set(FILTERED_SOURCES "") - foreach(SOURCE_FILE IN LISTS EXAMPLE_SOURCES) - string(FIND "${SOURCE_FILE}" "${TOP}/lib" FOUND_POS) - if(FOUND_POS EQUAL -1) - list(APPEND FILTERED_SOURCES ${SOURCE_FILE}) - endif() - endforeach() - set_source_files_properties(${FILTERED_SOURCES} PROPERTIES COMPILE_OPTIONS "${WARN_FLAGS_${CMAKE_C_COMPILER_ID}}") + endforeach() if (CMAKE_C_COMPILER_ID STREQUAL "GNU") if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0 AND NO_WARN_RWX_SEGMENTS_SUPPORTED) target_link_options(${TARGET} PRIVATE "LINKER:--no-warn-rwx-segments") endif() - - if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0) - target_compile_options(${TARGET} PRIVATE -Wconversion) - endif() - - if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - target_compile_options(${TARGET} PRIVATE -Wcast-function-type -Wstrict-overflow) - endif() - - if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0) - target_compile_options(${TARGET} PRIVATE -Wno-strict-aliasing) - endif() - endif() + elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") + target_compile_options(${TARGET} PRIVATE -Wno-unreachable-code) + endif () endfunction() function(family_add_board BOARD_TARGET) @@ -239,16 +225,21 @@ endfunction() function(family_configure_example TARGET RTOS) # Set OS per-target: FreeRTOS or Pico SDK if (NOT DEFINED RTOS) - set(RTOS noos CACHE STRING "RTOS") + set(RTOS noos) 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") + if (RTOS STREQUAL noos) target_compile_definitions(${TARGET} PUBLIC CFG_TUSB_OS=${TINYUSB_OPT_OS}) + else () + # remove CFG_TUSB_OS=OPT_OS_PICO from tinyusb_common_base to avoid redefinition + # NOTE: cannot remove it from interface declaration as pico-sdk use that + 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() + family_configure_common(${TARGET} ${RTOS}) pico_add_extra_outputs(${TARGET}) pico_enable_stdio_uart(${TARGET} 1) @@ -260,21 +251,9 @@ function(family_configure_example TARGET RTOS) endfunction() -function(rp2040_family_configure_example_warnings TARGET) - if (NOT PICO_TINYUSB_NO_EXAMPLE_WARNINGS) - family_add_default_example_warnings(${TARGET}) - endif() - if(CMAKE_C_COMPILER_ID STREQUAL "Clang") - target_compile_options(${TARGET} PRIVATE -Wno-unreachable-code) - endif() - suppress_tinyusb_warnings() -endfunction() - - function(family_configure_device_example TARGET RTOS) family_configure_example(${TARGET} ${RTOS}) target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_device) - rp2040_family_configure_example_warnings(${TARGET}) endfunction() @@ -296,7 +275,6 @@ endfunction() function(family_configure_host_example TARGET RTOS) 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 if (TARGET tinyusb_pico_pio_usb) @@ -317,8 +295,7 @@ endfunction() function(family_configure_dual_usb_example 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}) + target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_device tinyusb_host tinyusb_pico_pio_usb) endfunction() @@ -329,7 +306,6 @@ function(check_and_add_pico_pio_usb_support) #------------------------------------ # PIO USB for both host and device #------------------------------------ - if (NOT DEFINED PICO_PIO_USB_PATH) set(PICO_PIO_USB_PATH "${TOP}/hw/mcu/raspberry_pi/Pico-PIO-USB") endif() @@ -385,54 +361,3 @@ function(family_initialize_project PROJECT DIR) # now re-check for adding Pico-PIO_USB support now SDK is definitely available check_and_add_pico_pio_usb_support() endfunction() - - -# This method must be called from the project scope to suppress known warnings in TinyUSB source files -function(suppress_tinyusb_warnings) - # some of these are pretty silly warnings only occurring in some older GCC versions 9 or prior - if (CMAKE_C_COMPILER_ID STREQUAL "GNU") - if (CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0) - set(CONVERSION_WARNING_FILES - ${PICO_TINYUSB_PATH}/src/tusb.c - ${PICO_TINYUSB_PATH}/src/common/tusb_fifo.c - ${PICO_TINYUSB_PATH}/src/device/usbd.c - ${PICO_TINYUSB_PATH}/src/device/usbd_control.c - ${PICO_TINYUSB_PATH}/src/host/usbh.c - ${PICO_TINYUSB_PATH}/src/class/cdc/cdc_device.c - ${PICO_TINYUSB_PATH}/src/class/cdc/cdc_host.c - ${PICO_TINYUSB_PATH}/src/class/hid/hid_device.c - ${PICO_TINYUSB_PATH}/src/class/hid/hid_host.c - ${PICO_TINYUSB_PATH}/src/class/audio/audio_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/midi/midi_device.c - ${PICO_TINYUSB_PATH}/src/class/usbtmc/usbtmc_device.c - ${PICO_TINYUSB_PATH}/src/portable/raspberrypi/rp2040/hcd_rp2040.c - ) - foreach(SOURCE_FILE IN LISTS CONVERSION_WARNING_FILES) - set_source_files_properties(${SOURCE_FILE} PROPERTIES COMPILE_FLAGS "-Wno-conversion") - endforeach() - endif() - - if (TARGET tinyusb_pico_pio_usb) - set_source_files_properties( - ${PICO_TINYUSB_PATH}/hw/mcu/raspberry_pi/Pico-PIO-USB/src/pio_usb_device.c - ${PICO_TINYUSB_PATH}/hw/mcu/raspberry_pi/Pico-PIO-USB/src/pio_usb.c - ${PICO_TINYUSB_PATH}/hw/mcu/raspberry_pi/Pico-PIO-USB/src/pio_usb_host.c - ${PICO_TINYUSB_PATH}/src/portable/raspberrypi/pio_usb/hcd_pio_usb.c - PROPERTIES - COMPILE_FLAGS "-Wno-conversion -Wno-cast-qual -Wno-attributes") - endif() - elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang") - set_source_files_properties( - ${PICO_TINYUSB_PATH}/src/class/cdc/cdc_device.c - COMPILE_FLAGS "-Wno-unreachable-code") - set_source_files_properties( - ${PICO_TINYUSB_PATH}/src/class/cdc/cdc_host.c - COMPILE_FLAGS "-Wno-unreachable-code-fallthrough") - set_source_files_properties( - ${PICO_TINYUSB_PATH}/lib/fatfs/source/ff.c - PROPERTIES - COMPILE_FLAGS "-Wno-cast-qual") - endif() -endfunction() -- cgit v1.3.1 From 5da96a38f046aeaaf2e7f3dddb0b6d11b169a779 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 14 Apr 2026 14:04:07 +0700 Subject: fix ci --- examples/host/msc_file_explorer/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/host/msc_file_explorer/CMakeLists.txt b/examples/host/msc_file_explorer/CMakeLists.txt index 3c6d3352a..c8d196447 100644 --- a/examples/host/msc_file_explorer/CMakeLists.txt +++ b/examples/host/msc_file_explorer/CMakeLists.txt @@ -37,6 +37,6 @@ family_configure_host_example(${PROJECT_NAME} noos) # Suppress warnings on fatfs if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") set_source_files_properties(${TOP}/lib/fatfs/source/ff.c PROPERTIES - COMPILE_OPTIONS "-Wno-conversion -Wno-cast-qual" + COMPILE_OPTIONS "-Wno-conversion;-Wno-cast-qual" ) endif () -- cgit v1.3.1 From e32a510ce610507717d940d329169d8939c10eab Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 14 Apr 2026 19:14:05 +0700 Subject: remove -Werror from example sources to prevent build examples --- hw/bsp/rp2040/family.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index 1e49c7194..6e88b9fa1 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -200,8 +200,13 @@ function(family_add_default_example_warnings TARGET) # Apply warnings to all TinyUSB interface library sources as well as examples sources # we cannot set compile options for target since it will not propagate to INTERFACE sources then picosdk files + # Remove -Werror from example sources so per-file warning suppressions can work. + # -Werror is kept on TinyUSB sources to catch real issues. + set(example_warn_flags ${WARN_FLAGS_${CMAKE_C_COMPILER_ID}}) + list(REMOVE_ITEM example_warn_flags -Werror) + get_target_property(EXAMPLE_SOURCES ${TARGET} SOURCES) - set_source_files_properties(${EXAMPLE_SOURCES} PROPERTIES COMPILE_OPTIONS "${WARN_FLAGS_${CMAKE_C_COMPILER_ID}}") + set_source_files_properties(${EXAMPLE_SOURCES} PROPERTIES COMPILE_OPTIONS "${example_warn_flags}") foreach(TINYUSB_TARGET IN ITEMS tinyusb_common_base tinyusb_device_base tinyusb_host_base tinyusb_host_max3421 tinyusb_bsp) get_target_property(TINYUSB_SOURCES ${TINYUSB_TARGET} INTERFACE_SOURCES) -- cgit v1.3.1 From e7642cf753b67bcfee21983e2caa292c2722ba4c Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 14 Apr 2026 20:06:26 +0700 Subject: suppress null-dereference warnings in FreeRTOS builds --- hw/bsp/family_support.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/bsp/family_support.mk b/hw/bsp/family_support.mk index 69aa08922..6b08f6e88 100644 --- a/hw/bsp/family_support.mk +++ b/hw/bsp/family_support.mk @@ -170,6 +170,7 @@ ifeq ($(RTOS),freertos) # Suppress FreeRTOS source warnings CFLAGS += -Wno-error=cast-qual + CFLAGS += -Wno-error=null-dereference # FreeRTOS (lto + Os) linker issue LDFLAGS += -Wl,--undefined=vTaskSwitchContext -- cgit v1.3.1