I use my code on several different HW platforms though at this moment ony with STM32F4 cpu. But this is not something that is much specific to any particular cpu.
I had the issue when moving a few leds of my bootloader when I had to implement it on a different HW, the way board.h and pal.h is done the code is not portable even though the board.h configuration has been changed. I bet I am not the only one affected by this.
here is what I have done, and suggest for the future, it may not be the best solution, but it's work and is pretty clean.....
in the board.h I have added som port config lines like this:
Code: Select all
/*
* IO pins assignments.
*/
#define GPIO0 0
#define GPIO1 1
#define GPIO2 2
#define GPIO3 3
#define GPIO4 4
#define GPIO5 5
#define GPIO6 6
#define GPIO7 7
#define GPIO8 8
#define GPIO9 9
#define GPIO10 10
#define GPIO11 11
#define GPIO12 12
#define GPIO13 13
#define GPIO14 14
#define GPIO15 15
.
.
Code: Select all
#define GPIO_input_0 ( ( (uint64_t) GPIOA << 4) + GPIO0 )
#define GPIO_PWR_OUT ( ( (uint64_t) GPIOA << 4) + GPIO1 )
#define GPIO_Output_0 ( ( (uint64_t) GPIOA << 4) + GPIO2 )
#define GPIO_A_PIN3 ( ( (uint64_t) GPIOA << 4) + GPIO3 )
#define GPIO_DAC_1 ( ( (uint64_t) GPIOA << 4) + GPIO4 )
#define GPIO_SPI1_SCK ( ( (uint64_t) GPIOA << 4) + GPIO5 )
#define GPIO_SPI1_MISO ( ( (uint64_t) GPIOA << 4) + GPIO6 )
.
.
[i]and so forth for the rest of the GPIO's[/i]
.
.
the objective here is to have a single name for the signals attached to the GPIO's, which does not include any information in the name itself, and yest still carry both PIN_numnber and PORT_informatino in the value.
in the file pal.h I hav added a few macros to use instead of the original ones which just splits the above defines into the norman port, pad information.
Code: Select all
[b]#define palWritePP(portpad) palWritePad((GPIO_TypeDef *)((uint64_t) portpad >> 4),((uint64_t) portpad & 0x0F), bit)[/b]
#if !defined(pal_lld_writepad) || defined(__DOXYGEN__)
#define palWritePad(port, pad, bit) \
palWritePort(port, (palReadLatch(port) & ~PAL_PORT_BIT(pad)) | \
(((bit) & 1) << pad))
#else
#define palWritePad(port, pad, bit) pal_lld_writepad(port, pad, bit)
#endif
[b]#define palSetPadPP(portpad) palSetPad((GPIO_TypeDef *)((uint64_t) portpad >> 4),((uint64_t) portpad & 0x0F))
#define palClearPadPP(portpad) palClearPad((GPIO_TypeDef *)((uint64_t) portpad >> 4),((uint64_t) portpad & 0x0F))
#define palTogglePadPP(portpad) palTogglePad((GPIO_TypeDef *)((uint64_t) portpad >> 4),((uint64_t) portpad & 0x0F))
#define palSetPadModePP(portpad) palSetPadMode((GPIO_TypeDef *)((uint64_t) portpad >> 4),((uint64_t) portpad & 0x0F), mode)[/b]
and so instead of writing the code like this:
Code: Select all
palClearPad(GPIOB, GPIOB_LED_RX_YELLOW);
I write :
Code: Select all
palClearPadPP(GPIO_LED_RX_YELLOW);
and the code is portable without any changes, all changes now lie in board.h
first I hope this is usefull to someone else, and second I hope this (or similar) will come into the ChibiOS code.
enjoy
Svend Stave