Page 1 of 4
getting Hard Fault when using fast interrupts
Posted: Fri Apr 17, 2015 6:14 pm
by Coreglider
Hello! I'm running a project on STM32F405, and when I enabled two high priority interrupts , I'm getting Hard Fault handler in ~2 minutes. Interrupts don't use any system API. The OS now doesn't handle any functions, it only use one dummy thread which sleeps by chThdSleepMilliseconds(5) in a cycle.
Code: Select all
TIM_ITConfig(TIM9, TIM_IT_Update, ENABLE);
NVIC_SetPriority(TIM1_BRK_TIM9_IRQn, 1);
TIM_ClearITPendingBit(TIM9, TIM_IT_Update);
NVIC_ClearPendingIRQ(TIM1_BRK_TIM9_IRQn);
NVIC_EnableIRQ(TIM1_BRK_TIM9_IRQn);
TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);
NVIC_SetPriority(TIM2_IRQn, 1);
TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
NVIC_ClearPendingIRQ(TIM2_IRQn);
NVIC_EnableIRQ(TIM2_IRQn);
Code: Select all
void TIM1_BRK_TIM9_IRQHandler(void)
{
TIM_Cmd(TIM2,ENABLE);
TIM_SelectMasterSlaveMode(TIM2, TIM_SlaveMode_Reset);
TIM_ClearITPendingBit(TIM9, TIM_IT_Update);
}
void TIM2_IRQHandler(void)
{
TIM_SelectMasterSlaveMode(TIM2, 0);
TIM_Cmd(TIM2,DISABLE);
TIM_Cmd(TIM1, DISABLE);
TIM_Cmd(TIM4, DISABLE);
TIM4->CNT=0;
TIM_Cmd(TIM1, ENABLE);
TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
}
Re: getting Hard Fault when using fast interrupts
Posted: Fri Apr 17, 2015 6:18 pm
by Giovanni
Hi,
Try enabling debug options in chconf.h (checks, assertions, state checker) and see if something OS-related is caught.
Giovanni
Re: getting Hard Fault when using fast interrupts
Posted: Fri Apr 17, 2015 7:02 pm
by Coreglider
if something OS-related is caught.
Nothing was caught

Here's project. I'm using a modified vectors.s with standard CMSIS vectors names, and I've renamed vectors in chcore_v7m.c to match it. Can be a problem with it?
Re: getting Hard Fault when using fast interrupts
Posted: Fri Apr 17, 2015 7:14 pm
by Giovanni
Are you using the startup files provided with ChibiOS? linker files?
I will give a look to your projects tomorrow.
Giovanni
Re: getting Hard Fault when using fast interrupts
Posted: Fri Apr 17, 2015 7:24 pm
by Coreglider
The cstartup.s I'm using is provided by ChibiOS. And there are no any linker scripts in the project.
Re: getting Hard Fault when using fast interrupts
Posted: Sat Apr 18, 2015 10:16 am
by Giovanni
I don't see nothing obviously wrong but I can't run the code on my HW.
Please verify that the systick interrupt and all interrupts calling OS functions have priority between 2 and 15. Levels 0 and 1 are reserved for "fast" interrupts, calling the OS from there is an error.
You can also test the OS alone initially just with a blinking LED from that thread then try adding more things, this could give an hint about the problem.
Could you also try to understand where the exception actually happens?
Giovanni
Re: getting Hard Fault when using fast interrupts
Posted: Sat Apr 18, 2015 10:33 am
by Coreglider
I've tested the OS alone without these interrupts enabled and it seems to be fine. And when I comment all OS-related initializations, interrupts work without crash. Sytem handler priorities are set in chSysInit() and I never changed them. I've checked priority bits gpouping, and it seems to be the same in ChibiOS and NVIC functions. I'll try to find the exact moment related to the interrupts triggering, but I think it occurs when timer interrupt is fired at the moment of context change.
Re: getting Hard Fault when using fast interrupts
Posted: Sat Apr 18, 2015 10:37 am
by Giovanni
And that is strange, context switch is always performed in a critical zone in ChibiOS, an interrupt cannot occur there unless it is at priority above 2.
Giovanni
Re: getting Hard Fault when using fast interrupts
Posted: Sat Apr 18, 2015 10:50 am
by Coreglider
but fast interrupts with priority 1 can interfere the context switch process?
PS: I'm using a SystemInit() from CMSIS to setup the system. Can be any conflicts with ChibiOS?
Re: getting Hard Fault when using fast interrupts
Posted: Sat Apr 18, 2015 2:00 pm
by Giovanni
Priority 1 can preempt the kernel, this means that you cannot use the kernel from ISRs but anything else is allowed.
SystemInit() does nothing strange apparently.
Giovanni