Following on from the bug bug detailed here (https://github.com/stm32duino/Arduino_C ... ssues/1016) , the example code for EEPROM read and write wont operate on the internal EEPROM, but instead on an emulated EEPROM.
The advice on the bug note says that the HAL API can be used directly from within a sketch. Thinking that this is probably the only way forward for now until there's an update, I've given it a shot. The code to write values with HAL_FLASHEx_DATAEEPROM_Program appears to run through, however when I go to try to check that the values have been written with a different sketch, the program locks up as though I've hit something protected. I'll be honest, that I don't exactly understand the code for reading from EEPROM, as its a scavenged line, however I've seen it in a couple of places. I believe I've got the correct start point for the EEPROM address, but I could always be wrong.
I've attached the minimal code here. if anything obvious jumps out at anybody about the code, or from their experience about accessing the EEPROM, I'd be very grateful. The "Read" code gets as far as printing the first "0" address location, but does not even get as far as printing out the first underscore (just an underscore char to separate the address from the data).
if anybody understands the line from the read code: "tmp = *(__IO uint32_t*)address;" that would be amazing. There are asterisks in places that are unfamiliar to me.
Kindest thanks.
Write:
Code: Select all
#include <EEPROM.h>
#define FLASH_TYPEPROGRAMDATA_BYTE ((uint32_t)0x00) /*!< Program byte (8-bit) at a specified address.*/
//#define FLASH_TYPEPROGRAMDATA_HALFWORD ((uint32_t)0x01) /*!< Program a half-word (16-bit) at a specified address.*/
//#define FLASH_TYPEPROGRAMDATA_WORD ((uint32_t)0x02) /*!< Program a word (32-bit) at a specified address.*/
//#define FLASH_TYPEERASEDATA_BYTE (0x00U) // Erase 1 byte
//#define FLASH_TYPEERASEDATA_HALFWORD (0x01U) // Erase 2 bytes
//#define FLASH_TYPEERASEDATA_WORD (0x02U) // Erase 4 bytes
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
HAL_FLASHEx_DATAEEPROM_Unlock();
for (int i = 0 ; i < 6252 ; i++) {
HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE, i, 63);
Serial.println(i);
}
HAL_FLASHEx_DATAEEPROM_Lock();
}
void loop() {
}
Read:
Code: Select all
#include <EEPROM.h>
#define DATA_EEPROM_START_ADDR 0x08080000
#define DATA_EEPROM_END_ADDR 0x080817FF
// start reading from the first byte (address 0) of the EEPROM
int address = 0;
uint8_t value;
void setup() {
// initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
//HAL_FLASHEx_DATAEEPROM_Unlock();
}
void loop() {
// read a byte from the current address of the EEPROM
if (address < 6252){
value = readEEPROMByte(address);
Serial.print(address);
Serial.print('_');
Serial.print(value, DEC);
Serial.println();
address = address + 1;
}
}
uint8_t readEEPROMByte(uint32_t address) {
uint8_t tmp = 0;
address = address + 0x08080000;
tmp = *(__IO uint32_t*)address;
return tmp;
}