Force variables alignment in MC56F8XXXX DSC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Force variables alignment in MC56F8XXXX DSC

Jump to solution
2,062 Views
cabl
Contributor III

Hi there,

 

How could one easily force alignment of variables in code (avoiding creation of specific section in linker files, and explicit placement via OBJECT)? Something similar to the #pragma pack present in other micros.

 

Thanks.

 

----------------------------------

 

Hola,

 

¿Cómo se puede fozar fácilmente la alineación de variables desde el código (evitando crear secciones nuevas en el fichero del linker y evitando tener que colocar cada variable con OBJECT)? Algo parecido a #pragma pack existente para otros micros.

 

Gracias.

Labels (1)
1 Solution
1,681 Views
Ben
Senior Contributor I

Hi Carlos

Good news. I found out that one of our customers is doing exactly what you need.

The "trick" he used is adding attribute to variable definition. For example:

char test[6]       __attribute__((aligned(2)));

I did not try it yet.

If someone of CW staff watching this place, please comment. I saw no CW documentation for using attributes in code, only for LCF

I hope it helps

View solution in original post

0 Kudos
5 Replies
1,681 Views
Ben
Senior Contributor I

I think that the ALIGN command will do what you need. See ALIGN and ALIGNALL in the ELF linker file issue.

1,681 Views
cabl
Contributor III

Hi Ben,

thanks for your answer.

However, as far as I know, ALIGN is for the linker file, not for the code (*.c) file. I´m looking for a more flexible way that doesn´t imply changing linker file.

Best regards,

0 Kudos
1,682 Views
Ben
Senior Contributor I

Hi Carlos

Good news. I found out that one of our customers is doing exactly what you need.

The "trick" he used is adding attribute to variable definition. For example:

char test[6]       __attribute__((aligned(2)));

I did not try it yet.

If someone of CW staff watching this place, please comment. I saw no CW documentation for using attributes in code, only for LCF

I hope it helps

0 Kudos
1,681 Views
cabl
Contributor III

Hi Ben,

thank you for the info. I´ve found that from CW10.6 on it´s possible to do __attribute__((aligned(2))), though it seems that __attribute__((aligned(1))) is not working.

Regards

0 Kudos
1,681 Views
Ben
Senior Contributor I

Hi Carios

Thats correct, but you can add once to the linker file a section with ALIGNALL definition, and in the code putting the variables you want to align in this section.

The problem I have with the alignment is that you can not align data to 1 byte long, the minimum is 2 bytes. in data communication I need 1 byte too

0 Kudos