flash erase verify

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

flash erase verify

2,353 Views
jmfs
Contributor I

Hello,

 

I'm trying to use the flash command erase verify, but it doesn't seem to work (always returns 0). I'm following the flowchart in the datasheet. The device is mc9s08qe128, and I'm using codewarrior 10.1. Here is my code:

 

byte flashEraseVerify(const byte * flash_block){ if(FCDIV_FDIVLD) {  while(!FSTAT_FCBEF)   ;  if(FSTAT_FACCERR | FSTAT_FPVIOL)   FSTAT = FSTAT & 0x30;  *((byte*)flash_block) = 0xA; // dummy write  FCMD = 0x05; // erase verify command  FSTAT_FCBEF = 1;  while(!FSTAT_FCCF)   ;  return FSTAT_FBLANK; } return 0;}

 Using debug I've checked that FDIVLD is set and that the page isn't erased. I'm not sure if I can write the flash block address like this 

*((byte*)flash_destination) = 0xA; // dummy write

 I'm assuming that this function doesn't need to be executed from ram because it only needs to read from flash.

 

Thanks

Labels (1)
Tags (1)
0 Kudos
Reply
4 Replies

1,516 Views
bigmac
Specialist III

Hello, and welcome to the forum.

 

From the reference manual for the device, Table 4.23, for the erase verify command -

 

Verify all memory bytes in the flash array memory are erased.

If the flash array memory is erased, the FBLANK flag in the FSTAT register will set upon

command completion.

 

Therefore, the erase verify command tests whether the whole flash array has been erased, i.e. a mass erase has succeeded.  Running the code from flash cannot work as intended, since a mass erase would erase the code that executes the command.

 

In the event that no mass erase has occurred, the situation that you currently seem to have, I would expect that the returned result would be zero.

 

You may assume that a sector erase process has succeeded if the FSTAT_FACCERR and FSTAT_FPVIOL error flags are clear upon exit from the sector erase function.

 

I have attached some sample code for a different 9S08 device, that is capable of erasing a single flash sector, and provides byte by byte flash programming.  But you should be able to adapt.  It uses a fixed block of RAM for the code that requires to be RAM resident.

 

Regards,

Mac

 

0 Kudos
Reply

1,516 Views
jmfs
Contributor I

Thanks for the help all. My problem was that I didn't got the part that It verifies all the array. I was trying to use it to verify 512 bytes blocks. while running I'll try to use flags to control the state  of each used block and check the values of all the addresses only after a reset.

 

Thanks again

0 Kudos
Reply

1,516 Views
kef
Specialist I

I think that Erase Verify blankchecks all flash memory (not just block) and that it is not useful for application running on this chip. It is useful for BDM programmers. I think it is needed to disengage chip security after mass erase via BDM port.

Just search for non-0xFF byte to determine if it is blank or not.

0 Kudos
Reply

1,516 Views
AirDragon
Contributor III

Just a quick thought, would doing this work?

 

if(FCDIV_FDIVLD){  /*...*/  return FSTAT_FBLANK;}else  return 0;

 

0 Kudos
Reply