SVC call in vPortStartFirstTask causes Hardfault

amiller2 wrote on Tuesday, September 25, 2018:

I’m running a FreeRTOS test application that I’ve written for a Cortex-M3 device.

I’m having an issue where, on starting the scheduler, the SVC instruction at the end of vPortStartFirstTask causes a Hardfault exception.

I have a breakpoint in vPortSVCHandler and I can see that this is never entered: the execution seems to jump straight to the hardfault handler on execution of the ‘svc 0’ instruction at the end of vPortStartFirstTask from portasm.s.

I’ve seen a few descriptions of similar issues, but haven’t yet been able to determine the cause of this. Any help much appreciated.

1 Like

rtel wrote on Tuesday, September 25, 2018:

Calling the SVC instruction with interrupt globally disabled can cause a hard fault (if I recall correctly) but assuming you are using a moderately recent version of FreeRTOS then you should find interrupts are globally enabled before SVC is called. Therefore I’m going to postulate that one of two things is happening, either vPortSVCHandler is not installed as the SVC handler and you don’t see the break point being hit because the code is actually running a different handler, or that an interrupt is executing between interrupts being enabled and the SVC instruction completing - so again something else is being executed that you are not aware of. Try debugging the hard fault handler to see what was actually executing when the fault occurs: