Question

I am relatively new to embedded programming and have not been able to find a way to save data to the MCU, so that it persists during reboots.

I have read somewhere that I will need to use PROGMEM to save to the MCU flash. But have not found any further details.

I need to be able to perform the following:-

  • Save a string (device name) to the MCU.
  • Retrieve the string (device name) from the MCU when required.

I am developing on a ARM Cortex M4 Microcontroller

EDIT: I have just noticed that the ARM Cortex M4 (TI TM4C123x Series) I am working with has 2k of EEPROM, so I am assuming that is a better option for persisting data. But how?

Was it helpful?

Solution

If the data needs to persist through only a soft reset then you should be able to store the data in RAM. You would need to make sure that the startup code does not initialize the portion of RAM where the persistent data is located. But if you want the data to be persistent while power is removed then you need to store the data in non-volatile memory such as flash or EEPROM.

In order to write data to flash or EEPROM you're going to need driver code that manipulates the control registers as necessary. In order to write the driver you're going to have to read and understand the relevant sections of the data sheet for the device.

TI makes an evaluation board called the Tiva C LaunchPad (EK-TM4C123GXL) which contains a TM4C123G microcontroller. In support of the board they also provide software including example programs and drivers. Their driver software includes example drivers for the on-chip flash and EEPROM. You should download this software and review the flash and EEPROM drivers and other examples. You may be able to use their example driver as-is. Here is a link to the Tiva C LaunchPad resource page where you can download the software.

OTHER TIPS

You need to look at the data sheet for your specific microcontroller or system-on-a-chip.

You can probably write to program flash, but that's a bit "scary" since then you run the risk of external tools overwriting your data for instance when you re-flash the actual software the next time.

If your device has some other non-volatile storage area, use that instead of the program flash.

The exact directions on how to do this are (way) outside of what the C language specifies; you need to figure out which registers to write to and in what exact sequence. Often there are timing requirements too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top