Generating EEPROM data and .EEP file

Hi,
I am writing my 1st program using PlatformIO. This for an Arduino environment and as target an ATMEGA328P.
I’d like to specify (define) code in my source that is intended to go to EEPROM (initial values in the internal ATMEGA328’s EEPROM)

I use 2 sorts of code to generate EEPROM data :
__attribute__((section(".eeprom"))) uint8_t eepContent[6] = {0,1,0xFF,3,4,5};

or

static const uint16_t shutter1[] EEMEM = {
    // header
    0x8060, 0x0018,
    // data
    0x8030, 0x0018, 0x8018, 0x0018, 0x8030, 0x0018, 0x8030, 0x0018, // B
    0x8018, 0x0018, 0x8030, 0x0018, 0x8018, 0x0018, 0x8018, 0x0018, // 4
    0x8030, 0x0018, 0x8018, 0x0018, 0x8030, 0x0018, 0x8030, 0x0018, // B
    0x8030, 0x0018, 0x8018, 0x0018, 0x8018, 0x0018, 0x8018, 0x0018, // 8
    0x8030, 0x0018, 0x8030, 0x0018, 0x8030, 0x0018, 0x8030, 0x01c8, // F
    0x0000,
};

I do see an .EEP being generated but its empty (only the intel hex close record).

How can I adapt my source that some of the data will be moved to EEPROM and to the .EEP file ?

Thanks in advance,
Bram

Likely .eep file empty unless also read?

Where do you reference the eepContent variable in your .c/.cpp code?

More specifically, result of

#include <Arduino.h>

 __attribute__((section(".eeprom"))) uint8_t eepContent[6] = {0,1,0xFF,3,4,5};

void setup() { Serial.begin(9600); }

void loop() { delay(1000); }

is

:00000001FF

(empty)

but

#include <Arduino.h>

 __attribute__((section(".eeprom"))) uint8_t eepContent[6] = {0,1,0xFF,3,4,5};

void setup() { Serial.begin(9600); }

void loop() { delay(1000); uint8_t value = eeprom_read_byte(eepContent); Serial.println(value); }

results in

:060000000001FF030405EE
:00000001FF

You can also force the variable to be put in EEPROM regardless of its actual usage in your code (at risk of being wasteful if you forget about it) by using another special attribute, __used__

#include <Arduino.h>

 __attribute__((section(".eeprom"), __used__)) uint8_t eepContent[6] = {0,1,0xFF,3,4,5};

void setup() { Serial.begin(9600); }

void loop() { delay(1000); }

will make the data appear in the .eep file as well. This has the same effect as volatile, too, preventing all compiler optimization.

#include <Arduino.h>

volatile __attribute__((section(".eeprom"))) uint8_t eepContent[6] = {0,1,0xFF,3,4,5};

void setup() { Serial.begin(9600); }

void loop() { delay(1000); }

If you go on to naturally use the EEPROM variable you have created, then no such optimization is needed.

1 Like

First of all thanks for your quick response.
Actually I am not referring to the EEPROM contents (yet).

I wanted it to be default values to be used in my program later, (Timer values).
So that indeed might be the issue (not referencing them).

Im going to test some of your tips !!
Again thanks !