Hi,
I'm having trouble with entering the bootloader mode from main program.
There's bootloader code somewhere at known offset in flash.
The main program upon request does overwrites own interrupt vectors with
bootloader ones:
dint();
// flash timing clock = SMCLK (6Mhz) / 15
FCTL2 = FWKEY + FSSEL1 + FN0 + FN1 + FN2 + FN3;
pFlash = (uint8_t *)MAIN_VECTOR_START; // Initialize Flash pointer
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*pFlash = 0; // Dummy write to erase Flash segment
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for (i=0; i<VECTOR_SIZE; i++)
*pFlash++ = *pData++; // Write data to flash
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Reset LOCK bit
WDCTL = 666;
This works fine, MCU resets and runs the bootloader. But then weird stuff
starts happening, like TimerB0 interrupt out of nowhere, and eventually
everything goes bananas. External hardware reset, however, does help (via
JTAG emulator, button or an external hardware watchdog chip), and bootloader
starts working just fine. But isn't WD or flash violation supposed to cause
POR/PUC, which should be sufficient?
It seems that I am missing something obvious, but what? Of course, checked
interrupt and reset vectors, they are correct.
Thanks,
/Andrei