From ced27ee59cc30af02bb02a9b21a5a69b5987c0d4 Mon Sep 17 00:00:00 2001 From: Giampaolo Mancini Date: Tue, 10 Jan 2023 14:34:24 +0100 Subject: [PATCH 1/2] Add support for RX pull-up management --- cores/arduino/Serial.cpp | 9 +++++++++ cores/arduino/Serial.h | 1 + variants/OPTA/pins_arduino.h | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/cores/arduino/Serial.cpp b/cores/arduino/Serial.cpp index 325f8fd34..c5808622f 100644 --- a/cores/arduino/Serial.cpp +++ b/cores/arduino/Serial.cpp @@ -126,6 +126,15 @@ void UART::begin(unsigned long baudrate) { } } +void UART::begin(unsigned long baudrate, uint16_t config, bool no_rx_pullup) { + begin(baudrate, config); +#if defined(SET_GPIO_PULL_FUNCTION) + if (no_rx_pullup) { + SET_GPIO_PULL_FUNCTION(_rx, NO_PULL); + } +#endif +} + void UART::on_rx() { #if defined(SERIAL_CDC) if (is_usb) { diff --git a/cores/arduino/Serial.h b/cores/arduino/Serial.h index f20e14060..f511256ad 100644 --- a/cores/arduino/Serial.h +++ b/cores/arduino/Serial.h @@ -45,6 +45,7 @@ class UART : public HardwareSerial { } void begin(unsigned long); void begin(unsigned long baudrate, uint16_t config); + void begin(unsigned long baudrate, uint16_t config, bool no_rx_pullup); void end(); int available(void); int peek(void); diff --git a/variants/OPTA/pins_arduino.h b/variants/OPTA/pins_arduino.h index 698a1ecef..aed78568a 100644 --- a/variants/OPTA/pins_arduino.h +++ b/variants/OPTA/pins_arduino.h @@ -193,4 +193,22 @@ void _ontouch1200bps_(); #define USB_MAX_POWER (500) +static GPIO_TypeDef * const GPIO_PORT[] = { + GPIOA, + GPIOB, + GPIOC, + GPIOD, + GPIOE, + GPIOF, + GPIOG, + GPIOH, + GPIOI, + GPIOJ, + GPIOK, +}; + +#include "pin_device.h" +#define SET_GPIO_PULL_FUNCTION(x, y) LL_GPIO_SetPinPull(GPIO_PORT[STM_PORT(x)], ll_pin_defines[STM_PIN(x)], y) +#define NO_PULL LL_GPIO_PULL_NO + #endif //__PINS_ARDUINO__ From 831b2529901ca1a5e9e3b5683d8ab8ea1a1b0f01 Mon Sep 17 00:00:00 2001 From: Giampaolo Mancini Date: Tue, 10 Jan 2023 15:17:56 +0100 Subject: [PATCH 2/2] Define separate PIN for RS485_RE --- variants/OPTA/pins_arduino.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/OPTA/pins_arduino.h b/variants/OPTA/pins_arduino.h index aed78568a..6812a8f56 100644 --- a/variants/OPTA/pins_arduino.h +++ b/variants/OPTA/pins_arduino.h @@ -182,7 +182,7 @@ void _ontouch1200bps_(); #define RS485_DEFAULT_TX_PIN SERIAL2_TX #define RS485_DEFAULT_DE_PIN PB_14 -#define RS485_DEFAULT_RE_PIN RS485_DEFAULT_DE_PIN +#define RS485_DEFAULT_RE_PIN PB_13 #define SerialLoRa Serial3 #define LORA_BOOT0 (PG_7)