Skip to main content
Ekim.1
Associate III
April 3, 2020
Solved

How to fix variables to a specific memory using STM32CubeIDE

  • April 3, 2020
  • 3 replies
  • 4824 views

Hello, everyone.

I am using STM32CubeIDE.

I want to position one variable in the .noinit section and to secure the memory location of this variable to 0x2001FF0.

volatile uint8_t data1 __attribute__ ((section (".noinit")));

I succeeded in using the above code to locate it in the .noinit section, but I did not fix the memory address.

How can you fix your memory address?

This topic has been closed for replies.
Best answer by alister

You're needing to define a section in your linker script, position it at a memory address, use the section attribute in your C source to place the variable there, the section's uninitialised, and the section should not be called .noinit.

For a guide, Google threw this: http://blog.atollic.com/using-gnu-gcc-on-arm-cortex-devices-placing-code-and-data-on-special-memory-addresses-using-the-gnu-ld-linker. It's by Atollic. But CubeIDE will be the same as they both use gnu. This will be good for context.

For detail, consult the linker's documentation: https://sourceware.org/binutils/docs/ld/Scripts.html#Scripts.

A note about .noinit. Typically, it's used for variables you don't want initialised and don't care what their address is, and typically you'd only place large static-storage-class buffers there because there's insignificant cycle-saving placing small variables there.

3 replies

berendi
Principal
April 3, 2020

Just use a pointer, and make sure that the memory area is excluded in the linker script (*.ld).

alister
alisterBest answer
Senior III
April 3, 2020

You're needing to define a section in your linker script, position it at a memory address, use the section attribute in your C source to place the variable there, the section's uninitialised, and the section should not be called .noinit.

For a guide, Google threw this: http://blog.atollic.com/using-gnu-gcc-on-arm-cortex-devices-placing-code-and-data-on-special-memory-addresses-using-the-gnu-ld-linker. It's by Atollic. But CubeIDE will be the same as they both use gnu. This will be good for context.

For detail, consult the linker's documentation: https://sourceware.org/binutils/docs/ld/Scripts.html#Scripts.

A note about .noinit. Typically, it's used for variables you don't want initialised and don't care what their address is, and typically you'd only place large static-storage-class buffers there because there's insignificant cycle-saving placing small variables there.

BMcDo.3
Associate III
February 14, 2024