[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
%3CLINGO-SUB%20id%3D%22lingo-sub-1106670%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%5BLPC55xx%5D%20Why%20FLASH%20Program%20cannot%20Success%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1106670%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3EMCUXpresso%20SDK%20for%20LPC55xx%20uses%20FLASH%20API%20to%20implement%20FLASH%20drivers.%20Some%20user%20may%20meet%20issue%20when%20executes%20FLASH%20program%20code%2C%20for%20instance%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3E%3CEM%3Estatus%20%3D%20FLASH_Program(%26amp%3BflashInstance%2C%20destAdrss%2C%20(uint8_t%20*)s_bufferFF%2C%208)%3B%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%20%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3EAfter%20execution%20this%20code%2C%20nothing%20changed%20in%20the%20destination%20address%2C%20but%20error%20code%20%3CSTRONG%3E101%3C%2FSTRONG%3E%20returns%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22pastedImage_1.png%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22pastedImage_1.png%22%20style%3D%22width%3A%20496px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F97129i5F9E31F36FD18C15%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22pastedImage_1.png%22%20alt%3D%22pastedImage_1.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3EThis%20error%20code%20looks%20new%2C%20as%20it%20doesn%E2%80%99t%20commonly%20exist%20in%20other%20older%20LPCs.%20If%20we%20check%20FLASH%20driver%20status%20code%20from%20UM%2C%20code%20101%20means%20FLASH_Alignment%20Error%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22pastedImage_2.png%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22pastedImage_2.png%22%20style%3D%22width%3A%20554px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F97174iD6DEFB488D0FC278%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22pastedImage_2.png%22%20alt%3D%22pastedImage_2.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3EAlignment%20error%20Ah%20ha%3F%20!%20Go%20back%20to%20the%20definition%20of%20FLASH_Program%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3E%3CEM%3Estatus_t%20FLASH_Program(flash_config_t%20*config%2C%20uint32_t%20start%2C%20uint32_t%20*src%2C%20uint32_t%20lengthInBytes)%3B%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3ENew%20user%20often%20overlooks%20the%20UM%20description%20of%20this%20API%20%E2%80%9Cthe%20required%20%3CEM%3Estart%3C%2FEM%3E%20and%20the%20%3CEM%3ElengthInBytes%3C%2FEM%3E%20must%20be%20page%20size%20aligned%E2%80%9D.%20That%E2%80%99s%20to%20say%2C%20to%20execute%20FLASH_Program%20function%2C%20both%20start%20address%20and%20the%20length%20must%20be%20512%20bytes-aligned.%20So%20if%20we%20modify%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3E%3CEM%3Estatus%20%3D%20FLASH_Program(%26amp%3BflashInstance%2C%20destAdrss%2C%20(uint8_t%20*)s_bufferFF%2C%20%3CSTRONG%20style%3D%22color%3A%20red%3B%20%22%3E8%3C%2FSTRONG%3E)%3B%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3ETo%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3E%3CEM%3Estatus%20%3D%20FLASH_Program(%26amp%3BflashInstance%2C%20destAdrss%2C%20(uint8_t%20*)s_bufferFF%2C%20%3CSTRONG%20style%3D%22color%3A%20red%3B%20%22%3E512%3C%2FSTRONG%3E)%3B%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3EFLASH_Program%20can%20be%20successful.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3E%3CSTRONG%3E%EF%BC%81%EF%BC%81NOTE%3C%2FSTRONG%3E%3A%20In%20old%20version%20of%20SDK2.6.x%2C%20the%20description%20of%20FLASH_Program%20says%20the%20start%20address%20and%20length%20are%20word-aligned%20which%20is%20not%20correct.%20The%20new%20SDK2.7.0%20has%20fixed%20the%20typo.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3E%3CSTRONG%3EKeep%20in%20mind%3A%3C%2FSTRONG%3E%20Even%20you%20want%20to%20program%201%20word%2C%20the%20lengInBytes%20is%20still%20512%20aligned%2C%20as%20same%20as%20destAdrss!%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3EPS.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3EI%20always%20recommend%20my%20customer%20to%20check%20FLASH%20driver%20status%20code%20when%20meet%20problem%20with%20FLASH%20API.%20We%20can%20find%20it%20in%20UM11126%2C%20Chapter%209%2C%20FLASH%20API.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3EI%20extract%20here%20for%20your%20quickly%20browse%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22pastedImage_3.png%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22pastedImage_3.png%22%20style%3D%22width%3A%20543px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F97220i88BED0265319B6B6%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22pastedImage_3.png%22%20alt%3D%22pastedImage_3.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2015px%3B%22%3EHappy%20Programming%20%3CIMG%20class%3D%22jive_emoji%22%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Fimages%2Femojis%2F1f60a.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CP%3E%3C%2FP%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1106670%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3ELPC55xx%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
100% helpful (1/1)
Version history
Last update:
‎01-20-2020 02:00 AM
Updated by: