[Solved] The use of EEMEM, but eep remain empty.

I’m using Arduino IDE 1.8.2 and 1.8.1, the problem still unsolved the eep file returns 13 bytes which is an empty intel hex.

Even trying

#include <avr/io.h>
#include <avr/eeprom.h>

const uint8_t eeprdata[] EEMEM = {
    1,                                      // this indicate a valid data
    0, 0x02, 0xd0, 0x3, 0x20, 100, 60, 0,   // struct channel 1
    0, 0x02, 0xd0, 0x3, 0x20, 100, 60, 0,   // struct channel 2
    0, 0x02, 0xd0, 0x3, 0x20, 100, 60, 0,   // struct channel 3
    0, 0x02, 0xd0, 0x3, 0x20, 100, 60, 0,   // struct channel 4
};

The file remains empty.

I read this but I don’t know how to fix, when the versions are different and I have some doubts where to put the patch.

Does your actual code reference eeprdata?

Here is a good start http://snippets-r-us.com

OK sorry being confusing, I supposed the snippet was explainatory enough.
The following will compile correctly with Arduino IDE 1.8.2

#include <avr/io.h>
#include <avr/eeprom.h>

const uint8_t eeprdata[] EEMEM = {
    1,                                      // this indicate a valid data
    0, 0x02, 0xd0, 0x3, 0x20, 100, 60, 0,   // struct channel 1
    0, 0x02, 0xd0, 0x3, 0x20, 100, 60, 0,   // struct channel 2
    0, 0x02, 0xd0, 0x3, 0x20, 100, 60, 0,   // struct channel 3
    0, 0x02, 0xd0, 0x3, 0x20, 100, 60, 0,   // struct channel 4
};
void setup() {}
void loop() {}

Anyways the mentioned *.ino.eep file contains no valid data.

As already alluded to, the compiler can optimize away items in the code that are not used. Since that example does nothing at all, I'm guessing that's what happened here.

So, supposing that. How will I write to eeprom a block of data, by avrdude ?
In such a case any constrain to block compiler otpimizations ?
My intent is to write the initial data directy in eeprom by avrdude. Not by the program.

Otherwise I would opt to EEPROMex. But I fill like a complication.

EEPROMVar<int> myvar = 750;

So any of my persistent data should work in EEPROM.

#include <avr/io.h>
#include <avr/eeprom.h>

const uint8_t eeprdata[] EEMEM = {
    1,                                      // this indicate a valid data
    0, 0x02, 0xd0, 0x3, 0x20, 100, 60, 0,   // struct channel 1
    0, 0x02, 0xd0, 0x3, 0x20, 100, 60, 0,   // struct channel 2
    0, 0x02, 0xd0, 0x3, 0x20, 100, 60, 0,   // struct channel 3
    0, 0x02, 0xd0, 0x3, 0x20, 100, 60, 0,   // struct channel 4
};

void setup( void )
{
  GPIOR0 = eeprom_read_byte(&eeprdata[0]);
}

void loop(void){}

ExperimentUno:
I’m using Arduino IDE 1.8.2 and 1.8.1, the problem still unsolved the eep file returns 13 bytes which is an empty intel hex.

Even trying

#include <avr/io.h>

#include <avr/eeprom.h>

const uint8_t eeprdata EEMEM = {
   1,                                      // this indicate a valid data
   0, 0x02, 0xd0, 0x3, 0x20, 100, 60, 0,   // struct channel 1
   0, 0x02, 0xd0, 0x3, 0x20, 100, 60, 0,   // struct channel 2
   0, 0x02, 0xd0, 0x3, 0x20, 100, 60, 0,   // struct channel 3
   0, 0x02, 0xd0, 0x3, 0x20, 100, 60, 0,   // struct channel 4
};



The file remains empty.

I read [this](http://www.fucik.name/Arduino/eemem.php) but I don't know how to fix, when the versions are different and I have some doubts where to put the patch.

You have the EEMEM array formatted correctly, but the compiler will not add it to the object file and link it in unless you actually USE it in your program.

Try simply adding this:

Serial.println (eeprom_read_byte ((const uint8_t *) eeprdata[0]));

– or –

uint8_t n = (sizeof (eeprdata) / sizeof (*eeprdata));
uint8_t x;
for (x = 0; x < n; x++) {
    Serial.println (eeprom_read_byte ((const uint8_t *) eeprdata[x]));
}

This forces the compiler to say “ah ha he’s actually trying to read a value - now I have to link it in!” and then you should see a rather larger “sketch.eep” file! :slight_smile:

ExperimentUno: So, supposing that. How will I write to eeprom a block of data, by avrdude ? In such a case any constrain to block compiler otpimizations ? My intent is to write the initial data directy in eeprom by avrdude. Not by the program.

I THINK (haven't tried it) if you declare your EEMEM array as static or volatile, it will be compiled in even if you don't use it.

This shouldn't be a problem though, because of course your FINISHED program will use the EEMEM data and then it will be compiled in.

To test to be sure the data is "going in", try "static", "volatile" or better simply one line of code that references the array. That should do it, and you can verify by looking at the .EEP file.

NOTE though that off-the-shelf Arduino bootloaders don't usually load .eep files because the bootloaders are so full of garbage like blinking LED's and monitor programs that they need to save space and sacrificed eeprom loading (which is no problem since most people use the ridiculous Arduino "EEPROM.h" library instead of doing it the right way (by using EEMEM).

If you're interested in slim 328p and mega2560 bootloaders that take a lot less space in the boot flash section AND actually load eeprom hex files, PM me.

Thanks everybody, I solved. @ krupski Neither volatile nor static would force to create the eeprom data.

For future references, the clue is to mention the use of that data, so the compiler won't optimize :-\ I think that should be an option in the CLI to avoid this case, but this it could be hidden to be set from the IDE.