I am migrating a project from CubeIDE (GCC) to the most comprehensive software development solution for Arm®-based microcontrollers uVision (ARM Compiler 5) and have a difficulty using __align keyword.

CubeIDE code which compiles fine in CubeIDE:

#include <stdalign.h> 
typedef struct {
    volatile alignas(uint32_t) uint16_t imageDark[320]; 
} test_results;

First issue is that uVision cannot locate <stdalign.h> which is part of standard library of the C programming language:

..\Src\device_tests.c(3): error:  #5: cannot open source input file "stdalign.h": No such file or directory

So I removed <stdalign.h> and based on these KEIL documentation rewrote my code to

typedef struct {
         volatile __align(__ALIGNOF__(uint32_t)) uint16_t imageDark[320];
} test_results;

Now I am receiving the following error:

..\Src\device_tests.c(46): error:  #80: a storage class may not be specified here
    volatile __align(__ALIGNOF__(uint32_t)) uint16_t imageDark[320];
..\Src\device_tests.c(46): error:  #328: invalid storage class for a class member
    volatile __align(__ALIGNOF__(uint32_t)) uint16_t imageDark[320];

Any help on how to make alignment work in uVision would be greatly appreciated.

1

There are 1 best solutions below

0
On

I found out that the problem was that I was trying to align inside a struct. The above-mentioned syntax works for variables outside a struct. However to make it work inside struct I used the following syntax:

typedef struct {
     volatile uint16_t imageDark[320] __attribute__((aligned (4)));
} test_results;