Q: How to implement FreeRTOS on STM32: task creation priority and stack sizing?
Answer
FreeRTOS on STM32 is initialized via vTaskStartScheduler() after hardware setup. Task creation uses xTaskCreate() with parameters: task function name stack depth (in words not bytes) parameters priority and handle pointer. Higher numbers = higher priority. Stack sizing requires calculating worst-case usage – use uxTaskGetStackHighWaterMark() at runtime to tune. Avoid large local arrays on stack; use heap-allocated buffers instead. For STM32F4 the FPU context requires 88 additional bytes per task. Use configUSE_TIME_SLICING=1 for round-robin scheduling. Never call vTaskDelay() with 0 – use taskYIELD() instead. Stack overflow detection should be enabled during development.
Filed under: FAQ
