[LPC55xx] Why FLASH Program cannot Success?

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

[LPC55xx] Why FLASH Program cannot Success?

[LPC55xx] Why FLASH Program cannot Success?

MCUXpresso SDK for LPC55xx uses FLASH API to implement FLASH drivers. Some user may meet issue when executes FLASH program code, for instance:

status = FLASH_Program(&flashInstance, destAdrss, (uint8_t *)s_bufferFF, 8);


After execution this code, nothing changed in the destination address, but error code 101 returns:

pastedImage_1.png

This error code looks new, as it doesn’t commonly exist in other older LPCs. If we check FLASH driver status code from UM, code 101 means FLASH_Alignment Error:

pastedImage_2.png

Alignment error Ah ha? ! Go back to the definition of FLASH_Program,

status_t FLASH_Program(flash_config_t *config, uint32_t start, uint32_t *src, uint32_t lengthInBytes);

New user often overlooks the UM description of this API “the required start and the lengthInBytes must be page size aligned”. That’s to say, to execute FLASH_Program function, both start address and the length must be 512 bytes-aligned. So if we modify

status = FLASH_Program(&flashInstance, destAdrss, (uint8_t *)s_bufferFF, 8);

To

status = FLASH_Program(&flashInstance, destAdrss, (uint8_t *)s_bufferFF, 512);

FLASH_Program can be successful.

 

!!NOTE: In old version of SDK2.6.x, the description of FLASH_Program says the start address and length are word-aligned which is not correct. The new SDK2.7.0 has fixed the typo. 

Keep in mind: Even you want to program 1 word, the lengInBytes is still 512 aligned, as same as destAdrss!

PS.

I always recommend my customer to check FLASH driver status code when meet problem with FLASH API. We can find it in UM11126, Chapter 9, FLASH API.

I extract here for your quickly browse:

pastedImage_3.png

 

Happy Programming

Labels (1)
Attachments
100% helpful (1/1)
Version history
Last update:
‎01-20-2020 02:00 AM
Updated by: