ISR Epilogue/Prologue (Cortex M3)

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
rjp
Posts: 9
Joined: Wed Jul 17, 2013 12:18 am

ISR Epilogue/Prologue (Cortex M3)

Post 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.
User avatar
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)

Post 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
rjp
Posts: 9
Joined: Wed Jul 17, 2013 12:18 am

Re: ISR Epilogue/Prologue (Cortex M3)

Post 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.
User avatar
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)

Post 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
rjp
Posts: 9
Joined: Wed Jul 17, 2013 12:18 am

Re: ISR Epilogue/Prologue (Cortex M3)

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