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
This is closest answer to my question:
https://community.nxp.com/t5/LPC-Microcontrollers-Knowledge/LPC55xx-How-to-fix-AHB-Read-HardFault-Er...
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
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.