cancel
Showing results for 
Search instead for 
Did you mean: 

Writing my own ID into flash

laesser
Associate II

Hello,

I want to write my own ID in the STM32WL55 memory. For this I use STM32Cubeprogram and the ST-LINK V3.
My question is: 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.
I looked at the memory organization in the documentation but it's a bit confusing.

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
BarryWhit
Lead II

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.

 

- If someone's post helped resolve your issue, please thank them by clicking "Accept as Solution".
- Please post an update with details once you've solved your issue. Your experience may help others.

View solution in original post

4 REPLIES 4
Bob S
Principal

I don't know specifically for the WL55 chips, but there is usually an OTP section (one-time programmable) that is available, typically in the 0x1fff7xxx area (after the internal bootloader).  If you don't want to use that (or if it is too small), then any area of flash that is not used by your main program or in-circuit code updater.

AScha.3
Chief II

Hi,

OTP area seems perfect for this, see rm:

AScha3_0-1721671740203.png

AScha3_1-1721671783504.png

 

If you feel a post has answered your question, please click "Accept as Solution".
TDK
Guru

You can also consider using the 96-bit unique ID (UID) or UID64 register to identify the chip, if that's the intention.

 

If you feel a post has answered your question, please click "Accept as Solution".
BarryWhit
Lead II

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.

 

- If someone's post helped resolve your issue, please thank them by clicking "Accept as Solution".
- Please post an update with details once you've solved your issue. Your experience may help others.