2025-10-31 12:05 PM
hello everyone ,i am using stm32f1 and cubeide , i want to put a 16bit security key on flash memory position page 63 during compile or build process ,is it possible ?
Solved! Go to Solution.
2025-10-31 11:54 PM
problem solved I put this part at the bottom of linker file before closing '}' of
/* Sections */
SECTIONS
/////start user section////
.mydata 0x0800FC04 : //address
{
KEEP(*(.mydata))
} >FLASH
//end user section
} //SECTIONS closing brace
then add this following line in c file
const uint32_t myValue __attribute__((section(".mydata"))) = 33668899; //store key 33668899
i tried this method from claude thanks everyone
2025-10-31 12:57 PM - edited 2025-10-31 12:58 PM
With a GNU toolchain (that comes with CubeIDE or any other): include a snippet like following in the SECTIONS part of the linker script:
ADDR = 0x08010000 ; /* the address */
SECTIONS
{
....................
....................
.security_key ADDR:
{
key_start = .; /* Public symbol to access from C */
SHORT(0x1234)
}
...........
}
2025-10-31 1:17 PM
See this knowledge base
2025-10-31 4:11 PM
At a "compiler" level you could also cast a pointer.
uint16_t *key = (uint16_t *)0x080FF800;
Can use for structures too, adapt the address to reflect the specific STM32 part you are using. Shrink the FLASH size in the Linker Script to stop it being used.
Other part have OTP or EEPROM.
2025-10-31 11:54 PM
problem solved I put this part at the bottom of linker file before closing '}' of
/* Sections */
SECTIONS
/////start user section////
.mydata 0x0800FC04 : //address
{
KEEP(*(.mydata))
} >FLASH
//end user section
} //SECTIONS closing brace
then add this following line in c file
const uint32_t myValue __attribute__((section(".mydata"))) = 33668899; //store key 33668899
i tried this method from claude thanks everyone