调试RT1052时,报Error:…\FreeRTOS\port\RVDS\ARM_CM7\r0p1\port.c,776问题: configASSERT( ( portAIRCR_REG & portPRIORITY_GROUP_MASK ) <= ulMaxPRIGROUPValue ); 分析:该问题为我们分配中断优先级组时不满足FreeRTOS的中断优先级分组规则 解决办法: 1、设置中断优先级组为4bit抢占优先级,0bit子优先级 2、在FreeRTOSConfig.h文件中修改configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY的值(我们设置为1) //configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY的值为系统可管理的最高中断优先级 //用于配置 basepri 寄存器 当 basepri 设置为某个值的时候,会让系统不响应比该优先级低的中断,而优先级比之更高的中断则不受影响 /* 比如当这个宏定义配置为 5 的时候,中断优先级数值在 0、 1、 2、 3、 4 的这些中断是不受 FreeRTOS 管理的,不可被屏蔽,也不能调用 FreeRTOS 中的 API 函数 接口,而中断优先级在 5 到 15 的这些中断是受到系统管理,可以被屏蔽的 */ 3、设置对应中断的抢占优先级和子优先级(抢占优先级的设置不能小于configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY的值,也就是中断的优先级不能比系统可管理的最高优先级高,如果该值比configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY的值小,这个中断是不受 FreeRTOS 管理的) bsp_nvic.c文件:
#include "./bsp/nvic/bsp_nvic.h"
void Set_NVIC_PriorityGroup(PriorityGroup_Type PriorityGroup)
{
NVIC_SetPriorityGrouping((uint32_t)PriorityGroup);
}
void set_IRQn_Priority(IRQn_Type IRQn,PreemptPriority_Type PreemptPriority, SubPriority_Type SubPriorit)
{
uint32_t PriorityGroup = 0;
uint32_t Priority_Encode = 0;
PriorityGroup = NVIC_GetPriorityGrouping();
Priority_Encode = NVIC_EncodePriority(PriorityGroup,(uint32_t)PreemptPriority,(uint32_t)SubPriorit);
NVIC_SetPriority(IRQn, Priority_Encode);
}
bsp_nvic.h文件:
#ifndef __NVIC_H
#define __NVIC_H
#include "fsl_common.h"
typedef enum PriorityGroup{
Group_0 = 0,
Group_1,
Group_2,
Group_3,
Group_4,
Group_5,
Group_6,
Group_7,
}PriorityGroup_Type;
typedef enum PreemptPriority {
Group0_PreemptPriority_0 = 0,
Group0_PreemptPriority_1,
Group0_PreemptPriority_2,
Group0_PreemptPriority_3,
Group0_PreemptPriority_4,
Group0_PreemptPriority_5,
Group0_PreemptPriority_6,
Group0_PreemptPriority_7,
Group0_PreemptPriority_8,
Group0_PreemptPriority_9,
Group0_PreemptPriority_10,
Group0_PreemptPriority_11,
Group0_PreemptPriority_12,
Group0_PreemptPriority_13,
Group0_PreemptPriority_14,
Group0_PreemptPriority_15,
Group1_PreemptPriority_0 = 0,
Group1_PreemptPriority_1,
Group1_PreemptPriority_2,
Group1_PreemptPriority_3,
Group1_PreemptPriority_4,
Group1_PreemptPriority_5,
Group1_PreemptPriority_6,
Group1_PreemptPriority_7,
Group1_PreemptPriority_8,
Group1_PreemptPriority_9,
Group1_PreemptPriority_10,
Group1_PreemptPriority_11,
Group1_PreemptPriority_12,
Group1_PreemptPriority_13,
Group1_PreemptPriority_14,
Group1_PreemptPriority_15,
Group2_PreemptPriority_0 = 0,
Group2_PreemptPriority_1,
Group2_PreemptPriority_2,
Group2_PreemptPriority_3,
Group2_PreemptPriority_4,
Group2_PreemptPriority_5,
Group2_PreemptPriority_6,
Group2_PreemptPriority_7,
Group2_PreemptPriority_8,
Group2_PreemptPriority_9,
Group2_PreemptPriority_10,
Group2_PreemptPriority_11,
Group2_PreemptPriority_12,
Group2_PreemptPriority_13,
Group2_PreemptPriority_14,
Group2_PreemptPriority_15,
Group3_PreemptPriority_0 = 0,
Group3_PreemptPriority_1,
Group3_PreemptPriority_2,
Group3_PreemptPriority_3,
Group3_PreemptPriority_4,
Group3_PreemptPriority_5,
Group3_PreemptPriority_6,
Group3_PreemptPriority_7,
Group3_PreemptPriority_8,
Group3_PreemptPriority_9,
Group3_PreemptPriority_10,
Group3_PreemptPriority_11,
Group3_PreemptPriority_12,
Group3_PreemptPriority_13,
Group3_PreemptPriority_14,
Group3_PreemptPriority_15,
Group4_PreemptPriority_0 = 0,
Group4_PreemptPriority_2,
Group4_PreemptPriority_3,
Group4_PreemptPriority_4,
Group4_PreemptPriority_5,
Group4_PreemptPriority_6,
Group4_PreemptPriority_7,
Group5_PreemptPriority_0 = 0,
Group5_PreemptPriority_1,
Group5_PreemptPriority_2,
Group5_PreemptPriority_3,
Group6_PreemptPriority_0 = 0,
Group6_PreemptPriority_1,
Group7_PreemptPriority_0 = 0
}PreemptPriority_Type;
typedef enum SubPriority {
Group0_SubPriority_0 = 0,
Group1_SubPriority_0 = 0,
Group2_SubPriority_0 = 0,
Group3_SubPriority_0 = 0,
Group4_SubPriority_0 = 0,
Group4_SubPriority_1,
Group5_SubPriority_0 = 0,
Group5_SubPriority_1,
Group5_SubPriority_2,
Group5_SubPriority_3,
Group6_SubPriority_0 = 0,
Group6_SubPriority_2,
Group6_SubPriority_3,
Group6_SubPriority_4,
Group6_SubPriority_5,
Group6_SubPriority_6,
Group6_SubPriority_7,
Group7_SubPriority_0 = 0,
Group7_SubPriority_1,
Group7_SubPriority_2,
Group7_SubPriority_3,
Group7_SubPriority_4,
Group7_SubPriority_5,
Group7_SubPriority_6,
Group7_SubPriority_7,
Group7_SubPriority_8,
Group7_SubPriority_9,
Group7_SubPriority_10,
Group7_SubPriority_11,
Group7_SubPriority_12,
Group7_SubPriority_13,
Group7_SubPriority_14,
Group7_SubPriority_15
}SubPriority_Type;
void Set_NVIC_PriorityGroup(PriorityGroup_Type PriorityGroup) ;
void set_IRQn_Priority(IRQn_Type IRQn,PreemptPriority_Type PreemptPriority, SubPriority_Type SubPriorit);
#endif
以下内容为RT1052中断优先级分组的设置依据 1、其实RT1052的中断优先级的配置方式和其他M系列的单片机配置方式基本一样,需要注意的是,RT1052只支持16位优先级,[7:4] 我们主要使用如下两个函数进行中断优先级分组和中断优先级设置(NVIC_SetPriorityGrouping;NVIC_SetPriority)
2、设置优先级分组函数(NVIC_SetPriorityGrouping) 从代码可以看出设置中断优先级分组是对寄存器AIRCR的8-10位进行配置的 AIRCR寄存器如下所示(详细请参考《armv7m_arm》参考手册第 B3.2.6 章节) 优先级分组的值设定如下:各个值代表的含义如下 0-- bit 1-7为抢占优先级,bit 0子优先级 1-- bit 2-7为抢占优先级,bit 0-1子优先级 … 6-- bit 7为抢占优先级,bit 0-6位子优先级 从上图中可以看出AIRCR[PRIGROUP]虽然可以设置为从0-7,但是我们在文件MIMXRT1052.h中指定了__NVIC_PRIO_BITS的值,也就是用4bit来设定中断优先级分组方法,在函数__NVIC_SetPriority中分析该设置优先级过程可以得到:优先级的设置只有高4bit可用,也就意味着AIRCR[PRIGROUP]的值如果设置为0/1/2/3起始都是代表设置4bit抢占优先级,0bit子优先级的
|