cancel
Showing results for 
Search instead for 
Did you mean: 

How do you assign a specific address to a static constant variable? (STM32CubeIDE)

JayDev
Senior II

Not sure if this is relatively straight forward, I assume it likely is pretty straight forward (using an STM32L412 device in MXCubeIDE) but I'm having trouble finding out how to go about it. I've tried a number of complicated ways to do this (creating a section in the linker script, feel free to check out my previous post) but it sounds like the easiest way would be to create the desired array in Flash by initializing it as a static const (at a desired location).

For my application, I won't need to write to this location (at least not from within code), and I don't want it to be zero initialized. Essentially, I want to be able to change the values in flash using STM32CubeProgrammer (there's a practical reason for this, besides my own learning) so I can change that section of the code without changing the operation of the rest of the code.

For instance, I want to take this 4 byte array and assign it to memory location 0x08010000, for instance.

static const uint8_t flash_array[4] =
{
	0x01, 0x02, 0x03, 0x04
};

If I compile it as is, I can see it's placed elsewhere (which makes sense as I didn't specify a desired location) and I can see it just fine at the location using STM32CubeProgrammer. I assume there's a way I can assign just the variable minus the initialization to a memory location.

I know I can just compile the code, make note of the location and change this after the fact but I'd like a little more control over the variable if at all possible (in case I find a reason to need this functionality down the road).

Any help you can give me would be greatly appreciated! I've been searching for different approaches and solutions for the past day or so and I keep getting close but haven't quite found the path I need to resolve this issue.

Thanks!

1 REPLY 1
Radosław
Senior II

This can be done only by linker. You need to create separate section for this variable.