Skip to content

Commit 1130198

Browse files
Enable add'l UART_AUX pinouts for RP2350
Fixes #2835. Thanks @deltaford!
1 parent 46a58fb commit 1130198

File tree

1 file changed

+52
-8
lines changed

1 file changed

+52
-8
lines changed

cores/rp2040/SerialUART.cpp

+52-8
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,20 @@ extern void serialEvent1() __attribute__((weak));
3232
extern void serialEvent2() __attribute__((weak));
3333

3434
bool SerialUART::setRX(pin_size_t pin) {
35-
#ifdef PICO_RP2350B
36-
constexpr uint64_t valid[2] = { __bitset({1, 13, 17, 29, 33, 45}) /* UART0 */,
37-
__bitset({5, 9, 21, 25, 37, 41}) /* UART1 */
35+
#if defined(PICO_RP2350B)
36+
constexpr uint64_t valid[2] = { __bitset({1, 3, 13, 15, 17, 19, 29, 31, 33, 35, 45, 47}) /* UART0 */,
37+
__bitset({5, 7, 9, 11, 21, 23, 25, 27, 37, 39, 41, 43}) /* UART1 */
38+
};
39+
#elif defined(PICO_RP2350)
40+
constexpr uint64_t valid[2] = { __bitset({1, 3, 13, 15, 17, 19, 29}) /* UART0 */,
41+
__bitset({5, 7, 9, 11, 21, 23, 25, 27}) /* UART1 */
3842
};
3943
#else
4044
constexpr uint64_t valid[2] = { __bitset({1, 13, 17, 29}) /* UART0 */,
4145
__bitset({5, 9, 21, 25}) /* UART1 */
4246
};
4347
#endif
48+
4449
if ((!_running) && ((1LL << pin) & valid[uart_get_index(_uart)])) {
4550
_rx = pin;
4651
return true;
@@ -59,9 +64,13 @@ bool SerialUART::setRX(pin_size_t pin) {
5964
}
6065

6166
bool SerialUART::setTX(pin_size_t pin) {
62-
#ifdef PICO_RP2350B
63-
constexpr uint64_t valid[2] = { __bitset({0, 12, 16, 28, 32, 44}) /* UART0 */,
64-
__bitset({4, 8, 20, 24, 36, 40}) /* UART1 */
67+
#if defined(PICO_RP2350B)
68+
constexpr uint64_t valid[2] = { __bitset({0, 2, 12, 14, 16, 18, 28, 30, 32, 34, 44, 46}) /* UART0 */,
69+
__bitset({4, 6, 8, 10, 20, 22, 24, 26, 36, 38, 40, 42}) /* UART1 */
70+
};
71+
#elif defined(PICO_RP2350)
72+
constexpr uint64_t valid[2] = { __bitset({0, 2, 12, 14, 16, 18, 28}) /* UART0 */,
73+
__bitset({4, 6, 8, 10, 20, 22, 24, 26}) /* UART1 */
6574
};
6675
#else
6776
constexpr uint64_t valid[2] = { __bitset({0, 12, 16, 28}) /* UART0 */,
@@ -170,6 +179,41 @@ SerialUART::SerialUART(uart_inst_t *uart, pin_size_t tx, pin_size_t rx, pin_size
170179
static void _uart0IRQ();
171180
static void _uart1IRQ();
172181

182+
// Does the selected TX/RX need UART_AUX function (rp2350)
183+
static gpio_function_t __gpioFunction(int pin) {
184+
switch (pin) {
185+
#if defined(PICO_RP2350) || defined(PICO_RP2350B)
186+
case 2:
187+
case 3:
188+
case 6:
189+
case 7:
190+
case 10:
191+
case 11:
192+
case 14:
193+
case 15:
194+
case 18:
195+
case 19:
196+
case 22:
197+
case 23:
198+
case 26:
199+
case 27:
200+
case 30:
201+
case 31:
202+
case 34:
203+
case 35:
204+
case 38:
205+
case 39:
206+
case 42:
207+
case 43:
208+
case 46:
209+
case 47:
210+
return GPIO_FUNC_UART_AUX;
211+
#endif
212+
default:
213+
return GPIO_FUNC_UART;
214+
}
215+
}
216+
173217
void SerialUART::begin(unsigned long baud, uint16_t config) {
174218
if (_running) {
175219
end();
@@ -180,9 +224,9 @@ void SerialUART::begin(unsigned long baud, uint16_t config) {
180224

181225
_fcnTx = gpio_get_function(_tx);
182226
_fcnRx = gpio_get_function(_rx);
183-
gpio_set_function(_tx, GPIO_FUNC_UART);
227+
gpio_set_function(_tx, __gpioFunction(_tx));
184228
gpio_set_outover(_tx, _invertTX ? 1 : 0);
185-
gpio_set_function(_rx, GPIO_FUNC_UART);
229+
gpio_set_function(_rx, __gpioFunction(_rx));
186230
gpio_set_inover(_rx, _invertRX ? 1 : 0);
187231
if (_rts != UART_PIN_NOT_DEFINED) {
188232
_fcnRts = gpio_get_function(_rts);

0 commit comments

Comments
 (0)