cancel
Showing results for 
Search instead for 
Did you mean: 

how to write a specific portion of memory during compile?

ahmash
Associate III

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
ahmash
Associate III

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

View solution in original post

4 REPLIES 4
Pavel A.
Super User

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)
  }
...........
}

 

Karl Yamashita
Principal

See this knowledge base

https://community.st.com/t5/stm32-mcus/how-to-allocate-a-variable-in-a-specific-address-in-stm32cubeide/ta-p/732470

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.
CAN Jammer an open source CAN bus hacking tool
CANableV3 Open Source

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ahmash
Associate III

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