cancel
Showing results for 
Search instead for 
Did you mean: 

Writing to & Reading from STM32H7 FLASH memory

mazotcu16
Associate II

Hello, i am trying to read and write from flash memory to hold some configuration datas. I am using STM32H723. When i try to write some part of flash memory, i can write for a few times, than my program goes to hardfault. When i run the code again, my program goes to hardfault instantly without reading even once. When i change the memory address to read to, i can read a few times again but then get the same result. I have some MPU regions but not in the flash area, also i enabled the Speculation default mode settings from Cortex M7 window so i have a 4GB of MPU region that is arranged as default. What might be causing this?

 

void Flash_Read_Data (uint32_t StartSectorAddress, uint32_t *data, uint16_t numberofwords)
{
	while (1)
	{

		*data = *(__IO uint32_t *)StartSectorAddress;
		StartSectorAddress += 4;
		data++;
		if (!(numberofwords--)) break;
	}
}

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Flash can only be written once before it must be erased.

> What might be causing this?

If you try to write twice, it will (a) not work and (b) trigger an ECC error. An ECC error will also occur when you read from a location that has been improperly written to like this.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
Andrew Neil
Evangelist III

Where, exactly, do these Hard Faults occur?

Have you tried debugging to see what's going on?

https://community.st.com/t5/stm32-mcus/how-to-debug-a-hardfault-on-an-arm-cortex-m-stm32/ta-p/672235

 

LCE
Principal

I tried the same, but with the H723's sector size of 128 kB in flash using it as eeprom doesn't make much sense.

So each time you want to overwrite some bits, you must erase the complete 128 kB sector.

TDK
Guru

Flash can only be written once before it must be erased.

> What might be causing this?

If you try to write twice, it will (a) not work and (b) trigger an ECC error. An ECC error will also occur when you read from a location that has been improperly written to like this.

If you feel a post has answered your question, please click "Accept as Solution".