How to initialize EEprom in Pico Arduino

Hi, I am working with the Pico Arduino and I need to initialize the contents of two addresses of the EEprom memory, we know that the Raspberry Pi Pico RP2040 does not have integrated EEprom memory but that the Arduino is using a fragment of the flash memory for this purpose, well I'm using this code but it doesn't seem to work, It seems that with the attribute constructor the EEprom memory is not being written correctly, could someone help me? Here is my code:

#include <EEPROM.h>

#define EEPROM_ADDR_1 12
#define EEPROM_ADDR_2 33
#define PREDEF_VALUE_1 55
#define PREDEF_VALUE_2 88

// Constructor de atributos para inicializar EEPROM
void __attribute__((constructor)) initEEPROM() {
  EEPROM.begin(512); // Inicializa la EEPROM Simulada
  EEPROM.write(EEPROM_ADDR_1, PREDEF_VALUE_1);
  EEPROM.write(EEPROM_ADDR_2, PREDEF_VALUE_2);
}

void setup() {
  Serial.begin(115200);
  Serial.println("Test EEPROM Pico");

  int value1 = EEPROM.read(EEPROM_ADDR_1);
  int value2 = EEPROM.read(EEPROM_ADDR_2);

  Serial.print("Valor en la dirección ");
  Serial.print(EEPROM_ADDR_1);
  Serial.print(": ");
  Serial.println(value1);
  
  Serial.print("Valor en la dirección ");
  Serial.print(EEPROM_ADDR_2);
  Serial.print(": ");
  Serial.println(value2);
}

void loop() {
}

Please could you give me an example how to do it?

Your suggest to me in this case is not working for me because every time I initialize or reset the RPi pico the EEprom is written the same value, what I need as I said at the beginning of the post is to initialize or prerecord those two data, I need the EEprom to come with those values ​​already recorded or stored before entering setup().

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.