LPC55xx how to detect, if Flash Region is readable?

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

LPC55xx how to detect, if Flash Region is readable?

959 Views
bressan
Contributor III

Hi,

we use flash for program memory and for storing resources, like pictures and settings.

With LPC2xxx and LPC17xx this was no problem, if flash region was ff ff ff... it was empty and we were able to write it.

Reading was always no problem.

Now advantage is, we've got smaller pages to erase.
My problem: If I wrote once in an area, I can read it. But if it's empty, I can only check, if the whole area is empty by flash_verify_erase().

Example:

erase area 0x30000 to 0x31000

flash_verify_erase(adr=0x30400, size=0x200), is ok, so we assume region is empty, we must not read.

Write data to 0x30200 to 0x30800

flash_verify_erase(adr=0x30400, size=0x200), fails, so we assume region is full with data

read data from 0x30500 to 0x30600 is ok,

but

flash_verify_erase(adr=0x30700, size=0x200), fails, so we assume region is full with data

read data from 0x30700 to 0x30900 ==> hard fault.

How can I check, if one region is save to read from? Do I have to write my own method, to check every single page?

Thanks for your help in advance

Bernhard

Edit: formatting

Labels (1)
0 Kudos
3 Replies

822 Views
bressan
Contributor III
0 Kudos

884 Views
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi Bernahrd, I hope you're doing well!

 

Currently, the mechanism implemented to determine if a flash section is empty is to use the FLASH_VerifyErase function.

This is to avoid the possibility of causing a Hardfault like the one you're experiencing.

 

Please let me know if you need any more information.

 

Take care, best regards,

Sebastian

0 Kudos

884 Views
bressan
Contributor III

Hi Sebastian,

thanks, for your try to help me. The FLASH_VerifyErase function is not enough, to determine, if it's safe to read from a region, as explained from the sample above.

I wrote something, which covers most use cases:

BOOL iap_checkReadable(const U32 destinationAddress, const U32 size){
  const U32 pagesize= 0x200;
  U32 start = destinationAddress;
  U32 end = start + size;
  U32 pos = 0;
  U8 Status =0;
  flash_config_t flashInstance;
  U32 PflashSize =0;
  BOOL retval = TRUE;
  
  start &= c_alignMask0x200; 
  end = (end +0x1ff) & c_alignMask0x200;   //aligned (bigger)
  
  //if empty, not readable ==> must be done with FLASH_VerifyErase()
  
  prepareFlashing();   //reduce cpu-speed and disable irq
  Status = FLASH_Init(&flashInstance);
  if(Status != kStatus_Success){
    resetLastState();
    return FALSE;
  }  
  FLASH_GetProperty(&flashInstance, kFLASH_PropertyPflashPageSize, &PflashSize);
  
  for(pos=0; pos <end; pos += pagesize){
    //destinationAddress and size must be word-aligned. size value counts bytes.
    Status = FLASH_VerifyErase(&flashInstance, start, end -start);
    if(0!=Status){
      retval = FALSE;
      break;
    }
  }
  resetLastState();  //reset cpu-speed and enable irq
  
  return retval;
}

I'm still searching for some easier and faster way, to prevent reading from unreadable areas.

And this code don't cover the case, if only a small part (i.e. 32 bytes) of a page is unreadable.

0 Kudos