Page 1 of 1

ISR Epilogue/Prologue (Cortex M3)

Posted: Thu Apr 10, 2014 8:06 pm
by rjp
Do the epilogue (blank, so not really relevant) and prologue for an ISR need to be at the naked ISR level? I'm using a Cortex M3 that has some vendor provided and automatically generated code for the interrupt handlers that I am trying to avoid modifying, and I've put my epi/pro calls one call frame down from the naked ISR. I'm also seeing a very intermittent crash related to interrupts that I haven't been able to figure out, so I'm wondering if I've broken the rules.

The crash I'm seeing is two-fold: I get a Hard Fault (the actual fault varies), and it ultimately traces back to the context switch routine. This leads me to believe that a thread's context is getting totally hosed. The main stack pointer is invalid at the start of the fault. I've checked and no code modifies the MSP register other than the startup code, so there must be code running in an interrupt context that modifies the stack pointer.

I just want to make sure I'm not doing something that is known to be wrong.

Re: ISR Epilogue/Prologue (Cortex M3)

Posted: Thu Apr 10, 2014 8:35 pm
by Giovanni
Hi,

The macros must be placed as documented because there are assumptions about the stack structure, you may try to invoke the generated ISR code from the real ISR written using rules. The generated function should be a normal void void..(void) function.

Giovanni

Re: ISR Epilogue/Prologue (Cortex M3)

Posted: Thu Apr 10, 2014 8:45 pm
by rjp
Okay. I didn't see anything in the documentation about the state of the stack for the call. There is no intervening C-code after the epilogue, but there would be stack unwinding. For now, I'll just move the epilogue call to the generated code and see if that resolves the crash, and if it does, then I'll try to figure out the best way to properly integrate it. Thanks for the quick response as always.

Re: ISR Epilogue/Prologue (Cortex M3)

Posted: Thu Apr 10, 2014 8:56 pm
by Giovanni
The documentation just states how to write ISRs, you should not make assumptions about the inner working of those macros nor try to place them in different places.

RTOSes, in general, need to hook ISRs in their own way.

Giovanni

Re: ISR Epilogue/Prologue (Cortex M3)

Posted: Thu Apr 10, 2014 9:24 pm
by rjp
So far with the modified generated code it hasn't crashed. I'm going to let it run over the weekend to be sure. I'll probably just remove the dependence on the generated code and just use the headers with the relevant information if this works.

Thanks again.