HC(S)12 Compiler alignment

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

HC(S)12 Compiler alignment

Jump to solution
1,176 Views
markuskandler
Contributor I

Hello,

I'm developing on the S912ZVML12 using codewarrior. Is there any possibility to force alignment for a variable.

Something linke this:

volatile uint8 SomeArray[6][4] __attribute__((aligned (4)));

With this line of code the Compiler writes:

"volatile uint8 SomeArray[6][4] __attribute__((aligned (4))) => illegal or unsupported __attribute__"

How can the 32bit alignment forced for this Array?

 

Thanks

Labels (1)
0 Kudos
1 Solution
838 Views
stanish
NXP Employee
NXP Employee

Hello Markus,

This feature has been added into the latest relase CodeWarrior for MCU v10.6.

You can download it here:

CW-MCU10: CodeWarrior for MCUs (Eclipse IDE) - ColdFire, 56800/E DSC, Kinetis, Qorivva 56xx, RS08/S0...

Stan

View solution in original post

0 Kudos
5 Replies
839 Views
stanish
NXP Employee
NXP Employee

Hello Markus,

This feature has been added into the latest relase CodeWarrior for MCU v10.6.

You can download it here:

CW-MCU10: CodeWarrior for MCUs (Eclipse IDE) - ColdFire, 56800/E DSC, Kinetis, Qorivva 56xx, RS08/S0...

Stan

0 Kudos
838 Views
cabl
Contributor III

Hello Stanislav,

I´m having alignment problems too and I wonder how can I apply the  __attribute__((aligned())) in my case:

- I have a struct (let´s call it strSType) with several fields with varying sizes (char F1[11], word F2[2], char F3, dword F4...)

- I read a byte array from memory (let´s say flash) and I want to cast this array so that I can access it by field:

byte by[512];

strSType *pstr;

ReadFromFlash(by,512);

pstr=(strSType *)by;

.... And the use

pstr->F1[]...

pstr->F4...

Any suggestion?

Thanks in advance

0 Kudos
838 Views
stanish
NXP Employee
NXP Employee

Hello Carlos,

If your strSType struct located in flash is initialized by the code in your project e.g.:

const strSType  struct_in_Flash = { "hello", {0,1},'1',0x1234....}

then you don't have to consider any padding bytes/alignments within the structure.

But you should  possibly consider alignment of byte array by[512]  if you require better speed performance.

What kind of problem do you observe? Can you please describe it more in the detail?

Regards,

Stan

0 Kudos
838 Views
cabl
Contributor III

Hello Stan,

thanks for the answer.

I´m trying to read data from an external flash memory and process it (for example, reading the master boot record of a FAT filesystem). As I read an array of bytes (let´s call it byArr[512]) without padding bytes but my structure has padding bytes I cannot simply cast the byte array to my struct and expect that each field is located where it should.

For example, I read the 512 bytes of the master boot record of the FAT, and try to cast this byte array to the structure:

typedef struct _MasterBoot_Entries

{

  UINT8   ExcecutableCode[446];

  Partition_Entries Partitions[4];

  UINT16  MBRSignature;

}MasterBoot_Entries;

It happens that ((MasterBoot_Entries *)byArr)->MBRSignature does not match the real value, which is *((UINT16 *)&byArr[510]).

It happens the same with all the fields in each ((MasterBoot_Entries *)byArr)->Partitions[x], as ((MasterBoot_Entries *)byArr)->Partitions is dword aligned, with padding byte before it

Am I missing something?

Regards

0 Kudos
838 Views
Wlodek_D_
Senior Contributor II

Hello,

Thank you for your post, however please consider moving it to the right community place (e.g. CodeWarrior Development Tools or 16-bit Microcontrollers ) to get it visible for active members.

For details please see general advice Where to post a Discussion? (https://community.freescale.com/docs/DOC-99909 )

Thank you for using Freescale Community.

0 Kudos