cancel
Showing results for 
Search instead for 
Did you mean: 

EEPROM Write Goes to Hard Fault

VijayRakeshM
Associate III

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;
}

1 ACCEPTED SOLUTION

Accepted Solutions

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();

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

5 REPLIES 5

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.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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.

0690X000006DGFxQAO.png

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();

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

This worked but what was the problem? I have not understood.

markH
Associate III

I had a similar issue with a project, changing the languages to C99 and C++03 fixed this