2020-02-11 03:29 AM
i'm working with spc570s and using gnu free gccc in spc5studio.
In my program I need to apply __attribute__(( aligned(32))) to an const struct variable.
I tried like this but it does't work.
for example.
typedef struct
{
uint32_t aa;
uint 32_ bb;
...
}A
static const A ***[2] __attribute__(( aligned(32)))
i want to allocate *** with starting address 0xdddddd00(20,40, 60).
Thank you in advance.
Solved! Go to Solution.
2020-02-12 10:01 PM
First, align the structure, not the variable. See https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-aligned-type-attribute. For example
typedef struct
{
uint32_t first;
uint32_t second;
} __attribute__((aligned(32))) myStruct_t;
myStruct_t myStruct[2];
Next, control its placement in memory. Your post suggests you've already done this somehow. Otherwise for example
myStruct_t myStruct[2] __attribute__((section(".myDevice")));
And in your linker command file
MEMORY
{
<snip>
MY_DEVICE (rw) : ORIGIN = 0xdddddd00, LENGTH = 64
}
SECTIONS
{
<snip>
.myDevice (NOLOAD) :
{
*(.myDevice)
} >MY_DEVICE
}
Finally, as you're accessing a device of some kind and the number and order of bus accesses is probably significant, you ought tell the compiler that with a volatile qualification on each of the structure members, for example
typedef struct
{
volatile uint32_t first;
volatile uint32_t second;
} __attribute__((aligned(32))) myStruct_t;
2020-02-11 03:51 AM
> I tried like this but it does't work.
How did you determine it doesn't work ?
> i want to allocate *** with starting address 0xdddddd00(20,40, 60).
Not sure what that is supposed to mean.
__align__ (32) means an address divisible by 32, i.e. the least significant 5 bits are zero.
With writing "0xdddddd00", you seem to assume the last 8 bits are zero, i.e. align (256).
2020-02-11 04:17 AM
No output/errors/warnings from the compiler? What does the compiler do?
2020-02-11 08:30 PM
I compiled and checked the address of the variable in the map file. start address of variable is 0xddddddF0.
I want the starting address of one of variable to be located at an address that starts with an even number as 32(0x20)byte boundrary( i.e. 0xddddddE0, 0xddddddC0).
2020-02-11 08:31 PM
There is no errors/warnings. i'm using GNU GCC in SPC5Studio.
2020-02-11 10:31 PM
I don't use SPC tools, or GCC version. Never had such trouble with other gcc tools.
Assuming it might be a compiler/linker bug, have you tried the next larger alignment size, i.e. __attribute__(( aligned(64))) ?
2020-02-12 04:22 PM
Thank you to reply. i wil try as your mention.
2020-02-12 10:01 PM
First, align the structure, not the variable. See https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-aligned-type-attribute. For example
typedef struct
{
uint32_t first;
uint32_t second;
} __attribute__((aligned(32))) myStruct_t;
myStruct_t myStruct[2];
Next, control its placement in memory. Your post suggests you've already done this somehow. Otherwise for example
myStruct_t myStruct[2] __attribute__((section(".myDevice")));
And in your linker command file
MEMORY
{
<snip>
MY_DEVICE (rw) : ORIGIN = 0xdddddd00, LENGTH = 64
}
SECTIONS
{
<snip>
.myDevice (NOLOAD) :
{
*(.myDevice)
} >MY_DEVICE
}
Finally, as you're accessing a device of some kind and the number and order of bus accesses is probably significant, you ought tell the compiler that with a volatile qualification on each of the structure members, for example
typedef struct
{
volatile uint32_t first;
volatile uint32_t second;
} __attribute__((aligned(32))) myStruct_t;
2020-02-25 03:18 PM
Thank you for your reply