A colleague has written a CAN-based bootloader for a family of devices that utilizes the MC9S12DG256 MCU, Mask 0L01Y. I've modified the bootloader for the device that I'm working on, and after using it to load the application code, the application's EEPROM erase/write routines no longer work properly.
The rest of the application appears to execute correctly. It is performing all of its CAN-based communication, and the PC software can connect to and recognize the device.
However, when I try to change any configurable parameters, the EEPROM erase/write does not take. Upon power-cycling, all the parameters revert back to their default states.
The EEPROM initialization routine I'm using is below:
INITEE |= 0x01;
ECLKDIV = ECLK_DIVISOR; // ECLK_DIVISOR = 74
ECNFG = 0x00;
EPROT = 0x88; // EPOPEN (bit 7) = 1; EPDIS (bit 3) = 1
As can be seen above, I've seen the EPROT register to 0x88 so that the entire EEPROM array is unprotected (EPOPEN = 1) and protection is disabled (EPDIS = 1).
I put a diagnostic routine into the code that transmits the value of the EPROT register, and what I've found is that when the application is running in standalone mode, EPROT is set to the expected value of 0x88.
However, when the application is running after being loaded via the bootloader, the value of EPROT is unstable - it is sometimes 0x48, sometimes 0x18, etc. In each case, the EPOPEN bit is set to 0, which means that the entire EEPROM array is protected, and hence, not writable.
I can't run the code through the BDM and set breakpoints because it's already executing the CAN Loader, so debugging has been extremely challenging, to say the least.
Can anyone think of any reasons why the state of the EPROT register would randomly change to protected mode only when loading the application with the CAN Loader?
Any thoughts or suggestions would be much appreciated. Thanks in advance.