Tom Bray

Re-flashing last sector 0xFE00 in MC9S12DG128

Discussion created by Tom Bray on Feb 14, 2007
Latest reply on Feb 23, 2007 by Tom Bray
I used AN2720 to create a boot loader for flashing my application. Since the boot loader doesn't use interrupts I need to reprogram the ISR Vector table to addresses in the application. My boot loader is in the 0x4000 (3E) block and my application in the 0xC000 (3F) block. My unimplemented ISR is at FF7E for both the boot loader and application. I have placed Application checksums in the 6 bytes below this. I am running CodeWarrior 5.7 with P&E Micro USB Multilink Interface for debugging.

Everything works fine until I try to erase the last sector. First it doesn't erase the sector, then it will only write from 0xFE00 through 0xFEFD. At this point I seem to still be able to see all of the flash. However when I exit and try to return to a new debug session, the security bits have been set and I have to run an unsecure program to regain access. If I only erase the last sector it still affects the security bits, even though in both cases I still see address 0xFF0F = 0xFE when finished.

I've tried just over-writing a word in the vector table, but I get an Access Error. I also tried blocking a write to addresses 0xFF00 through 0xFF1F to ensure that they didn't accidently get programmed, no difference.

To create the simplest flash programmer possible I created a project with a wrapper main.c around the app note files. See attached

Eventually I would like to be able to re-program the boot loader too. I created a version of flash.c & Do_On_Stack.asm that runs completely in RAM. The idea is to download via RS-232 the complete boot loader, verify a checksum, then go to RAM to reprogram it. Since interrupts are disabled I thought that I should be able to reprogram the last sector first then the boot loader. With this version I can program my application just fine, but still can't re-program the last sector, FE00.

BTW: I added FCNFG=0; and PPAGE=0x3F; before trying to erase or reprogram the last sector.

What am I doing wrong?