how to assign absolute address to an array and structures.
Hi @aravindhg ,
@giraffe508 's answer is correct, you can refer to the above reply, thanks so much!
Best Regards,
Kerry
Hi, To assign an absolute address to an array or structure, you can use the attribute keyword along with the section attribute in your C code. The section attribute allows you to specify a particular memory section where the variable should be placed. Here's an example of how to do this:
// Declare an array with an absolute address uint8_t myArray[10] __attribute__((section('.myArraySection')));
// Declare a structure with an absolute address struct MyStruct { uint32_t field1; uint16_t field2; } myStruct __attribute__((section('.myStructSection')));
Next, you need to modify your linker script to define the memory sections and their respective addresses. Here's an example of how to do this:
MEMORY { /* Other memory regions */ MY_ARRAY_REGION (rw) : ORIGIN = 0x20000000, LENGTH = 0x10 MY_STRUCT_REGION (rw) : ORIGIN = 0x20000010, LENGTH = 0x10 }
SECTIONS { /* Other sections */ .myArraySection : { KEEP(*(.myArraySection)) } > MY_ARRAY_REGION
.myStructSection : { KEEP(*(.myStructSection)) } > MY_STRUCT_REGION }
In this example, the linker script defines two memory regions, MY_ARRAY_REGION and MY_STRUCT_REGION, with their respective starting addresses and lengths. The .myArraySection and .myStructSection sections are then placed in these memory regions.
Make sure to adjust the memory addresses and lengths according to your specific requirements and the memory map of your target device.