How to read data from a specific Flash address in order write it on a variable

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

How to read data from a specific Flash address in order write it on a variable

2,048 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Burkhard on Tue Jun 17 08:55:30 MST 2014
Dear programers,

I would like to use the LPC810M021FN8 for a new application.
In order to save the state of the device before turning it off I save that state to the flash page which starts with the address 0xC00.

Here comes the problem: How do I read that value which is stored the flash address 0xC00?

Any easy to understand C code would be much appreciated!

I use for writing the state to the address this code: http://www.lpcware.com/content/forum/eeprom-emulation

Thanks in advance!
Burkhard
Labels (1)
0 Kudos
4 Replies

1,787 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sun Apr 12 15:10:46 MST 2015

Quote: bonds22
Here comes the problem: How do I read that value which is stored the flash address 0xC00?



memcpy 

or a simple old-fashioned pointer:

 uint32_t val;
 uint32_t address= [color=#00f]type in your address here[/color];
 val = (*(uint32_t*)address);
0 Kudos

1,787 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bonds22 on Sun Apr 12 14:22:26 MST 2015
Here comes the problem: How do I read that value which is stored the flash address 0xC00?
0 Kudos

1,787 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Helmut Stettmaier on Tue Jul 29 04:58:41 MST 2014
Hello Burkhard,
To locate a parameter block into the flash memory and read it randomly I suggest to declare the structure of the block and place a variable of this structure at the location in flash as desired.
This is done in 3 steps:
- declare sthe structure as usual,
- place a variable of this structure in a section, and
- locate the section at the desired location
This is code which currently works:

const __attribute__ ((section(".param_page"))) struct sParams {
uint8_tsize;///< size of this struct
// more stuff
int16_t altAlarm;///< Altitude (lower boundary) when an alarm shall be generated
} Params;


In the IDE click or select:  Project|Properties|C/C++Build|Settings|MCU Linker|Miscellanous
Add the linker control: --section-start=.param_page=0x3f80

This allows you to read any value, e.g. Params.altAlarm .

Hope that helps.
Kind regards, Helmut
0 Kudos

1,787 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by starblue on Tue Jun 17 09:27:09 MST 2014
This is just part of the normal memory, so you can for example access it via a pointer, or use memcpy to copy it.
0 Kudos