cancel
Showing results for 
Search instead for 
Did you mean: 

__attribute__ ((aligned (32))) doesn't work.

HIm
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
alister
Lead

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;

View solution in original post

8 REPLIES 8
Ozone
Lead

> 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).

Uwe Bonnes
Principal II

No output/errors/warnings from the compiler? What does the compiler do?

HIm
Associate II

​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).

0690X00000D9h8DQAR.jpg

​There is no errors/warnings. i'm using GNU GCC in SPC5Studio.

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))) ?

HIm
Associate II

​Thank you to reply. i wil try as your mention.

alister
Lead

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;

Thank you for your reply​