Unlocking mutex in RTC ISR and thread switching causes HardFault

Hello,

I trying to unlock mutex in RTC Alarm ISR and after alarm shoots and mutex is unlocked, the thread switch request is pending. RTC ISR in rtc.c file check that flag and calls thread_yield() to call a scheduler. After PendSV interrupt is triggered, HardFault occurs right after PendSV enabling command.

When the same operations done from for example, TIM interrupt which used by xtimer, context switching goes well.

FSR/FAR: CFSR: 0x00040000 HFSR: 0x40000000

My device is STM32L151.

Best regards,

Anon

Do you have some example code that you can share which triggers this fault?

Best regards, Joakim

Sure. Here it is: http://pastebin.com/ZGwtZKDd

Hi,

Any ideas on this?

The CFSR numbers indicate that the stacked PC was invalid upon return from ISR. Is the stack of the sleeping process being corrupted somehow?

http://infocenter.arm.com/help/topic/com.arm.doc.dui0553a/Cihcfefj.html#Cihgbdbi (go to UsageFault Status Register)

Do you have the possibility to run your device with a debugger attached? You should try to look at the differences in the contents of the thread stack between the two different methods (xtimer vs RTC). Also, check the values of the core registers before the hardfault, likely near the bx r0 in isr_svc, (did it run that far?)

Regards, Joakim