Nicer STM32 IO pin config using X macros

This forum is about you. Feel free to discuss anything is related to embedded and electronics, your awesome projects, your ideas, your announcements, not necessarily related to ChibiOS but to embedded in general. This forum is NOT for support.
Post Reply
jpa
Posts: 6
Joined: Mon May 14, 2012 3:13 pm
Been thanked: 2 times

Nicer STM32 IO pin config using X macros

Post by jpa »

Hi,

I made a few extra macros in my board.h which in my opinion make it easier to configure IO pins.
Example of pin configuration:

Code: Select all

#define GPIOA_PINS(X) \
X(GPIOA,  0, SENS3       , ANALOG     , LOW , PUSHPULL ,  50M , FLOATING ,  0) \
X(GPIOA,  1, SENS2       , ANALOG     , LOW , PUSHPULL ,  50M , FLOATING ,  0) \
X(GPIOA,  2, SENS1       , ANALOG     , LOW , PUSHPULL ,  50M , FLOATING ,  0) \
X(GPIOA,  3, ADC_TEMP    , ANALOG     , LOW , PUSHPULL ,  50M , FLOATING ,  0) \
X(GPIOA,  4, SPI1_CS     , OUTPUT     , HIGH, PUSHPULL ,  50M , PULLUP   ,  0) \
X(GPIOA,  5, SPI1_SCK    , ALTERNATE  , LOW , PUSHPULL ,  50M , PULLUP   ,  5) \
X(GPIOA,  6, SPI1_MISO   , ALTERNATE  , LOW , PUSHPULL ,  50M , PULLUP   ,  5) \
...


This way all the information about each pin is on a single row. It also automatically defines names like GPIOA_SPI1_CS for use in palWritePad().

Full code is available here:
https://github.com/PetteriAimonen/ebike ... rc/board.h
If someone finds this useful, feel free to copy the macros.
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: Nicer STM32 IO pin config using X macros

Post by DeusExMachina »

This looks nice and neat!
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Nicer STM32 IO pin config using X macros

Post by Giovanni »

Nice, that would require non trivial changes in the board files generator but after that all board files would be updated automatically.

BTW, I did read this post but I was on my way home then I forgot to answer...

Giovanni
Post Reply