From 9746ed42cc776332abaa6097d581db3fd06a8344 Mon Sep 17 00:00:00 2001 From: bernard Date: Sat, 24 Oct 2026 10:20:32 +0800 Subject: [PATCH 1/2] [bsp][esp32] fix FreeRTOS include order for C3/C6 builds ESP-IDF's scons shim forwards with #include_next, so RT-Thread's FreeRTOS-Wrapper must be searched after the shim but before ESP-IDF's own FreeRTOS-Kernel V11 copy. Package SConscripts are evaluated in directory order, which is not stable. When the ESP-IDF package happens to be evaluated first, #include_next resolves the V11 kernel header and the Wrapper configuration defaults are never applied, so the ESP32-C3/C6 builds fail with: #error Missing definition: configNUMBER_OF_CORES ... #error Missing definition: configMINIMAL_STACK_SIZE ... Move the Wrapper include directories back to the position right after the shim after PrepareBuilding(), in both BSPs, using a shared helper. Verified on the ESP32-C3/C6 BSPs by forcing the failing package order: drv_uart.c reports the errors above before the change and compiles after it. Co-authored-by: DeepSeek 4.1 Flash --- bsp/ESP/ESP32_C3/SConstruct | 4 +++ bsp/ESP/ESP32_C6/SConstruct | 4 +++ bsp/ESP/tools/freertos_include.py | 46 +++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 bsp/ESP/tools/freertos_include.py diff --git a/bsp/ESP/ESP32_C3/SConstruct b/bsp/ESP/ESP32_C3/SConstruct index 4b507b7b6a74..57b34386ce5b 100644 --- a/bsp/ESP/ESP32_C3/SConstruct +++ b/bsp/ESP/ESP32_C3/SConstruct @@ -68,6 +68,10 @@ Export('rtconfig') # prepare building environment objs = PrepareBuilding(env, RTT_ROOT, remove_components = ['libc']) +sys.path = sys.path + [os.path.join(os.path.dirname(SDK_ROOT), 'tools')] +from freertos_include import fix_freertos_include_order +fix_freertos_include_order(env) + objs.extend(SConscript(os.path.join(libraries_path_prefix, 'drivers', 'SConscript'), variant_dir='build/libraries/drivers', duplicate=0)) # make a building DoBuilding(TARGET, objs) diff --git a/bsp/ESP/ESP32_C6/SConstruct b/bsp/ESP/ESP32_C6/SConstruct index 2d877aebd133..6375e3a55033 100644 --- a/bsp/ESP/ESP32_C6/SConstruct +++ b/bsp/ESP/ESP32_C6/SConstruct @@ -164,6 +164,10 @@ _match_idf_spi_lock_stub_to_spi_config() objs = PrepareBuilding(env, RTT_ROOT, remove_components = ['libc']) +sys.path = sys.path + [os.path.join(os.path.dirname(SDK_ROOT), 'tools')] +from freertos_include import fix_freertos_include_order +fix_freertos_include_order(env) + objs.extend(SConscript(os.path.join(libraries_path_prefix, 'drivers', 'SConscript'), variant_dir='build/libraries/drivers', duplicate=0)) DoBuilding(TARGET, objs) diff --git a/bsp/ESP/tools/freertos_include.py b/bsp/ESP/tools/freertos_include.py new file mode 100644 index 000000000000..8e107208204a --- /dev/null +++ b/bsp/ESP/tools/freertos_include.py @@ -0,0 +1,46 @@ +"""Build helpers shared by the ESP32 BSPs.""" + +import os + + +def _norm(path): + return os.path.normcase(os.path.abspath(str(path))).replace('\\', '/').lower() + + +def fix_freertos_include_order(env): + """Keep the RT-Thread FreeRTOS-Wrapper first in the include search order. + + ESP-IDF's scons shim (components/rtthread/scons/include/freertos/FreeRTOS.h) + forwards with #include_next, so the Wrapper include + directories must be searched after the shim but before ESP-IDF's own + FreeRTOS-Kernel copy. Package SConscripts are evaluated in directory + order, which is not stable, so enforce the order after PrepareBuilding(). + """ + cpp = list(env.get('CPPPATH', [])) + shim = None + wrapper = [] + wrapper_keys = set() + + for path in cpp: + norm = _norm(path) + if norm.endswith('/components/rtthread/scons/include'): + if shim is None: + shim = path + elif '/freertos_wrapper-' in norm or '/freertos-wrapper-' in norm: + if norm not in wrapper_keys: + wrapper_keys.add(norm) + wrapper.append(path) + + if shim is None or not wrapper: + return + + # Drop the Wrapper entries first so that they can be inserted right after + # the shim, whatever order the package SConscripts ran in. + rest = [p for p in cpp if _norm(p) not in wrapper_keys] + + shim_key = _norm(shim) + for index, path in enumerate(rest): + if _norm(path) == shim_key: + rest[index + 1:index + 1] = wrapper + env.Replace(CPPPATH=rest) + return From 74852d853fe5ce8ac28dc6ce560197e08b1c098b Mon Sep 17 00:00:00 2001 From: bernard Date: Sat, 24 Oct 2026 10:47:16 +0800 Subject: [PATCH 2/2] [bsp][esp32] prefer the BSP FreeRTOSConfig in attachconfig builds Wi-Fi/BLE attachconfigs add ESP-IDF's components/freertos/config/include to the include path, and it was searched before the BSP's idf_port/include/freertos. The Wrapper's FreeRTOS.h then picked ESP-IDF's FreeRTOSConfig.h, whose configTASK_NOTIFICATION_ARRAY_ENTRIES maps to CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES -- a symbol the RT-Thread sdkconfig shim does not define -- and the ESP32-C3 BLE/Wi-Fi builds failed with "configTASK_NOTIFICATION_ARRAY_ENTRIES must be at least 1". Move the BSP idf_port include directories together with the Wrapper include directories, so the BSP configuration is used. Verified with the ESP32-C3 devices.ble and devices.wifi attachconfigs: idf_port/src/port.o fails before the change and compiles after it. Co-authored-by: DeepSeek 4.1 Flash --- bsp/ESP/tools/freertos_include.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/bsp/ESP/tools/freertos_include.py b/bsp/ESP/tools/freertos_include.py index 8e107208204a..a30bafbfcaf7 100644 --- a/bsp/ESP/tools/freertos_include.py +++ b/bsp/ESP/tools/freertos_include.py @@ -19,28 +19,39 @@ def fix_freertos_include_order(env): cpp = list(env.get('CPPPATH', [])) shim = None wrapper = [] - wrapper_keys = set() + front = [] + front_keys = set() for path in cpp: norm = _norm(path) if norm.endswith('/components/rtthread/scons/include'): if shim is None: shim = path - elif '/freertos_wrapper-' in norm or '/freertos-wrapper-' in norm: - if norm not in wrapper_keys: - wrapper_keys.add(norm) + continue + + if '/freertos_wrapper-' in norm or '/freertos-wrapper-' in norm: + if norm not in front_keys: + front_keys.add(norm) wrapper.append(path) + front.append(path) + elif norm.endswith('/idf_port/include') or \ + norm.endswith('/idf_port/include/freertos'): + # The BSP's FreeRTOSConfig.h must win over the ESP-IDF copy that + # Wi-Fi/BLE configurations add to the include path. + if norm not in front_keys: + front_keys.add(norm) + front.append(path) if shim is None or not wrapper: return - # Drop the Wrapper entries first so that they can be inserted right after - # the shim, whatever order the package SConscripts ran in. - rest = [p for p in cpp if _norm(p) not in wrapper_keys] + # Drop the Wrapper and BSP port config entries first so that they can be + # inserted right after the shim, whatever order the SConscripts ran in. + rest = [p for p in cpp if _norm(p) not in front_keys] shim_key = _norm(shim) for index, path in enumerate(rest): if _norm(path) == shim_key: - rest[index + 1:index + 1] = wrapper + rest[index + 1:index + 1] = front env.Replace(CPPPATH=rest) return