2020-04-29 12:13 PM
Hi all,
I am using HAL_FLASH_Program() to program an uuid into a specific address. I can verify it write successfully by reading from the address. However, if I power cycle the MCU, the memory at that address returns to the original value. If I write it directly through ST-Link then it stays permanently. Does anyone know why is that? Do I need to erase the memory location before write to it using HAL_FLASH_Program()? I am using STM32F745.
Thank you
Solved! Go to Solution.
2020-04-30 10:45 AM
How exactly do you write it?
2020-04-30 10:46 AM
I posted the code in the comment below.
2020-04-30 10:48 AM
The address must be aligned, 0x080BFFFB is not aligned for halfword writes, use an even number (and for full words, one divisible by 4).
2020-04-30 10:52 AM
2020-04-30 10:59 AM
()
2020-04-30 11:02 AM
> set PG before STRT.
No need for that on the F7
2020-04-30 11:35 AM
Thank you. Changing the address solved the PGPERR problem. However, my original problem still remains. The flash write is not permanent, and when I power cycle the MCU, it goes back to 0xFFFF.
What is interesting is if I run the MCU in debugger mode, put a break point anywhere inside the FA_program_uuid() above, it works. I then can stop the debug session, power reset, and the memory data remains.
However if I run in debugger mode without any break point, the memory data is reverted back to 0xFFFF.
What could be the difference between running in debugger mode, with a break point, vs running in normal (release) mode (and vs running in debugger mode without a break point)?
2020-04-30 11:40 AM
Fixed it:
FLASH->CR |= 0x1; //Set PG bit
__DMB();
*(volatile uint16_t*) 0x080BFFFA = uuid;
__DMB();
while(FLASH->SR & 0x0100)
P.S. And of course the HAL code is broken in this regard...
2020-04-30 11:55 AM
Thank you! It now works properly.