Skip to content

mimxrt1011: UART: Add additional error checking #4513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions ports/mimxrt10xx/common-hal/busio/UART.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
Copy link

@d-c-d d-c-d Mar 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was the assert(self->rx) a known failure, since we just checked self-rx above, so we know it's false
compare that to the self-tx and self->uart usages below

self->uart = mcu_uart_banks[self->tx->bank_idx - 1];
}

assert(self->uart);

if (self->rx) {
config_periph_pin(self->rx);
}
Expand Down