6 years, 8 months ago.

How to read data from the flash

After reviewing the IAP internal flash write example and documentation, I seem to be missing a basic point:

How do I read the contents of the flash into memory?

In my application I want to store a large data table in flash (only once or maybe occasional updates) but refer to the table frequently and rapidly. In the example and in the hardware manual I see write and compare, but not a simple read function.

I'm sure I must be missing something basic.



Question relating to:

Sample code for how to erase/write LPC1768, LPC11U24, LPC1114, LPC812 and LPC824 internal flash memory. This program uses IAP call of MCU's ROM routines. The IAP library also supports read/write … EEPROM, IAP, In-Application Programming, internal EEPROM, internal flash memory

1 Answer

6 years, 8 months ago.

See in the main.cpp there the memdump function. The basic part you are missing is that you need specialised hardware to write to the flash (I personally don't know why you would want to use that hardware also for comparing, since you can simply read it out and compare it in code), but you don't need anything special to read from flash, you do it all the time in your code.

What you only need to know is the address where it is stored, which depends on which flash block you are using. Then you can simply make a pointer towards that block. For example:

char *table = (char*)your_address;

Make a new table pointer (effectively the same as an array, so afterwards you can use it as an array), and give that as value the address where the data is, converted to char pointer.

Accepted Answer

Since editting answers seems to be again/still broken, you can also check as example: http://mbed.org/users/Sissors/code/FreescaleIAP/. It is for Freescale devices, and uses significantly different functions, but it also uses that method to read back data.

posted by Erik - 20 Jun 2014

Thanks, that was very helpful. Having not worked with this processor before, I didn't realize that it had a simple flat memory model. I was able to set up pointers as you mentioned and read out any of the flash address space!

posted by Chuck Davis 21 Jun 2014