我想用stm32在ucos-II系统下实现外部中断,ucos-ii移植没问题。但是无法初始化nvic,只要加入NVIC初始化结体的代码系统就无法工作,注释掉后系统又能正常工作了。 main.c #include "ucos_ii.h" #include "stm32f10x.h" #include "led.h" static OS_STK startup_task_stk[STARTUP_TASK_STK_SIZE]; static OS_STK task1_stk[TASK1_STK_SIZE]; static void systick_init(void) { RCC_ClocksTypeDef rcc_clocks; RCC_GetClocksFreq(&rcc_clocks); SysTick_Config(rcc_clocks.HCLK_Frequency / OS_TICKS_PER_SEC); } static void task1(void *p_arg) { NVIC_init(); for (;;) { GPIO_SetBits(GPIOE, GPIO_Pin_5); OSTimeDly(500); GPIO_ResetBits(GPIOE, GPIO_Pin_5); OSTimeDly(500); } } static void startup_task(void *p_arg) { INT8U err; systick_init(); /* Initialize the SysTick. */ #if (OS_TASK_STAT_EN > 0) OSStatInit(); /* Determine CPU capacity. */ #endif /* TODO: create application tasks here */ err = OSTaskCreate(task1, (void *)0, &task1_stk[TASK1_STK_SIZE-1], TASK1_PRIO); if (OS_ERR_NONE != err) while(1); OSTaskDel(OS_PRIO_SELF); } int main(void) { PPP_init(); OSInit(); OSTaskCreate(startup_task, (void *)0, &startup_task_stk[STARTUP_TASK_STK_SIZE - 1], STARTUP_TASK_PRIO); OSStart(); return 0; } 其中GPIO_init()用于初始化GPIO和端口时钟,NVIC_init()用于初始化NVIC和EXTI。 GPIO_init() void PPP_init(void) { SystemInit(); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOC, &GPIO_InitStructure); } NVIC_init() void NVIC_init(void) { NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3); NVIC_InitStructure.NVIC_IRQChannel=EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure); EXTI_ClearITPendingBit(EXTI_Line0); EXTI_InitStructure.EXTI_Line=EXTI_Line0; EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_Init(&EXTI_InitStructure); EXTI_GenerateSWInterrupt(EXTI_Line0); } 如果注释掉 NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure); 两行代码中的任意一行 系统可以正常运行,也就是task1中的灯可以闪烁,如果没有注释掉,体统不能工作 灯不闪 有哪位大虾可以为小弟提供正确的代码例程,我将感激不尽,终身难忘!~ QQ 417748195 邮箱:mkkj@live.cn |
RE:stm32在ucos-II下外部中断无法实现