From bdb96189386c65b9ba24634f58f220278768bd04 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 31 Mar 2026 22:00:22 -1000 Subject: [PATCH] Enable configSUPPORT_STATIC_ALLOCATION for all LibreTiny platforms The FreeRTOS timer command queue moves from heap to BSS on all LibreTiny targets, not just BK72xx. RTL87xx and LN882x benefit from the same heap savings. --- esphome/components/libretiny/__init__.py | 12 +++++++----- esphome/components/libretiny/freertos_static_alloc.c | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/esphome/components/libretiny/__init__.py b/esphome/components/libretiny/__init__.py index 91fdf002305..2eeb8809976 100644 --- a/esphome/components/libretiny/__init__.py +++ b/esphome/components/libretiny/__init__.py @@ -438,11 +438,13 @@ async def component_to_code(config): # 4-8KB flash). Even if linked, it would use locks, so explicit FreeRTOS # mutexes are simpler and equivalent. cg.add_define(ThreadModel.MULTI_NO_ATOMICS) - # Enable FreeRTOS static allocation so FreeRTOSQueue can use - # xQueueCreateStatic (queue storage in BSS, no heap allocation). - # BK72xx's FreeRTOSConfig.h doesn't define this, defaulting to 0. - # The -D wins over the #ifndef default in FreeRTOS.h. - cg.add_build_flag("-DconfigSUPPORT_STATIC_ALLOCATION=1") + + # Enable FreeRTOS static allocation APIs (xQueueCreateStatic, etc.). + # Moves FreeRTOS internal structures (timer command queue) from heap to BSS, + # and allows FreeRTOSQueue to use xQueueCreateStatic on BK72xx. + # LibreTiny's FreeRTOSConfig.h doesn't define this, defaulting to 0. + # The -D wins over the #ifndef default in FreeRTOS.h. + cg.add_build_flag("-DconfigSUPPORT_STATIC_ALLOCATION=1") # RTL8710B needs FreeRTOS 8.2.3+ for xTaskNotifyGive/ulTaskNotifyTake # required by AsyncTCP 3.4.3+ (https://github.com/esphome/esphome/issues/10220) diff --git a/esphome/components/libretiny/freertos_static_alloc.c b/esphome/components/libretiny/freertos_static_alloc.c index cd919e86a9e..dc95eda7854 100644 --- a/esphome/components/libretiny/freertos_static_alloc.c +++ b/esphome/components/libretiny/freertos_static_alloc.c @@ -10,7 +10,7 @@ * allowing queue storage to live in BSS with zero runtime heap allocation. */ -#ifdef USE_BK72XX +#ifdef USE_LIBRETINY #include #include @@ -45,4 +45,4 @@ void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackT #endif /* configSUPPORT_STATIC_ALLOCATION */ -#endif /* USE_BK72XX */ +#endif /* USE_LIBRETINY */