laesser wrote:
> is there a small flash area where I can write this identifier and which does not interfere with the code and data so as not to be deleted.
Bob S Wrote:
> [use] any area of flash that is not used by your main program
As others have mentioned, UID and OTP are the "proper" ways for identifying a particular chip/board. But if you really want to do use a flash location for this:
- You can easily modify the linker script to carve out a chunk of flash out of the address-space seen by the linker. It then becomes unavailable for the linker to place code/data in.
- Since CubeIDE uses STM32CubeProgrammer behind the scenes for programming the chip and it, in turn, only erases sectors used by the program it's downloading, any flash address space not occupied by the program will not be erased during programming.
So all you need to do it is edit the linker script and modify the flash section's size to be one sector smaller. Anything you put into that sector will not be disturbed by subsequent programming.