# STM32L0 Hangs on writing EEPROM

I've got an STM32L073RZ and I'm attempting to write a 4 byte value to the internal 6 KB EEPROM. I'm running MbedOS 5.11.4 but attempting to use the HAL for this. Here's the code:

HAL_Init();

float calibrationFactor = 13000.0;
uint32_t calibrationFactor_bits;

LOG("Store float in 32 bits");
memcpy(&calibrationFactor_bits, &calibrationFactor, sizeof(uint32_t));

LOG("Unlock EEPROM");
HAL_FLASHEx_DATAEEPROM_Unlock();

LOG("Write to EEPROM");
HAL_StatusTypeDef success = HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAM_WORD, DATA_EEPROM_BASE, calibrationFactor_bits);
LOG("HAL_StatusTypeDef: %d", success);

LOG("Lock EEPROM");
HAL_FLASHEx_DATAEEPROM_Lock();


The program seems to hang when writing to the EEPROM as the function HAL_FLASHEx_DATAEEPROM_Program never returns. As far as I'm aware I'm not doing anything wrong but obviously I must be. Does anyone have any pointers?

EDIT: I've now also tried a code snippet from the STM32L073RZ reference manual, still with the same issue:

*(uint32_t *)(DATA_EEPROM_BASE) = calibrationFactor_bits;

• "Hangs" isn't really a useful problem report - use the debugger to figure out where it is sitting, for example in an infinite loop or in the hard fault handler. You may want to try something simple without mbed os. – Chris Stratton Apr 5 '19 at 16:26

ScopedRomWriteLock make_rom_writable;

then call HAL_FLASHEx_DATAEEPROM_Program.