Skip to content

Commit b400897

Browse files
Avoid initial glitch on Serial1/2 when RX high (#1154)
Fixes #1153 Set up the GPIO redirects before the UART is pulled from reset to avoid a possible bad byte at `Serial1/2.begin()`.
1 parent 7573500 commit b400897

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

cores/rp2040/SerialUART.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@ void SerialUART::begin(unsigned long baud, uint16_t config) {
134134
_overflow = false;
135135
_queue = new uint8_t[_fifoSize];
136136
_baud = baud;
137+
138+
_fcnTx = gpio_get_function(_tx);
139+
_fcnRx = gpio_get_function(_rx);
140+
gpio_set_function(_tx, GPIO_FUNC_UART);
141+
gpio_set_function(_rx, GPIO_FUNC_UART);
142+
if (_rts != UART_PIN_NOT_DEFINED) {
143+
_fcnRts = gpio_get_function(_rts);
144+
gpio_set_function(_rts, GPIO_FUNC_UART);
145+
}
146+
if (_cts != UART_PIN_NOT_DEFINED) {
147+
_fcnCts = gpio_get_function(_cts);
148+
gpio_set_function(_cts, GPIO_FUNC_UART);
149+
}
150+
137151
uart_init(_uart, baud);
138152
int bits, stop;
139153
uart_parity_t parity;
@@ -171,18 +185,6 @@ void SerialUART::begin(unsigned long baud, uint16_t config) {
171185
break;
172186
}
173187
uart_set_format(_uart, bits, stop, parity);
174-
_fcnTx = gpio_get_function(_tx);
175-
_fcnRx = gpio_get_function(_rx);
176-
gpio_set_function(_tx, GPIO_FUNC_UART);
177-
gpio_set_function(_rx, GPIO_FUNC_UART);
178-
if (_rts != UART_PIN_NOT_DEFINED) {
179-
_fcnRts = gpio_get_function(_rts);
180-
gpio_set_function(_rts, GPIO_FUNC_UART);
181-
}
182-
if (_cts != UART_PIN_NOT_DEFINED) {
183-
_fcnCts = gpio_get_function(_cts);
184-
gpio_set_function(_cts, GPIO_FUNC_UART);
185-
}
186188
uart_set_hw_flow(_uart, _rts != UART_PIN_NOT_DEFINED, _cts != UART_PIN_NOT_DEFINED);
187189
_writer = 0;
188190
_reader = 0;

0 commit comments

Comments
 (0)