Documentation/coding style suggestion....

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Documentation/coding style suggestion....

Post by rew »

On http://chibios.org/dokuwiki/doku.php?id ... _dma_guide I see:

Code: Select all

#if defined(__GNUC__)
__attribute__((aligned (32)))
#endif
static uint8_t txbuf[SPI_BUFFERS_SIZE];

Might I suggest to write such things as:

Code: Select all

ALIGNED32 static uint8_t txbuf[SPI_BUFFERS_SIZE];

and have

Code: Select all

#if defined(__GNUC__)
#define ALIGNED32 __attribute__((aligned (32)))
#else
// Auch! Data that needs 32-byte alignment will not be aligned!
#warning "don't know how to align data to 32 bytes!"
#define ALIGNED32
#endif
somewhere else?

Why? First it deals with the compiler issue in one place. Adding a different compiler is easier when this is concentrated somewhere. Second it makes the code shorter and more readable. The code now clearly shows that the buffer needs 32-byte alignment, even if there is no way to indicate this to the compiler.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Documentation/coding style suggestion....

Post by Giovanni »

Probably the HAL should include a compiler-related abstraction module in order to implement that.

The problem are the dumb proprietary compilers that do not necessarily allow alignments, or implement them in a way that is not placeable in a macro like that.

Giovanni
Post Reply