STM32 on FreeRTOS
When working with STM32 and FreeRTOS, memory management and interrupt priorities are the two most critical aspects.
The Setup
Using STM32CubeMX helps, but understanding what it generates is critical. For instance, the SysTick interrupt priority.
Math behind scheduling
A basic mathematical model for task shedulability in Rate Monotonic Analysis (RMA) is given by:
Where is computation time and is the period constraint.
Code snippet
Here is a basic setup for an LED blink task over RTOS:
void vTaskLed(void *pvParameters) {
for(;;) {
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
vTaskDelay(pdMS_TO_TICKS(500));
}
}
Remember to configure the priority grouping correctly via NVIC_SetPriorityGrouping(0);.