本人菜鸟一个,刚接触ucos移植到stm32. 在做外部触发中断时遇到了问题,请大侠指点迷津。。。。。
目的:程序建立了一个任务App_Task_Key按键控制LED灯的闪烁,开启了EXTI_Line13的中断,当按下按钮的时候,会触发中断,进而关灭LED灯。
问题:现有三个任务在程序中,前两个也是LED的任务,两个LED能够顺利轮训闪烁运行,但是增加第三个中断控制任务时, 当我按下按键触发中断,就是一直死在那里中断里出不来。另两个任务也无法运行了。
void App_TaskCreate(void)
{
#if OS_TASK_NAME_SIZE > 7
INT8U err;
#endif
OSTaskCreate((void (*)(void *)) App_TaskToggleLED,
(void * ) 0,
(OS_STK * )&App_TaskToggleLEDStk[APP_CFG_TASK_ToggleLED_STK_SIZE - 1],
(INT8U ) APP_CFG_TASK_ToggleLED_PRIO
);
OSTaskCreate((void (*)(void *)) App_LED2task,
(void *) 0,
(OS_STK *)&App_TaskToggleLED2Stk[APP_CFG_TASK_ToggleLED2_STK_SIZE - 1],
(INT8U ) APP_CFG_TASK_ToggleLED2_PRIO
);
OSTaskCreate((void (*)(void *)) App_Task_Key,
(void *) 0,
(OS_STK *)&App_TaskToggleKeyStk[APP_CFG_TASK_ToggleKey_STK_SIZE - 1],
(INT8U ) APP_CFG_TASK_ToggleKey_PRIO
);
#endif
#if OS_TASK_NAME_SIZE > 14
OSTaskNameSet(APP_CFG_TASK_ToggleLED_PRIO, (INT8U *)"uC/OS-II LED", &err);
OSTaskNameSet(APP_CFG_TASK_ToggleLED2_PRIO, (INT8U *)"uC/OS-II LED", &err);
OSTaskNameSet(APP_CFG_TASK_ToggleKey_PRIO, (INT8U *)"uC/OS-II LED", &err);
#endif
}
static void App_Task_Key(void* p_arg)
{
(void) p_arg ;
INT8U err;
Sem_Task_Key=OSSemCreate(0);
while(1)
{
OSSemPend(Sem_Task_Key,0,&err);// 等待信号量
GPIO_SetBits(GPIOB, GPIO_Pin_13);
OSTimeDlyHMSM(0,0,1,0);
}
}
void EXTI13_IRQHandler(void)
{
OSIntEnter();
OSSemPost(Sem_Task_Key);
EXTI_ClearITPendingBit(EXTI_Line13);
OSIntExit();
}
void BSP_NVICConfiguration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //抢占式优先级别设置为无抢占优先级
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn ; //指定中断源
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //指定响应优先级别1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道3
NVIC_Init(&NVIC_InitStructure);
}
static void BSP_ExtIntrInit(void)
{
GPIO_InitTypeDef gpio_init;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
gpio_init.GPIO_Pin = GPIO_Pin_13;
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &gpio_init);
/* Enable AFIO Clock*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
/* Connect EXTI13 Line to PC.13 pin */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13); //将PA3连接到外部中断通道3
/* Configure EXTI13 Line */
EXTI_InitStructure.EXTI_Line = EXTI_Line13;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}