[LPC55xx] How to fix AHB Read HardFault Error

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

[LPC55xx] How to fix AHB Read HardFault Error

No ratings

[LPC55xx] How to fix AHB Read HardFault Error

Recently I have several customers experience HardFault error when perform AHB FLASH memory read on LPC55S69. If a FLASH sector has never been programed after mass erase, performing AHB reads of the FLASH memory contents will cause a hardware fault if an unrecoverable error is detected.

Why?

LPC55Sxx parts are delivered from the factory mass erased with ECC unset. When MCUXpresso IDE connects a chip via LinkServer, it will firstly erase the sectors that will be used for the image being programed, then program the code with a correct ECC set. The sectors beyond the end of the image will be left unchanged, which keep in “erased” states without ECC set on them.

 

When LPC55Sxx executes FLASH read code ( for example, mytemp = *(uint32_t*)0x4000 ) through AHB bus, it checks FLASH ECC while AHB read. No issue to read programed sectors because ECC has already set. But, read unprogrammed sectors with invalid ECC values leads to fail to read and go to HardFault_Handler as below:

pastedImage_1.png

If performing AHB reads of the flash memory contents AFTER a sector erase, we will have the same HardFault issue.

Solutions

There are two solutions to fix the error.

1. Read FLASH Content after Programing the FLASH Sector

Unlike mass erasing, programing FLASH updates the related ECC value. Thus with a successful ECC check, read AHB can be realizable by below code.

volatile uint32_t mytemp;
……
mytemp = *(uint32_t*)0x1000;//read memory content 0x1000 to mytemp‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

NOTE: 0x1000 MUST be a “programed” address. If the unused FLASH sector is in “erased” state, in order to read it, we need manually program it before AHB read. FLASH programming demo code can be referred in flashiap demo under MCUXpresso SDK package. See function FLASH_Program.

2. Read FLASH Content Using FLASH Controller Command

Read operations using FLASH controller commands (See UM11126 Section “Command listing (CMD)”) will not cause hard fault. This is the UM recommended method of read FLASH content.

Note: Flash operations (erase, blank check, program) and reading a single word can only be performed for CPU frequencies of up to 100 MHz. These operations cannot be performed for frequencies above 100 MHz.

So far I haven’t found a FLASH read demo code. Please follow below steps to create your demos.

Environment:

IDE: MCUXpresso IDE v11.1.0

SDK MCUXpresso SDK v2.7.0

Steps:

See attached document.

Thanks for the suggestion from Alex Yang and andybeeson

Labels (1)
Attachments
Comments

Hi !

Does reading of flash memory via controller have clock 100 Mhz limitation aslo ? What about prefetch bit enable/disable ?

Or 100 Mhz rule is applicabli for Write and Erase operations only ?

Yes, see UM11126:

pastedImage_2.png

Hi !

What about global interrupt disabling while program/erase operations ?

In what SRAM buffer/memory area executed wait loop until end of completion of program/erase operation.

Code can't be executed from nonbanked flash when it under erase and it is not clear what kind of preconditions need to be done.

Regards,

Eugene

Version history
Last update:
‎09-10-2020 03:30 AM
Updated by: