dsPIC33EP512MU814 resets when debugging code in auxiliary flash
I'm using a dsPIC33EP512MU814 chip. I'm developping a bootloader which will run in auxiliary flash memory. When I started testing it with ICD3 to step through my code, I first hit "pause" then check what I wanted to check and hit "play" again but for no obvious reason, the dsPIC reseted.
I created a test project to recreate the problem which arise every times by just halting and restarting the execution of the code. I've attached the main.c, linker script and project options (renamed *.txt) to this post.
It seems to be interrupt related because if I don't activate the TMR1 interrupt the dsPIC is not reseted. The IVT is placed at address 0x7FFFFA as supposed to. The ISR is called upon timer timeout. The weirdess thing is that if I put a breakpoint at T1Interrput() call in ISR below, the code halts every time when breakpoint is hit and when I restart execution I don't get a reset...
void __attribute__((__interrupt__, no_auto_psv)) _DefaultInterrupt(void)
T1Interrupt(); <--- Breakpoint here
default: /* Unknown interrupt */
Another weird thing is that if I put a breakpoint in the while loop below, the dsPIC halts when breakpoint is hit by when I restart execution, it resets.
// int16_t s16CurrentIpl;
INTCON1bits.NSTDIS = 1; /* Disable interrupt nesting */
RCONbits.SWDTEN = 0; /* Disable watchdog timer */
CORCONbits.VAR = 0; /* Fixed exception processing is enabled */
InitializeSystemClock(); /* Initialize system clock */
/* Disable all modules */
PMD1 = 0xFFFF;
PMD2 = 0xFFFF;
PMD3 = 0xFFFF;
PMD4 = 0xFFFF;
PMD6 = 0xFFFF;
PMD7 = 0xFFFF;
InitTmr1(); /* Start Timer 1 */
for(u16Count = 0U; u16Count < 100; u16Count++);
for(u16Count = 0U; u16Count < 1000; u16Count++); <--- Breakpoint here
/* Should never reach here!!! */
Has anyone ever seen something like this !? I need help to understand and fix this problem because is its a pain in the ... to debug like this.