2019-01-28 02:44 AM
Hi,
I'm trying save some data into EEPROM after successful storage of first byte for second byte it goes to hard fault irq. Can anyone help me out from this issue
void Save_data(float Data)
{
char Buff[15];unsigned long Address=0x08080000;
sprintf(Buff,"%f\n",Data);
for(int i=0;i<15;i++)
{
HAL_FLASH_Unlock();
if(Buff[i] == '\n')
{
HAL_FLASH_Program(FLASH_TYPEPROGRAMDATA_BYTE,Address++,'\0');
break;
}
HAL_FLASH_Program(FLASH_TYPEPROGRAMDATA_BYTE,Address++,Buff[i]);
HAL_FLASH_Lock();
}
return;
}
Solved! Go to Solution.
2019-01-28 05:44 AM
The processors R7 register would be of particular interest here.
Perhaps use the EEPROM functions
#define FLASH_DisableRunPowerDown HAL_FLASHEx_DisableRunPowerDown
#define HAL_DATA_EEPROMEx_Unlock HAL_FLASHEx_DATAEEPROM_Unlock
#define HAL_DATA_EEPROMEx_Lock HAL_FLASHEx_DATAEEPROM_Lock
#define HAL_DATA_EEPROMEx_Erase HAL_FLASHEx_DATAEEPROM_Erase
#define HAL_DATA_EEPROMEx_Program HAL_FLASHEx_DATAEEPROM_Program
HAL_FLASHEx_DATAEEPROM_Unlock();
HAL_FLASHEx_DATAEEPROM_Program(TYPEPROGRAMDATA_BYTE, EEPROM_START + addr, (uint32_t)data); // Iterate use WORD/HALFWORD as appropriate
HAL_FLASHEx_DATAEEPROM_Lock();
2019-01-28 04:44 AM
What part are you using?
Is the memory blank at the location you are writing?
What instruction specifically is faulting, and what are the register settings?
You can also pull the lock/unlock out of the loop but I don't think that is the issue.
2019-01-28 05:24 AM
Hi Clive,
I'm using STM32L072CZY6TR, The Memory I'm trying to write has a value of 0x00 and while loading the address it's going to hard fault. I had tried to pull the Lock/unlock out of loop but the issue didn't resolved. I'm sharing the debug screen with register values.
2019-01-28 05:44 AM
The processors R7 register would be of particular interest here.
Perhaps use the EEPROM functions
#define FLASH_DisableRunPowerDown HAL_FLASHEx_DisableRunPowerDown
#define HAL_DATA_EEPROMEx_Unlock HAL_FLASHEx_DATAEEPROM_Unlock
#define HAL_DATA_EEPROMEx_Lock HAL_FLASHEx_DATAEEPROM_Lock
#define HAL_DATA_EEPROMEx_Erase HAL_FLASHEx_DATAEEPROM_Erase
#define HAL_DATA_EEPROMEx_Program HAL_FLASHEx_DATAEEPROM_Program
HAL_FLASHEx_DATAEEPROM_Unlock();
HAL_FLASHEx_DATAEEPROM_Program(TYPEPROGRAMDATA_BYTE, EEPROM_START + addr, (uint32_t)data); // Iterate use WORD/HALFWORD as appropriate
HAL_FLASHEx_DATAEEPROM_Lock();
2019-01-28 09:38 PM
This worked but what was the problem? I have not understood.
2022-10-18 08:06 AM
I had a similar issue with a project, changing the languages to C99 and C++03 fixed this