AnsweredAssumed Answered

Mass erasing paged memory

Question asked by Robyn Yost on May 20, 2013
Latest reply on Jun 11, 2013 by Robyn Yost

Chip: MC9S12C128

 

I have a program that resides in both paged and unpaged memory.  The program loads fine through the IDE.  However, I am working on a CAN bootloader and being able to program the chip through a GUI using the P&E unit_12z libraries. Right now, I am having problems with erasing the second page of paged memory.

 

I do a mass erase command.  That erases the unpaged memory and the first page of paged memory.  That makes since as that is all that is in flash.  I have tried to set the PPAGE register to 0x39 before a mass erase to erase the second page of paged memory but it doesn't have any effect.  Is there something I am missing?  How do you mass erase the paged memory?

 

The code snipet is:

 

    // Mass erase flash
   write_data_byte(0x100, 0x49);// set FCLKDIV clock divider
   write_data_byte(0x103, 0);   // FCFNG select block 0
   write_data_byte(0x102, 0x10);// set the WRALL bit in FTSTMOD to affect all blocks
   write_data_byte(0x104, 0xFF);// FPROT all protection disabled
   write_data_byte(0x105, 0x30);// clear PVIOL and ACCERR in FSTAT register
   write_data_byte(0x106, 0x41);// write MASS ERASE command in FCMD register
   write_data_byte(0x105, 0x80);// clear CBEIF in FSTAT register to execute the command
   Sleep(2000);                   // wait for command to complete

 

   // Reprogram Security byte to Unsecure state
   write_data_byte(0x100, 0x49);// set FCLKDIV clock divider
   write_data_byte(0x103, 0);   // FCFNG select block 0
   write_data_byte(0x104, 0xFF);

// FPROT all protection disabled

   write_data_byte(0x105, 0x30);// clear PVIOL and ACCERR in FSTAT register
   write_data_word(0xFF0E, 0xFFFE); // write security byte to "Unsecured" state
   write_data_byte(0x106, 0x20);// write MEMORY PROGRAM command in FCMD register
   write_data_byte(0x105, 0x80);// clear CBEIF in FSTAT register to execute the command
   Sleep(2000);                   // wait for command to complete

 

    // Mass erase flash
   write_data_byte(0x100, 0x49);// set FCLKDIV clock divider
   write_data_byte(0x103, 0);   // FCFNG select block 0
   write_data_byte(0x102, 0x10);// set the WRALL bit in FTSTMOD to affect all blocks
   write_data_byte(0x104, 0xFF);// FPROT all protection disabled
   write_data_byte(0x105, 0x30);// clear PVIOL and ACCERR in FSTAT register
write_data_byte(0x30, 0x39);// Set the PPAGE register to the next page
   write_data_byte(0x106, 0x41);// write MASS ERASE command in FCMD register
   write_data_byte(0x105, 0x80);// clear CBEIF in FSTAT register to execute the command
   Sleep(2000);                   // wait for command to complete



   bReturn = set_speed();

 

 


Outcomes