From ebc3f8f5c46e8df243671b28cf92b0063c3ccd61 Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Sat, 22 Mar 2025 12:43:02 +0100 Subject: [PATCH] boards/nucleo-f302r8: add rs485 support add rs485 support for nucleo-f302r8 based on RS485 CAN Waveshare shield. Signed-off-by: raiden00pl --- boards/arm/stm32/nucleo-f302r8/Kconfig | 4 +++ .../arm/stm32/nucleo-f302r8/include/board.h | 27 ++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/boards/arm/stm32/nucleo-f302r8/Kconfig b/boards/arm/stm32/nucleo-f302r8/Kconfig index 2679993956c4c..01a67d113d201 100644 --- a/boards/arm/stm32/nucleo-f302r8/Kconfig +++ b/boards/arm/stm32/nucleo-f302r8/Kconfig @@ -9,6 +9,10 @@ config NUCLEOF302R8_HIGHPRI bool "High priority interrupt test" default n +config NUCLEOF302R8_RS485_WAVESHARE + bool "Map USART1 pins to match RS485 CAN Waveshare shield" + default n + if SENSORS_QENCODER config NUCLEO_F302R8_QETIMER diff --git a/boards/arm/stm32/nucleo-f302r8/include/board.h b/boards/arm/stm32/nucleo-f302r8/include/board.h index 2d020fb0db5c9..9c87ed3d0acb9 100644 --- a/boards/arm/stm32/nucleo-f302r8/include/board.h +++ b/boards/arm/stm32/nucleo-f302r8/include/board.h @@ -206,10 +206,31 @@ #define GPIO_USART2_RX GPIO_USART2_RX_2 /* PA3 */ #define GPIO_USART2_TX GPIO_USART2_TX_2 /* PA2 */ -/* USART1 */ +/* USART1 + * + * At default use: + * USART1_RX - PB7 + * USART1_TX - PB6 + * + * If CONFIG_NUCLEOF302R8_RS485_WAVESHARE=y use configuration to match RS485 + * shield from Waveshare: + * + * USART1_RX - PA10 + * USART1_TX - PA9 + * RS485_DIR - PA8 (arduino D7) + * + */ -#define GPIO_USART1_RX GPIO_USART1_RX_2 /* PB7 */ -#define GPIO_USART1_TX GPIO_USART1_TX_2 /* PB6 */ +#ifdef CONFIG_NUCLEOF302R8_RS485_WAVESHARE +# define GPIO_USART1_RX GPIO_USART1_RX_1 /* PA10 */ +# define GPIO_USART1_TX GPIO_USART1_TX_1 /* PA9 */ +# define GPIO_USART1_RS485_DIR (GPIO_OUTPUT | GPIO_PUSHPULL | \ + GPIO_SPEED_50MHz | GPIO_OUTPUT_CLEAR | \ + GPIO_PORTA | GPIO_PIN8) +#else +# define GPIO_USART1_RX GPIO_USART1_RX_2 /* PB7 */ +# define GPIO_USART1_TX GPIO_USART1_TX_2 /* PB6 */ +#endif /* CAN */