Page 1 of 1

Nicer STM32 IO pin config using X macros

Posted: Sun Jan 31, 2016 4:34 pm
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.

Re: Nicer STM32 IO pin config using X macros

Posted: Tue Apr 19, 2016 5:00 am
by DeusExMachina
This looks nice and neat!

Re: Nicer STM32 IO pin config using X macros

Posted: Tue Apr 19, 2016 8:03 am
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