[FreeRTOS].FreeRTOS CortexM3 M4中斷優先級設置總結

轉自:https://blog.csdn.net/xukai871105/article/details/53516857html

前言
本文將說明在FreeRTOS嵌入式操做系統中,如何設置STM32 Cortex M3和M4系列MCU的中斷優先級。
總結spa

  • 【1】STM32L1系列,STM32F1系列,STM32F4系列,設置NVIC時須要使用NVIC_PriorityGroup_4。
  • 【2】搶佔優先級的要比「MAX」更大,而比「LOWEST」更小。例如 configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY=5 , configLIBRARY_LOWEST_INTERRUPT_PRIORITY=15 ,那麼NVIC搶佔優先級設置的具體值應該比MAX=5更大(包括等於),比LOWEST=15更小(包括等於),也就是說5,6,7,8,9,10,11,12,13,14,15確定是合法值。
  • 【3】FreeRTOS中,數值越大優先級越高,這種優先級能夠成爲邏輯優先級。Cortex M3/M4中斷中,數值越大優先級越低,這種優先級成爲中斷優先級。二者相反,因此纔會出現比"MAX"更大而比「LOWEST」更小的狀況。

示意代碼
【FreeRTOSConfig.h】操作系統

/* Use the system definition, if there is one */
#ifdef __NVIC_PRIO_BITS
#define configPRIO_BITS __NVIC_PRIO_BITS
#else
#define configPRIO_BITS 4 /* 15 priority levels */
#endif

#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY    15
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY    5
/* The lowest priority. */
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* Priority 5, or 95 as only the top four bits are implemented. */
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )

【NVIC設置】
【示例A】.net

NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

NVIC_InitStructure.NVIC_IRQChannel = XXXX_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_LOWEST_INTERRUPT_PRIORITY;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

【示例A】code

NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

NVIC_InitStructure.NVIC_IRQChannel = XXXX_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_LOWEST_INTERRUPT_PRIORITY-1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
相關文章
相關標籤/搜索