I am facing the following problem. I am programming an ARM cortex M4 micro controller and I would like it to have a default value for IP address, netmask, gateway and so on. This default values should be changeable via serial communication AND the changes should be persistent. For example: default value for IP address and netmask are: 192.168.1.20 255.255.255.0 The user changes the address and netmask to 192.168.2.10 255.255.255.0 Now after disconnecting and reconnecting the unit to power supply the "default" values should be the user entered (192.168.2.10/255.255.255.0)
To solve this, I thought about using the so called work flash memory of my uC. This is a non-volatile memory which can be written using special commands. What I am trying to achieve is to define default values in the program code (as variables at the moment, or as defines later if possible) which are picked up by the linker and whose VALUE is put to the non-volatile memory (work flash) at address 0x200C000.
Right now my linker file looks like this:
MEMORY
{
rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x100000 /* 1MB */
ram (rwx) : ORIGIN = 0x1FFF0000, LENGTH = 0x10000 /* 64K */
ram1 (rwx) : ORIGIN = 0x20038000, LENGTH = 0x10000 /* 64K */
wofl (rwx) : ORIGIN = 0x200C0000, LENGTH = 0x8000 /* 32K */
}
...
.wifi_defaults :
{
KEEP(*(.wifi_defaults*));
} > wofl
...
and the variable declaration in the source code (just for testing):
uint16_t __attribute__((section(".wifi_defaults"))) test= 0x00D0;
The .map file shows me:
.wifi_defaults 0x200c0000 0x2
*(.wifi_defaults*)
.wifi_defaults
0x200c0000 0x2 ..\obj\HSFirmware.o
0x200c0000 test
But when accessing the variable I am not getting the correct value, just the initial 0xFFFF which was returned even before starting to mess with the linker stuff.
I also tried to use a CONST in front of the variable declaration, which made no difference.
As far as I understand my code puts an uninitialized variable at the specified code segment. How can I put an initialized variable at the given address?