If I were in your shoes I would implement following steps:
1) Excluding parts of the code in a logical order and testing remaining code to localize error
2) Implement interrupt catcher. It means, there is subroutine for each interrupt created and all unused interrupt routines are directed to one function which can visualize the interrupt which was launched.
volatile unsigned int number_of_ISR = 0;
//==============================================================================
void Unimplemented_ISR(void)
{ asm nop; //insert breakpoint here. If you are here, check the "number_of_ISR"
//asm BGND // you can use this code to enter the background debug mode
}
//==============================================================================
#pragma CODE_SEG NON_BANKED
interrupt 1 void ISR_1 (void) {number_of_ISR = 1; Unimplemented_ISR();}
interrupt 2 void ISR_2 (void) {number_of_ISR = 2; Unimplemented_ISR();}
interrupt 3 void ISR_3 (void) {number_of_ISR = 3; Unimplemented_ISR();}
…
// intentionally commented because it is used in application
//interrupt 20 void ISR_20 (void) {number_of_ISR = 20; Unimplemented_ISR();}
…
#pragma CODE_SEG DEFAULT
//==============================================================================
#pragma CODE_SEG NON_BANKED
interrupt 20 void SCI0_Isr(void)
{
…
}
#pragma CODE_SEG DEFAULT
//==============================================================================
3) Test/Check all interrupts to be sure interrupt flags are correctly cleared. Interrupt routine, which is currently executed, is not interruptible (except I-bit is cleared)
4) Check all register which are writable anytime in the SPECIAL mode, but which are write once in the NORMAL mode.
5) Fill the stack area with some pattern to be able to check whether you do not underflow it. You must do it on some condition externally launched to avoid the pattern is written after each reset. Of course, if the code clears entire stack after reset in some init function you should avoid it to be able to check content of the stack after accidental reset.
However, if you want only to check where SP points you can use FILL command in the prm file which fills the stack with some pattern and you can visualize the SP or content of the stack or check the stack and visualize the value.
(note; reading SP leads to asm code)
Best regards,
Ladislav