How to read and write a structure in the flash ROM of KE15Z?

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

How to read and write a structure in the flash ROM of KE15Z?

947 Views
whiteliondd6
Contributor I

I am using KE15Z as my board and trying to read and write the structure in the flash ROM of the MCU using FLASH APIs. I have tried this for integer array and it is working fine but, in the case of structure I'm facing a problem in writing API. Exactly how to give pointer source buffer to the API?

0 Kudos
Reply
3 Replies

939 Views
bobpaddock
Senior Contributor III

Not really enough information there.

What API?

Do you have some code you can show?

In general you can not write a structure, or anything else, to flash (in the context I think you mean).

 

0 Kudos
Reply

931 Views
whiteliondd6
Contributor I

I am using 'FLASH_Program (flash_config_t config, uint32_t start, uint8_t src, uint32_t lengthInBytes)' this API.

0 Kudos
Reply

925 Views
bobpaddock
Senior Contributor III

That is a declaration for a function.

Where is this code coming from?
MCUXpresso driver or something else?

https://mcuxpresso.nxp.com/api_doc/dev/2370/group__qn__flash.html

On that assumption using their own config as example structure:

"Exactly how to give pointer source buffer to the API?"

This answers the question, however writing structures to flash like this is a bad idea.

flash_config_t config;

uint8_t *src=(uint8_t *) &config;

Then pass src to your function.

Note that the SDK says source is a uint32_t *, not uint8_t *.
Some devices like the KL27 will only write to flash 32 bits at a time.
This could lead to other casts being required.

offsetof() in stddef.h will be of use to you.

0 Kudos
Reply