2023-06-07 03:30 PM
2023-06-07 03:54 PM - edited 2023-11-20 03:41 AM
Hi
I have been having problems with Eeprom Emulation API lately.
I`m trying to write a byte to 0x20 using EE_WriteVariable8bits but the return value is EEPROM_WRITE_ERROR. I noticed before execting Write , FLASH_FLAG_BSY is set in FLASH.SR
I call XXXFlashRead() to read some application variables at the beginning which performs mandatory EE_Init() according to AN4894
void XXXFlashRead(void) {
EE_Status ee_status = EE_OK;
/*
Unlock the Flash Program Erase controller
Unlock the Flash Program Erase controller*/
HAL_FLASH_Unlock();
/*Set EEPROM emulation firmware to erase all potentially incompletely erased
pages if the system came from an asynchronous reset. Conditional erase is
safe to use if all Flash operations where completed before the system reset*/
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) == RESET) {
/* System reset
comes from a power -on reset: Forced Erase Initialize EEPROM emulation driver( mandatory)*/
ee_status = EE_Init(EE_FORCED_ERASE);
if (ee_status != EE_OK) {
Error_Handler();
}
} else {
// Clear the Standby flag
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
// Check and Clear the Wakeup flag
if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUF) != RESET) {
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF);
}
/* System reset comes from a STANDBY wakeup: Conditional Erase
Initialize EEPROM emulation driver (mandatory)*/
ee_status = EE_Init(EE_CONDITIONAL_ERASE);
if (ee_status != EE_OK) {
Error_Handler();
}
}
#if (PRODUCT_TYPE == PRODUCT_BACNET)
uint8_t Index = 1;
//Flash Address :1 to 10 - Read BACnet Device Name from Flash
for (Index = 1; Index < 10; Index++) {
ee_status |= EE_ReadVariable8bits(Index,
&Config.deviceName[Index - 1]);
}
//Flash Address :11 - Read BACnet Device Instance Number
ee_status |= EE_ReadVariable8bits(11, &Config.deviceInstance);
//Flash Address :12 - Read MSTP Address from Flash
ee_status |= EE_ReadVariable8bits(12, &Config.mstpAddress);
#else
if ((EE_ReadVariable32bits(EEPROM_BAUDRATE_ADDR, &Config.baud)
& EE_STATUSMASK_ERROR ) == EE_STATUSMASK_ERROR) {
Error_Handler();
}
if ((EE_ReadVariable8bits(EEPROM_MODBUS_SLAVE_ADDR,
&Config.modbusSlaveAddr) & EE_STATUSMASK_ERROR )
== EE_STATUSMASK_ERROR) {
Error_Handler();
}
if ((EE_ReadVariable8bits(EEPROM_FW_UPDATE_ADDR, &isFWUpdateEnable)
& EE_STATUSMASK_ERROR ) == EE_STATUSMASK_ERROR) {
Error_Handler();
}
#endif
//Start cleanup IT mode, if cleanup is needed
if ((ee_status & EE_STATUSMASK_CLEANUP ) == EE_STATUSMASK_CLEANUP) {
ErasingOnGoing = 1;
ee_status |= EE_CleanUp_IT();
}
if ((ee_status & EE_STATUSMASK_ERROR ) == EE_STATUSMASK_ERROR) {
Error_Handler();
}
HAL_FLASH_Lock();
}
This is where the Write is called after receving a command from Modbus Client.
EE_WriteVariable8bits returns EE_WRITE_ERROR. Before executing EE_WriteVariable8bits I checked the FLASH.SR and the
void XXXFlash_SetFWUpdate(uint8_t isFwUpdate) {
EE_Status ee_status = EE_OK;
//Unlock the Flash Program Erase controller
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS) ;
if (isFwUpdate == 1)
ee_status = EE_WriteVariable8bits(EEPROM_FW_UPDATE_ADDR, 0x55);
else
ee_status = EE_WriteVariable8bits(EEPROM_FW_UPDATE_ADDR, 0x22);
/* Test is completed successfully
Lock the Flash Program Erase controller*/
HAL_FLASH_Lock();
}
Screenshot the expression window
If I let debugger run , Hard Fault Handler is called. LAst know location is HAL_FLASH_Lock();
This functionality was working until few days ago where I was running some test and received an exception (I can`t remember the details) and I restarted debugger which migh left the flash in an odd state.
Full chip erase works using Cube Programmer
I was wondering if anyone knows resoution for this issue.
Thanks