Precautions when porting freertos to stm32

1. stm32 interrupt vector table configuration

In the use of STM32 , because the setting of interrupt priority uses library functions, please ensure that all priorities are set to preemptible priorities. The specific implementation method is to call the function before RTOS starts: NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4 );

Setting the priority grouping of NVIC to 4 indicates that the preemption priority levels 0-15 are supported (note that levels 0-15 are 16 levels, including level 0 ), and sub-priority is not supported.  

Continue to emphasize this point here. When the NVIC grouping is 4 , the configurable range of preemption priority is 0-15 , then the smaller the value, the higher the preemption priority level, that is, 0 represents the highest priority, 15 represents lowest priority. 


2. Interrupt-related configuration in freertos

#ifdef __NVIC_PRIO_BITS
	#define configPRIO_BITS __NVIC_PRIO_BITS
#else
	#define configPRIO_BITS       		4                  
#endif

This macro defines the actual number of bits used to configure the 8 -bit priority setting register of the STM32 . Keep the default, no configuration required.

#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY			15                      

This macro definition is used to configure the priority of the SysTick interrupt and PendSV interrupt used by FreeRTOS . When the NVIC grouping is set to 4 , the range defined by this macro is 0-15 , that is, the preemption priority is specially configured. The configuration here is 0x0f , that is, both SysTick and PendSV are configured with the lowest priority. In actual projects, it is also recommended that you configure the lowest priority. Keep the default, no configuration required.

#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY	5                      

This macro definition is more important and defines the highest priority interrupt managed by FreeRTOS . Simply put, it is the highest priority that allows the user to call the FreeRTOS API in this interrupt service routine . In the case of setting the priority grouping of NVIC to 4 . Configuring configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY to 0x05  means that users can call FreeRTOS API functions in interrupts with preemptive priority levels 5 to 15. Calls are not allowed in interrupts with preemptive priority levels 0 , 1 , 2, 3, and 4 . This can be modified according to actual needs. 


3. Why configure interrupt priority that is not controlled by Freertos

Are there any deep implications for interrupts not managed by FreeRTOS ?

Before explaining the interrupts that are not managed by FreeRTOS , there is a small knowledge point - interrupt latency. Interrupt delay time is an important indicator to measure RTOS real-time operating system, so what is interrupt delay? The time from the interrupt trigger to the execution of the first instruction of the interrupt service routine is the interrupt latency.
There are many places in the FreeRTOS
kernel source code to switch global interrupts, which will increase the interrupt delay time. For example, if the global interrupt is turned off somewhere in the source code, but an external interrupt is triggered at this time, the service routine of this interrupt needs to wait until the global interrupt is turned on again before it can be executed. The longer the time between switching interruptions, the larger the interruption delay time, which greatly affects the real-time performance of the system.

If this is an urgent interruption event and it is not implemented in time, the consequences can be imagined. In response to this situation, FreeRTOS has specially made a new switch interrupt implementation mechanism. When closing interrupts, only the interrupts managed by FreeRTOS are closed, and the interrupts not managed by FreeRTOS are not closed. These unmanaged interrupts are high-priority interrupts, and users can add programs that require real-time response to these interrupts.

4. What else needs to be configured in the FreeRTOSConfig.h file

#define configCPU_CLOCK_HZ						(SystemCoreClock)       //CPUƵÂÊ
#define configTICK_RATE_HZ						(200)   
These two items configure the system's clock and the heartbeat frequency of the tick timer. Once these two items are determined, the time slice is also determined.







Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324661509&siteId=291194637