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.
ISR Epilogue/Prologue (Cortex M3)
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: ISR Epilogue/Prologue (Cortex M3)
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
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)
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.
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: ISR Epilogue/Prologue (Cortex M3)
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
RTOSes, in general, need to hook ISRs in their own way.
Giovanni
Re: ISR Epilogue/Prologue (Cortex M3)
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.
Thanks again.