2025-09-14 6:32 AM
Hi,
I have a struct that looks like the following:
typedef struct {
uint8_t statusbyte;
uint8_t dmaBuffer[32];
} STRUCT_ReceptionBuffer;
The RM0091 instructs that source and destination addresses should be aligned on the data size. What I want to transfer to the buffer are 32-bit words (it is an I2S-to-USB-Audio conversion, and USB deals with bytes).
This means I need to align the struct. I am using the GCC compiler tools but the F0 HAL library also defines the __ALIGN_BEGIN and __ALIGN_END macros.
My question is, how and where should I place these macros in order for them to have the desired effect?
Does this look correct?
typedef __ALIGN_BEGIN struct {
uint8_t statusByte;
__ALIGN_BEGIN uint8_t dmaBuffer[32] __ALIGN_END;
} STRUCT_ReceptionBuffer __ALIGN_END;
Or would this be more correct?
typedef struct __ALIGN_BEGIN {
uint8_t statusByte;
__ALIGN_BEGIN uint8_t __ALIGN_END dmaBuffer[32];
} __ALIGN_END STRUCT_ReceptionBuffer ;
The complier does not seem to care much what I do. Even the following blatantly-wrong looking definition is completely fine?
typedef struct {
uint8_t statusByte; __ALIGN_END
uint8_t __ALIGN_END dmaBuffer[32];
} __ALIGN_END STRUCT_ReceptionBuffer;
Is this just a matter of trial and error? Or is it so that the compiler really doesn't care, and any errors caused by this only pop up during runtime?
Solved! Go to Solution.
2025-09-16 4:08 PM
@ankes Placement of __attribute__ sometimes is quirky. Newer gcc versions (and clang) warn about possibly wrong placement of __attribute__ , so keep an eye on compiler warnings.