STM32L151CB Internal EEPROM bugs out
Hello everyone,
For my current project, I am building a logger of sorts. Supposed to aquire data (from the ADC channels) over important time periods : looking for months of logging, with only a couple of notable events per week.
I was thining of storing such events on the internal EEPROM (4k), so they would be preserved in case power goes out. For that, I used the RM0038 and the HAL library on STM32 cube to write bits of code to read, write and clear EEPROM. (about 6 words per event)
I think I can successfully read it, with :
uint32_t EEPROM_Read_int32(uint32_t pos)
{
uint32_t* uint32_pointer;
uint32_t data;
uint32_pointer = (uint32_t*) (0x08080000+pos);
data = *uint32_pointer;
return data;
}
I had decent success writing on it with
void EEPROM_Write_uint32(uint32_t pos, uint32_t data)
{
HAL_FLASHEx_DATAEEPROM_Unlock();
HAL_FLASHEx_DATAEEPROM_Program(TYPEPROGRAMDATA_WORD, 0x08080000+pos, data);
HAL_FLASHEx_DATAEEPROM_Lock();
}
But terrible luck with erasing data with
void EEPROM_Clear(uint32_t pos)
{
HAL_FLASHEx_DATAEEPROM_Unlock();
HAL_FLASHEx_DATAEEPROM_Erase(TYPEERASEDATA_WORD, 0x08080000+pos);
HAL_FLASHEx_DATAEEPROM_Lock();
}
When I want to clear EEPROM most of the time // when i want to write on EEPROM some times, the program just bugs out and I have to restart the card.
I assume it is because it is trying to write on already occupied words and clear empty words, but it does not work even with a check before using the read fonction.
Using step by step debug, it fizzles when I reach
"*(__IO uint32_t *) Address = 0x00000000U;"
Anyone has enough insight on EEPROM to help me solve this issue ?
Also, let me know if you wish more information.
