2024-09-27 04:36 AM - last edited on 2024-09-27 04:38 AM by Andrew Neil
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;
}
}
Solved! Go to Solution.
2024-09-27 06:31 AM
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.
2024-09-27 04:40 AM
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
2024-09-27 05:12 AM
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.
2024-09-27 06:31 AM
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.