8000 mimxrt1011: UART: Add additional error checking · domdfcoding/circuitpython@71eee45 · GitHub
[go: up one dir, main page]

Skip to content

Commit 71eee45

Browse files
committed
mimxrt1011: UART: Add additional error checking
.. and make the 'invalid pin' messages standard. Closes adafruit#4502
1 parent 2453d70 commit 71eee45

File tree

1 file changed

+12
-2
lines changed
  • ports/mimxrt10xx/common-hal/busio

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
153153
mp_raise_ValueError(translate("Supply at least one UART pin"));
154154
}
155155

156+
if (rx && !self->rx) {
157+
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_RX);
158+
}
159+
if (tx && !self->tx) {
160+
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_TX);
161+
}
162+
156163
if (uart_taken) {
157164
mp_raise_ValueError(translate("Hardware in use, try alternative pins"));
158165
}
@@ -188,7 +195,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
188195
}
189196
}
190197
if (self->rts == NULL) {
191-
mp_raise_ValueError(translate("Selected RTS pin not valid"));
198+
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_RTS);
192199
}
193200
}
194201

@@ -202,16 +209,19 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
202209
}
203210
}
204211
if (self->cts == NULL) {
205-
mp_raise_ValueError(translate("Selected CTS pin not valid"));
212+
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_CTS);
206213
}
207214
}
208215

209216
if (self->rx) {
210217
self->uart = mcu_uart_banks[self->rx->bank_idx - 1];
211218
} else {
219+
assert(self->rx);
212220
self->uart = mcu_uart_banks[self->tx->bank_idx - 1];
213221
}
214222

223+
assert(self->uart);
224+
215225
if (self->rx) {
216226
config_periph_pin(self->rx);
217227
}

0 commit comments

Comments
 (0)
0