0
\$\begingroup\$

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;
\$\endgroup\$
  • \$\begingroup\$ "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. \$\endgroup\$ – Chris Stratton Apr 5 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.