diff options
| author | robert-hh <robert@hammelrath.com> | 2023-08-31 08:02:32 +0200 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-09-01 00:41:23 +1000 |
| commit | 81c19d93bc687e2bd953af16c9d779a97e822e5f (patch) | |
| tree | 21d8bc38553747dda9f82de3f32b873abf696442 | |
| parent | c86b9ec8bd11dbd665e2af29f2e8b6b6f1ce449a (diff) | |
mimxrt/machine_uart: Support slow baud rates for UART.
Down to 50 baud (in reverence to Jean-Maurice-Émile Baudot). Implemented
for the MIMXRT10xx MCU's only. The MIMXRT1176 runs down to 300 baud.
Signed-off-by: robert-hh <robert@hammelrath.com>
| -rw-r--r-- | ports/mimxrt/machine_uart.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/ports/mimxrt/machine_uart.c b/ports/mimxrt/machine_uart.c index 02e00c899..ab5d13e08 100644 --- a/ports/mimxrt/machine_uart.c +++ b/ports/mimxrt/machine_uart.c @@ -288,7 +288,18 @@ STATIC mp_obj_t machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args self->timeout_char = min_timeout_char; } - LPUART_Init(self->lpuart, &self->config, BOARD_BOOTCLOCKRUN_UART_CLK_ROOT); + #if defined(MIMXRT117x_SERIES) + // Use the Lpuart1 clock value, which is set for All UART devices. + LPUART_Init(self->lpuart, &self->config, CLOCK_GetRootClockFreq(kCLOCK_Root_Lpuart1)); + #else + // For baud rates < 1000000 divide the clock by 10, supporting baud rates down to 50 baud. + if (self->config.baudRate_Bps > 1000000) { + CLOCK_SetDiv(kCLOCK_UartDiv, 0); + } else { + CLOCK_SetDiv(kCLOCK_UartDiv, 9); + } + LPUART_Init(self->lpuart, &self->config, CLOCK_GetClockRootFreq(kCLOCK_UartClkRoot)); + #endif LPUART_TransferCreateHandle(self->lpuart, &self->handle, LPUART_UserCallback, self); uint8_t *buffer = m_new(uint8_t, rxbuf_len + 1); LPUART_TransferStartRingBuffer(self->lpuart, &self->handle, buffer, rxbuf_len); |
