cancel
Showing results for 
Search instead for 
Did you mean: 

EEPROM Erase/Writes w/ HAL very inconsistent

N.F. Singh
Associate II

I'm running STM32L072RZ and am running into weirdness with the EEPROM. I'm using the Cube32MX HAL library so I can avoid any potential issues. Below is my routine. Sometimes it runs just fine. Other times, it crashes my debug session and doesn't even go into my HardFault catch. Other times, it will crash, and then if I reset the processor it works every time after that.

Just makes no sense. Everything below, including DATA_EEPROM_BASE and the un/lock and the erase/program functions are direct from the HAL.

Is there anything I'm doing wrong here?

uint8_t XEEPROM_Program(uint32_t offsetAddr, uint32_t* dataSrc, uint32_t size) {
	uint32_t address = DATA_EEPROM_BASE+offsetAddr;
	if(!IS_FLASH_DATA_ADDRESS(address+size))
		return 0;
 
	HAL_FLASHEx_DATAEEPROM_Unlock();
 
	for(/**/; address<(DATA_EEPROM_BASE+offsetAddr+size); address+=sizeof(void*)){		
		HAL_FLASHEx_DATAEEPROM_Erase(address); 
		HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_WORD, address, *dataSrc);
		dataSrc++;
	}
	HAL_FLASHEx_DATAEEPROM_Lock();
 
	return 1;
 }

0 REPLIES 0