getting Hard Fault when using fast interrupts

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Coreglider
Posts: 17
Joined: Fri Apr 17, 2015 5:38 pm

getting Hard Fault when using fast interrupts

Post 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);
}
Attachments
h.zip
(129.35 KiB) Downloaded 253 times
Last edited by Coreglider on Fri Apr 17, 2015 7:29 pm, edited 1 time in total.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: getting Hard Fault when using fast interrupts

Post by Giovanni »

Hi,

Try enabling debug options in chconf.h (checks, assertions, state checker) and see if something OS-related is caught.

Giovanni
Coreglider
Posts: 17
Joined: Fri Apr 17, 2015 5:38 pm

Re: getting Hard Fault when using fast interrupts

Post 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?
Attachments
stmproject.zip
(484.04 KiB) Downloaded 263 times
Last edited by Coreglider on Fri Apr 17, 2015 8:17 pm, edited 1 time in total.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: getting Hard Fault when using fast interrupts

Post by Giovanni »

Are you using the startup files provided with ChibiOS? linker files?

I will give a look to your projects tomorrow.

Giovanni
Coreglider
Posts: 17
Joined: Fri Apr 17, 2015 5:38 pm

Re: getting Hard Fault when using fast interrupts

Post by Coreglider »

The cstartup.s I'm using is provided by ChibiOS. And there are no any linker scripts in the project.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: getting Hard Fault when using fast interrupts

Post 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
Coreglider
Posts: 17
Joined: Fri Apr 17, 2015 5:38 pm

Re: getting Hard Fault when using fast interrupts

Post 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.
Last edited by Coreglider on Sat Apr 18, 2015 10:47 am, edited 1 time in total.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: getting Hard Fault when using fast interrupts

Post 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
Coreglider
Posts: 17
Joined: Fri Apr 17, 2015 5:38 pm

Re: getting Hard Fault when using fast interrupts

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: getting Hard Fault when using fast interrupts

Post 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
Post Reply