From 7cf77876c8c338e33ef5765aaf93977040e6ebe7 Mon Sep 17 00:00:00 2001 From: Nat Gist Date: Sun, 26 Oct 2025 23:10:27 -0400 Subject: [PATCH 1/4] Return acheived baud rate from begin function --- cores/rp2040/SerialUART.cpp | 3 ++- cores/rp2040/SerialUART.h | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cores/rp2040/SerialUART.cpp b/cores/rp2040/SerialUART.cpp index b755b463c..aa15241c8 100644 --- a/cores/rp2040/SerialUART.cpp +++ b/cores/rp2040/SerialUART.cpp @@ -239,7 +239,7 @@ void SerialUART::begin(unsigned long baud, uint16_t config) { gpio_set_inover(_cts, _invertControl ? 1 : 0); } - uart_init(_uart, baud); + int achieved_baud = uart_init(_uart, baud); int bits, stop; uart_parity_t parity; switch (config & SERIAL_PARITY_MASK) { @@ -295,6 +295,7 @@ void SerialUART::begin(unsigned long baud, uint16_t config) { } _break = false; _running = true; + return achieved_baud; } void SerialUART::end() { diff --git a/cores/rp2040/SerialUART.h b/cores/rp2040/SerialUART.h index 5de17dfe9..41ae19774 100644 --- a/cores/rp2040/SerialUART.h +++ b/cores/rp2040/SerialUART.h @@ -64,10 +64,10 @@ class SerialUART : public arduino::HardwareSerial { bool setFIFOSize(size_t size); bool setPollingMode(bool mode = true); - void begin(unsigned long baud = 115200) override { - begin(baud, SERIAL_8N1); + int begin(unsigned long baud = 115200) override { + return begin(baud, SERIAL_8N1); }; - void begin(unsigned long baud, uint16_t config) override; + int begin(unsigned long baud, uint16_t config) override; void end() override; virtual int peek() override; From 6f7e6193645236aa3cc6174d6b75e1cf99c7dace Mon Sep 17 00:00:00 2001 From: Nat Gist Date: Mon, 27 Oct 2025 12:55:46 -0400 Subject: [PATCH 2/4] avoid altering virtual function spec --- cores/rp2040/SerialUART.cpp | 3 +-- cores/rp2040/SerialUART.h | 10 ++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cores/rp2040/SerialUART.cpp b/cores/rp2040/SerialUART.cpp index aa15241c8..28e803fa5 100644 --- a/cores/rp2040/SerialUART.cpp +++ b/cores/rp2040/SerialUART.cpp @@ -239,7 +239,7 @@ void SerialUART::begin(unsigned long baud, uint16_t config) { gpio_set_inover(_cts, _invertControl ? 1 : 0); } - int achieved_baud = uart_init(_uart, baud); + _achievedBaud = uart_init(_uart, baud); int bits, stop; uart_parity_t parity; switch (config & SERIAL_PARITY_MASK) { @@ -295,7 +295,6 @@ void SerialUART::begin(unsigned long baud, uint16_t config) { } _break = false; _running = true; - return achieved_baud; } void SerialUART::end() { diff --git a/cores/rp2040/SerialUART.h b/cores/rp2040/SerialUART.h index 41ae19774..eaa47712f 100644 --- a/cores/rp2040/SerialUART.h +++ b/cores/rp2040/SerialUART.h @@ -64,10 +64,10 @@ class SerialUART : public arduino::HardwareSerial { bool setFIFOSize(size_t size); bool setPollingMode(bool mode = true); - int begin(unsigned long baud = 115200) override { + void begin(unsigned long baud = 115200) override { return begin(baud, SERIAL_8N1); }; - int begin(unsigned long baud, uint16_t config) override; + void begin(unsigned long baud, uint16_t config) override; void end() override; virtual int peek() override; @@ -93,6 +93,11 @@ class SerialUART : public arduino::HardwareSerial { // on read) bool getBreakReceived(); + // Returns the baud rate the uart is actually operating at vs the desired baud rate specified to begin() + int getAcheivedBaud() { + return _achievedBaud; + } + private: bool _running = false; uart_inst_t *_uart; @@ -100,6 +105,7 @@ class SerialUART : public arduino::HardwareSerial { pin_size_t _rts, _cts; gpio_function_t _fcnTx, _fcnRx, _fcnRts, _fcnCts; int _baud; + int _achievedBaud; mutex_t _mutex; bool _polling = false; bool _overflow; From e706d389e85a8b269e0602b9c3d8ea65d2148801 Mon Sep 17 00:00:00 2001 From: Nat Gist Date: Mon, 27 Oct 2025 16:58:47 -0400 Subject: [PATCH 3/4] removed dangling return --- cores/rp2040/SerialUART.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/rp2040/SerialUART.h b/cores/rp2040/SerialUART.h index eaa47712f..65851aa17 100644 --- a/cores/rp2040/SerialUART.h +++ b/cores/rp2040/SerialUART.h @@ -65,7 +65,7 @@ class SerialUART : public arduino::HardwareSerial { bool setPollingMode(bool mode = true); void begin(unsigned long baud = 115200) override { - return begin(baud, SERIAL_8N1); + begin(baud, SERIAL_8N1); }; void begin(unsigned long baud, uint16_t config) override; void end() override; From 3740aa41f38bc4d5ff091313d4d2deea17568616 Mon Sep 17 00:00:00 2001 From: Nat Gist Date: Mon, 27 Oct 2025 17:20:20 -0400 Subject: [PATCH 4/4] updated per comments --- cores/rp2040/SerialUART.cpp | 2 +- cores/rp2040/SerialUART.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cores/rp2040/SerialUART.cpp b/cores/rp2040/SerialUART.cpp index 28e803fa5..363b9c0e8 100644 --- a/cores/rp2040/SerialUART.cpp +++ b/cores/rp2040/SerialUART.cpp @@ -239,7 +239,7 @@ void SerialUART::begin(unsigned long baud, uint16_t config) { gpio_set_inover(_cts, _invertControl ? 1 : 0); } - _achievedBaud = uart_init(_uart, baud); + _actualBaud = uart_init(_uart, baud); int bits, stop; uart_parity_t parity; switch (config & SERIAL_PARITY_MASK) { diff --git a/cores/rp2040/SerialUART.h b/cores/rp2040/SerialUART.h index 65851aa17..0807b48ea 100644 --- a/cores/rp2040/SerialUART.h +++ b/cores/rp2040/SerialUART.h @@ -94,8 +94,8 @@ class SerialUART : public arduino::HardwareSerial { bool getBreakReceived(); // Returns the baud rate the uart is actually operating at vs the desired baud rate specified to begin() - int getAcheivedBaud() { - return _achievedBaud; + int getActualBaud() { + return _running ? _actualBaud : 0; } private: @@ -105,7 +105,7 @@ class SerialUART : public arduino::HardwareSerial { pin_size_t _rts, _cts; gpio_function_t _fcnTx, _fcnRx, _fcnRts, _fcnCts; int _baud; - int _achievedBaud; + int _actualBaud; mutex_t _mutex; bool _polling = false; bool _overflow;