cancel
Showing results for 
Search instead for 
Did you mean: 

How to fix variables to a specific memory using STM32CubeIDE

Ekim.1
Associate II

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?

1 ACCEPTED SOLUTION

Accepted Solutions
alister
Lead

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.

View solution in original post

3 REPLIES 3
berendi
Principal

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

alister
Lead

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.


@alister wrote:

 

...

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.

That link is now dead. Here it is at the Wayback Machine, and attached.

Using GNU GCC on ARM Cortex devices: Placing code and data on special memory addresses using the GNU LD linker (archive.org)