From 2c9a4d215c9e261567bb9c103f71b9b5133bfb6e Mon Sep 17 00:00:00 2001 From: PerennialNovice <85557472+PerennialNovice@users.noreply.github.com> Date: Thu, 4 Apr 2024 11:21:17 +0200 Subject: [PATCH] add support for STM32 native HalfDuplex mode To be able to use the STM32 HalfDuplex mode, Rx has to be activated after each write. The HardwareSerial has to be intantiated as HalfDuplex by providing only one Pin to the constructor; i.e.: HardwareSerial Serial5(PA_0); Signed-off-by: PerennialNovice --- src/utility/port_handler.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/utility/port_handler.cpp b/src/utility/port_handler.cpp index 690395c..f147b08 100644 --- a/src/utility/port_handler.cpp +++ b/src/utility/port_handler.cpp @@ -58,6 +58,11 @@ void SerialPortHandler::begin(unsigned long baud) digitalWrite(dir_pin_, LOW); while(digitalRead(dir_pin_) != LOW); } +#ifdef ARDUINO_ARCH_STM32 + else{ + port_.enableHalfDuplexRx(); + } +#endif // ARDUINO_ARCH_STM32 setOpenState(true); } @@ -98,6 +103,11 @@ size_t SerialPortHandler::write(uint8_t c) digitalWrite(dir_pin_, LOW); while(digitalRead(dir_pin_) != LOW); } +#ifdef ARDUINO_ARCH_STM32 + else{ + port_.enableHalfDuplexRx(); + } +#endif // ARDUINO_ARCH_STM32 return ret; } @@ -120,6 +130,11 @@ size_t SerialPortHandler::write(uint8_t *buf, size_t len) digitalWrite(dir_pin_, LOW); while(digitalRead(dir_pin_) != LOW); } +#ifdef ARDUINO_ARCH_STM32 + else{ + port_.enableHalfDuplexRx(); + } +#endif // ARDUINO_ARCH_STM32 return ret; }