AnsweredAssumed Answered

STM32F3 NVIC Interrupt (while loop problem)

Question asked by KajteK on Sep 6, 2015
Latest reply on Sep 7, 2015 by KajteK
Hi everyone.
Few days ago I realized that my NVIC priorities don't work. I'm tring to use three different interrupts by timer, exti and SysTick. I guess when EXTI or SysTick have highest priority then TIM with while loop inside, TIM shouldn't block whole program but it does (I guess).
void InitializeTimer(){
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
 
    TIM_TimeBaseInitTypeDef timerInitStructure;
                timerInitStructure.TIM_Prescaler = 40000;
                timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
                timerInitStructure.TIM_Period = 1000;
                timerInitStructure.TIM_RepetitionCounter = 0;
    TIM_TimeBaseInit(TIM2, &timerInitStructure);
    TIM_Cmd(TIM2, ENABLE);
    TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
}
void EnableTimerInterrupt(){
    NVIC_InitTypeDef nvicStructure;
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
                nvicStructure.NVIC_IRQChannel = TIM2_IRQn;
                nvicStructure.NVIC_IRQChannelPreemptionPriority = 2;
                nvicStructure.NVIC_IRQChannelSubPriority = 2;
                nvicStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&nvicStructure);
}
void EnableExternalInterrupt(){
 
    NVIC_InitTypeDef nvicStructure1;
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
                nvicStructure1.NVIC_IRQChannel = EXTI0_IRQn;
                nvicStructure1.NVIC_IRQChannelPreemptionPriority = 0;
                nvicStructure1.NVIC_IRQChannelSubPriority = 0;
                nvicStructure1.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&nvicStructure1);
 
    EXTI_InitTypeDef extiStructure;
    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
                extiStructure.EXTI_Line = EXTI_Line0;
                extiStructure.EXTI_Mode = EXTI_Mode_Interrupt;
                extiStructure.EXTI_Trigger = EXTI_Trigger_Falling;
                extiStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&extiStructure);
}
void EXTI0_IRQHandler(){
    if(EXTI_GetITStatus(EXTI_Line0) != RESET)
    {
        if(GPIO_ReadOutputDataBit(GPIOE, LED4)== 0) GPIO_SetBits(GPIOE,LED4);
                            else GPIO_ResetBits(GPIOE, LED4);
        EXTI_ClearITPendingBit(EXTI_Line0);
    }
}
void TIM2_IRQHandler(){
    if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
    {
        if(GPIO_ReadOutputDataBit(GPIOE, LED7)== 0) GPIO_SetBits(GPIOE,LED7);
                    else GPIO_ResetBits(GPIOE, LED7);
        TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
    }
    int i=0;
    while(1);
 
}
void SysTick_Handler(void){
    if(GPIO_ReadOutputDataBit(GPIOE, LED10)== 0) GPIO_SetBits(GPIOE,LED10);
            else GPIO_ResetBits(GPIOE, LED10);
}
void main(void){
 
    InitGPIOA();
    InitLED3();
    InitLED10();
    InitializeTimer();
    EnableTimerInterrupt();
    EnableExternalInterrupt();
 
    NVIC_SetPriority(TIM2_IRQn,2);
    NVIC_SetPriority(EXTI0_IRQn,1);
    NVIC_SetPriority(SysTick_IRQn,0);
 
    if (SysTick_Config(160000))  while (1);     //Maksymalnie 16 000 000, ze wzgledu na 24-bit timer
 
    while(1);
}
Thanks in advance for your help and have a nice day. 

Outcomes