2019-08-11 02:51 AM
Hello everyone,
I just migrate from Keil. I can use __attribute__((at(0x6000000))) directive place a variable at a given absolute address ,but how to do this in STM32CubeIDE?
Thanks.
2019-08-11 07:44 AM
It is generally considered non-portable. You can use the attribute directive and section naming in the linker script of GNU tools.
Consider if you can just use pointers. For larger groups of data, structures.
ie
char *foo = (char *)0x6000000;
2019-08-11 07:57 AM
Thank you for your prompt reply.
I have a piece of code , such as
//-----------------------------------------------------------------------------------------------------------
__align(32) u8 mem2base[MEM2_MAX_SIZE] __attribute__((at(0X60000000)));
//-----------------------------------------------------------------------------------------------------------
There is a align directive ,so I don't think I can use the point.
I will use the attribute directive and section naming that you mentioned.
Thanks
2019-08-11 11:41 AM
Unless it's a physical special area, it would be better to avoid absolute address, especially when porting to different MCU.
Why such a need?
2019-08-13 08:43 AM
Yes, it's a SRAM address.
Thanks, I solved the issue by changing the link script file, add section directive.
2019-08-13 09:57 AM
You're providing an absolute address, where you explicitly control the placement.
The __align directive doesn't impact any other usage of the of the variable, as far as I'm aware
u8 *mem2base = (u8 *)0x60000000;
would have materially the same effect, and be accessible in the same way, ie printf("%02X\n", mem2base[123]);
2019-08-13 10:46 AM
oh, I see, this is the simpler way,
Thanks
2022-09-22 05:07 AM
@Community member
I'm tryna use this method of pointers, but how can I use this pointer to point to a variable?
It would be good if you post it with an example.
2022-09-22 09:37 AM
It's a pointer method, it works the way pointers do, perhaps K&R chapter on such things?
typedef struct _CONFIG_STRUCT {
uint32_t a;
uint32_t b;
uint32_t c[12];
uint32_t checksum;
} CONFIG_STRUCT;
CONFIG_STRUCT *cfg = (CONFIG_STRUCT *)0x60001000;
cfg->checksum = 1234;
cfg->a = 1;
cfg->b = 2;
printf("%d\n", cfg->b);
int foo = cfg->a;
...
2022-09-23 10:08 AM
@Community member
Thanks for the example. But this does not work if I'm giving the address as the initial address of the RAM and If I declare any global variable, it gets over written on the same address