From 71eee45a3779559686c5d07d9864aad679121ab6 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 30 Mar 2021 10:11:12 -0500 Subject: [PATCH] mimxrt1011: UART: Add additional error checking .. and make the 'invalid pin' messages standard. Closes #4502 --- ports/mimxrt10xx/common-hal/busio/UART.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ports/mimxrt10xx/common-hal/busio/UART.c b/ports/mimxrt10xx/common-hal/busio/UART.c index 29f9ea0b27..552844f32b 100644 --- a/ports/mimxrt10xx/common-hal/busio/UART.c +++ b/ports/mimxrt10xx/common-hal/busio/UART.c @@ -153,6 +153,13 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, mp_raise_ValueError(translate("Supply at least one UART pin")); } + if (rx && !self->rx) { + mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_RX); + } + if (tx && !self->tx) { + mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_TX); + } + if (uart_taken) { mp_raise_ValueError(translate("Hardware in use, try alternative pins")); } @@ -188,7 +195,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, } } if (self->rts == NULL) { - mp_raise_ValueError(translate("Selected RTS pin not valid")); + mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_RTS); } } @@ -202,16 +209,19 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, } } if (self->cts == NULL) { - mp_raise_ValueError(translate("Selected CTS pin not valid")); + mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_CTS); } } if (self->rx) { self->uart = mcu_uart_banks[self->rx->bank_idx - 1]; } else { + assert(self->rx); self->uart = mcu_uart_banks[self->tx->bank_idx - 1]; } + assert(self->uart); + if (self->rx) { config_periph_pin(self->rx); }