Skip to main content
Associate
September 27, 2024
Solved

Writing to & Reading from STM32H7 FLASH memory

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

 

 

This topic has been closed for replies.
TDK
TDKBest answer
September 27, 2024

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

3 replies

Andrew Neil
Super User
September 27, 2024

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

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
LCE
Principal III
September 27, 2024

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
TDKBest answer
September 27, 2024

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