Flash driver example: Reading the flash memory

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

Flash driver example: Reading the flash memory

Jump to solution
1,637 Views
gauravbanyal
Contributor IV

Hello,

 

I am using FRDM-KL03Z board and experimenting with the SDK 2.0 example \frdmkl03z\driver_examples\flash\pflash.

The example ends at flash write and verification. I would like to read the data written to the flash. I have tried using the function "FLASH_ReadResource" but I always get an error response "kStatus_FLASH_InvalidArgument" from the function "flash_check_resource_range". Moreover there is no mention of "FLASH_ReadResource" in the SDK API documentation.

 

Please let me know how to read out the array written to the flash in this example.

 

An early response will be much help.

Labels (1)
0 Kudos
Reply
1 Solution
1,012 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Gaurav Banyal,

The FLASH_ReadResource API is for a special flash memory region called Flash IFR. In particular for the KL03 this region includes a 64 bytes Program Once Field. You can find details about Program Once Field in the Reference Manual.

There is no dedicated API for reading flash as you can simply do it with a pointer or any C code method. Following the logic of the example you could read the written data in a separate buffer like below:

// Extra variables to read data
uint32_t read_buffer[BUFFER_LEN];
uint32_t *flash_ptr;

//...Example code

flash_ptr = (uint32_t*)destAdrss;

for (i = 0; i < BUFFER_LEN;  i++)
{   
   read_buffer[i] = *flash_ptr++;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I hope this helps to clarify.

Best Regards!,
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
Reply
1 Reply
1,013 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Gaurav Banyal,

The FLASH_ReadResource API is for a special flash memory region called Flash IFR. In particular for the KL03 this region includes a 64 bytes Program Once Field. You can find details about Program Once Field in the Reference Manual.

There is no dedicated API for reading flash as you can simply do it with a pointer or any C code method. Following the logic of the example you could read the written data in a separate buffer like below:

// Extra variables to read data
uint32_t read_buffer[BUFFER_LEN];
uint32_t *flash_ptr;

//...Example code

flash_ptr = (uint32_t*)destAdrss;

for (i = 0; i < BUFFER_LEN;  i++)
{   
   read_buffer[i] = *flash_ptr++;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I hope this helps to clarify.

Best Regards!,
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply