Skip to content

Commit 2251d0f

Browse files
authored
raspberrypi: Claim UART after checking pins
If, for some reason, you mix up TX and RX when calling `busio.UART` (who would do that ;) ), you get `Invalid pins`. When you go to try again, you'll get `All UART peripherals are in use` because the interface was claimed as busy before pins are verified. This should fix that issue.
1 parent d23d2e7 commit 2251d0f

File tree

1 file changed

+5
-5
lines changed
  • ports/raspberrypi/common-hal/busio

1 file changed

+5
-5
lines changed

ports/raspberrypi/common-hal/busio/UART.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
118118

119119
uint8_t uart_id = ((((tx != NULL) ? tx->number : rx->number) + 4) / 8) % NUM_UARTS;
120120

121+
self->tx_pin = pin_init(uart_id, tx, 0);
122+
self->rx_pin = pin_init(uart_id, rx, 1);
123+
self->cts_pin = pin_init(uart_id, cts, 2);
124+
self->rts_pin = pin_init(uart_id, rts, 3);
125+
121126
if (uart_status[uart_id] != STATUS_FREE) {
122127
mp_raise_RuntimeError(translate("All UART peripherals are in use"));
123128
} else {
124129
uart_status[uart_id] = STATUS_BUSY;
125130
}
126131

127-
self->tx_pin = pin_init(uart_id, tx, 0);
128-
self->rx_pin = pin_init(uart_id, rx, 1);
129-
self->cts_pin = pin_init(uart_id, cts, 2);
130-
self->rts_pin = pin_init(uart_id, rts, 3);
131-
132132
self->uart = UART_INST(uart_id);
133133
self->uart_id = uart_id;
134134
self->baudrate = baudrate;

0 commit comments

Comments
 (0)