1. 程式人生 > >STM32與FreeRTOS學習備忘,xSemaphoreGiveFromISR

STM32與FreeRTOS學習備忘,xSemaphoreGiveFromISR

在學習FreeRTOS的時候,使用中斷釋放訊號量時,出現了問題。

中斷函式卡在xSemaphoreGiveFromISR();函式裡了,具體是卡在portASSERT_IF_INTERRUPT_PRIORITY_INVALID();裡。

根據註釋檢視http://www.freertos.org/RTOS-Cortex-M3-M4.html,裡面有兩點點出關鍵。

1.

Most systems default to the wanted configuration, with the noticeable exception of the STM32 driver library. If you are using an STM32 with the STM32 driver library then ensure all the priority bits are assigned to be preempt priority bits by calling NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );

 before the RTOS is started.

意味著選中斷分組時只能選preempt為4bit,sub為0bit,即preemption範圍0~15,sub priority範圍為0


2.

Relevance when using the RTOS

FreeRTOS functions that end in "FromISR" are interrupt safe, but even these functions cannot be called from interrupts that have a logical priority above the priority defined by configMAX_SYSCALL_INTERRUPT_PRIORITY (
configMAX_SYSCALL_INTERRUPT_PRIORITY is defined in the FreeRTOSConfig.h header file). Therefore, any interrupt service routine that uses an RTOS API function must have its priority manually set to a value that is numerically equal to or greater than the configMAX_SYSCALL_INTERRUPT_PRIORITY setting. This ensures the interrupt's logical priority is equal to or less than the configMAX_SYSCALL_INTERRUPT_PRIORITY setting.

Cortex-M interrupts default to having a priority value of zero. Zero is the highest possible priority value. Therefore, never leave the priority of an interrupt that uses the interrupt safe RTOS API at its default value.

意味著不能讓中斷優先號分配不能小於configMAX_SYSCALL_INTERRUPT_PRIORITY!!!最好的分配方法當然是尾部15分配起,而不是從頭部0開始分配。


讓GPIO的中斷優先號大於configMAX_SYSCALL_INTERRUPT_PRIORITY,即中斷優先號不優先於(logic above)你定義的最優中斷優先號就行,xSemaphoreGiveFromISR();就可以用了。