1. How to port FreeRTOS to different Cortex-M cores?
Answer: To port FreeRTOS to the correct Cortex-M product, you must import the “port.c” file from the correct directory. For example, if the microcontroller has an IAR tool with a Cortex-M0 core, you need to get port.c from “FreeRTOS\Source\portable\IAR\ARM_CM0”.
2. Does FreeRTOS require ROM/RAM?
Answer: It depends on your compiler, code architecture, and RTOS kernel configuration. Generally, the RTOS kernel itself requires about 5 to 10 K bytes of ROM space.
If the number of threads or queues created increases, the RAM usage will also rise.
3. How to set the CPU clock?
Answer: The CPU clock is defined by configCPU_CLOCK_HZ in FreeRTOSConfig.h, for example, in STM32CubeF4 firmware, it is provided by SystemCoreClock, which indicates the HCLK clock (AHB bus), and this value is set when configuring the RCC clock by calling the SystemClock_Config() function.
4. How to set interrupt priorities?
Answer: Any interrupt service routine that uses RTOS API functions must have its priority manually set to be greater than or equal to the value set in configMAX_SYSCALL_INTERRUPT_PRIORITY in FreeRTOSConfig.h. This ensures that the logical priority of the interrupt is lower than or equal to the priority set by configMAX_SYSCALL_INTERRUPT_PRIORITY.
5. How to use a non-SysTick clock to generate time slice interrupts?
Answer: Users can optionally provide their own time slice interrupt source by using a non-SysTick timer to generate interrupts:
• Provide an implementation of vPortSetupTimerInterrupt() that generates interrupts at the frequency specified by the configTICK_RATE_HZ constant defined in FreeRTOSConfig.h.
• Configure xPortSysTickHandler() as the handler for the timer interrupt, ensuring that xPortSysTickHandler() is not mapped to SysTick_Handler() in FreeRTOSConfig.h, or is not named SysTick_Handler() in port.c.
6. How to enable tickless idle mode?
Answer: FreeRTOS tickless mode (low power) reduces MCU power consumption by entering sleep mode and stopping periodic time slice interrupts. To enable this feature, set configUSE_TICKLESS_IDLE to 1 in FreeRTOSConfig.h.
When using a non-SysTick timer to generate time slice interrupts, tickless idle mode can also be enabled. Users must add the following actions to the content described in the previous question:
• In FreeRTOSConfig.h, set configUSE_TICKLESS_IDLE to 2.
• Define portSUPPRESS_TICKS_AND_SLEEP() according to the relevant FreeRTOS documentation.
7. What are the common issues encountered in FreeRTOS applications based on STM32?
Answer: These would be issues related to STACK overflow and interrupt priorities.
The content is derived from an official ST user manual UM1722 about STM32Cube development applications with RTOS, which provides detailed information on the following topics. This article only includes the FAQ section.
For those interested, you can visit www.stmcu.com.cn or www.stmcu.org or www.st.com to search for UM1722 【Chinese and English versions】 to download and read more details.