2023-10-18 08:37 AM
I couldn’t figure out how to write a simple code to write some bytes at the end of the Flash on my STM32H7. I don’t need much bytes, only one uint32_t.
I tried using HAL_FLASH_Program by unlocking the flash first but couldn’t make it work..
Any help?
2023-10-19 05:37 AM
The STM32H735x would be the closest proxy, but any of them where you limit yourself to the one sector would suffice.
The Value Line parts share the same die as others but less of the Flash is tested to save time on the test equipment and improve throughput.
2023-10-19 05:59 AM
Would Option Bytes by a solution to my problem?
2023-10-19 07:02 AM - edited 2023-10-19 07:08 AM
> Would Option Bytes by a solution to my problem?
Option Bytes - not at all. A similar topic was here recently, about some other STM32. A short summary: unless the firmware install procedure has filled the whole flash page, you can find properly aligned empty space past the firmware image and write your data there. Properly aligned here means on 32 bytes boundary. Write also in multiples of 32 bytes (256 bits).
Also, as Tesla DeLorean noted, "value line" STM32H7 can actually have more than one flash page, but its up to you to find them and verify they are working. YMMV.
2023-10-19 07:30 AM
Writing at the end of the firmware sounds like a great idea.
Do I need to erase the bytes first? Or is it a simple as :
uint32_t data[8] = { 0x123456778,
0x123456778,
0x123456778,
0x123456778,
0x123456778,
0x123456778,
0x123456778,
0x123456778,
};
void writeUserSettings(uint32_t* data, uint32_t address)
{
HAL_FLASH_Unlock();
HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, address, data);
HAL_FLASH_Lock();
}
2023-10-19 08:06 AM
As simple as. Locate an empty place and write.
2023-10-19 08:41 AM
Can you be more specific? I know the address where I want to write but don’t know how to
2023-10-19 08:49 AM
Yes. Unlock, then write. Then lock (optionally).
2023-10-19 09:54 AM
The memory must be in an erased state, and then you get one-shot writing it. Perhaps check content first?
When you write/download your test app in the debugger it's going to erase the memory within the whole 128KB sector. You don't need to erase it again, as this will also erase your application, but you'll get one chance to write each block of 32-bytes. You can walk forward, or backward, within memory and write those slots.