Skip to content

Commit 9b82586

Browse files
arturo182tannewt
andauthored
raspberrypi : Check UART before claiming pins, claim it after
Co-authored-by: Scott Shawcroft <[email protected]>
1 parent 2251d0f commit 9b82586

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,16 +118,16 @@ 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+
if (uart_status[uart_id] != STATUS_FREE) {
122+
mp_raise_RuntimeError(translate("All UART peripherals are in use"));
123+
}
124+
// These may raise exceptions if pins are already in use.
121125
self->tx_pin = pin_init(uart_id, tx, 0);
122126
self->rx_pin = pin_init(uart_id, rx, 1);
123127
self->cts_pin = pin_init(uart_id, cts, 2);
124128
self->rts_pin = pin_init(uart_id, rts, 3);
129+
uart_status[uart_id] = STATUS_BUSY;
125130

126-
if (uart_status[uart_id] != STATUS_FREE) {
127-
mp_raise_RuntimeError(translate("All UART peripherals are in use"));
128-
} else {
129-
uart_status[uart_id] = STATUS_BUSY;
130-
}
131131

132132
self->uart = UART_INST(uart_id);
133133
self->uart_id = uart_id;

0 commit comments

Comments
 (0)