raspberrypi : Check UART before claiming pins, claim it after

Co-authored-by: Scott Shawcroft <scott@adafruit.com>
This commit is contained in:
arturo182 2022-01-11 22:02:47 +01:00 committed by GitHub
parent 2251d0f4b0
commit 9b825869c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -118,16 +118,16 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
uint8_t uart_id = ((((tx != NULL) ? tx->number : rx->number) + 4) / 8) % NUM_UARTS;
if (uart_status[uart_id] != STATUS_FREE) {
mp_raise_RuntimeError(translate("All UART peripherals are in use"));
}
// These may raise exceptions if pins are already in use.
self->tx_pin = pin_init(uart_id, tx, 0);
self->rx_pin = pin_init(uart_id, rx, 1);
self->cts_pin = pin_init(uart_id, cts, 2);
self->rts_pin = pin_init(uart_id, rts, 3);
uart_status[uart_id] = STATUS_BUSY;
if (uart_status[uart_id] != STATUS_FREE) {
mp_raise_RuntimeError(translate("All UART peripherals are in use"));
} else {
uart_status[uart_id] = STATUS_BUSY;
}
self->uart = UART_INST(uart_id);
self->uart_id = uart_id;