After developing some code in CCS and running it in RAM I was interested in running it from flash.
I managed to compile, link and load the program easily enough, but I started getting wierd behaviour after calling the following routine:
#pragma CODE_SECTION(InitFlash, "ramfuncs")
void InitFlash(void) {
EALLOW;
/* Flash set to activate mode */
FlashRegs.FPWR.bit.PWR = 3;
/* Clear the 3VSTAT bit */
FlashRegs.FSTATUS.bit.V3STAT = 1;
/* ONLY THE DEFAULT VALUE FOR THESE 2 REGISTERS SHOULD BE USED */
FlashRegs.FSTDBYWAIT.bit.STDBYWAIT = 0x01FF;
FlashRegs.FACTIVEWAIT.bit.ACTIVEWAIT = 0x01FF;
/* Set the Random Waitstate for the Flash */
FlashRegs.FBANKWAIT.bit.RANDWAIT = 5;
/* Set the Paged Waitstate for the Flash */
FlashRegs.FBANKWAIT.bit.PAGEWAIT = 5;
/* Set the Waitstate for the OTP */
FlashRegs.FOTPWAIT.bit.OTPWAIT = 8;
/* Enable Flash Pipeline mode to improve performance */
FlashRegs.FOPT.bit.ENPIPE = 1;
EDIS;
/* Force a pipeline flush */
asm(" RPT #6 || NOP");
}
After (or during) execution of that function, the PC seemed to jump around into ISRs that were also loaded into RAM, and after a while the PC ended up at an ESTOP0 instruction.
After a few attempts to debug the problem (recompiling and reloading etc.) I find that I'm now being prompted for a CSM password when reading/writing flash, and now I can't even load programs into RAM.
Is there anyway to reset the CSM password?
Surely there's no security comprimise if the flash is erased at the same time as resetting the password?
Is there a way to salvage the chip or should I just bin it now?
Any help is appreciated.