I am learning about how to use FreeRTOS and STM32duino. I added the the STM32FreeRTOS library to my project and try to use heap_4.c. I could manually set the heap size by the macro configTOTAL_HEAP_SIZE
, but I want it be set automatically.
So I set configAPPLICATION_ALLOCATED_HEAP
to 1 and declare a byte array uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
in my main.cpp
. The macro configTOTAL_HEAP_SIZE
should be replaced by ((size_t)((uint32_t)&_estack - (uint32_t)&_Min_Stack_Size - (uint32_t)&_end))
, And the compiler says that it is not an integral constant-expression.
_estack
, _Min_Stack_Size
and _end
could be found in linker script. And I could print the right value of configTOTAL_HEAP_SIZE
, but I can’t use configTOTAL_HEAP_SIZE
to declare the heap.
[env:genericSTM32F407VET6]
platform = ststm32
board = genericSTM32F407VET6
framework = arduino
lib_archive = false
build_flags =
-D SERIAL_UART_INSTANCE=1
-D configMEMMANG_HEAP_NB=4
-D configAPPLICATION_ALLOCATED_HEAP=1
-D configSUPPORT_DYNAMIC_ALLOCATION=1
; I want to set heap size automatically
; -D configTOTAL_HEAP_SIZE=96*1024
lib_deps =
stm32duino/STM32duino FreeRTOS@^10.3.1
In file included from .pio/libdeps/genericSTM32F407VET6/STM32duino FreeRTOS/src/FreeRTOSConfig.h:17,
from .pio/libdeps/genericSTM32F407VET6/STM32duino FreeRTOS/src/FreeRTOS/Source/include/FreeRTOS.h:56,
from .pio/libdeps/genericSTM32F407VET6/STM32duino FreeRTOS/src/FreeRTOS.h:9,
from .pio/libdeps/genericSTM32F407VET6/STM32duino FreeRTOS/src/cmsis_os.h:9,
from src/main.cpp:3:
.pio/libdeps/genericSTM32F407VET6/STM32duino FreeRTOS/src/FreeRTOSConfig_Default.h:106:44: error: size of array 'ucHeap' is not an integral constant-expression
106 | #define configTOTAL_HEAP_SIZE ((size_t)((uint32_t)&_estack - (uint32_t)&_Min_Stack_Size - (uint32_t)&_end))
| ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.cpp:12:17: note: in expansion of macro 'configTOTAL_HEAP_SIZE'
12 | uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
thanks