Skip to content

Commit 81c19d9

Browse files
robert-hhdpgeorge
authored andcommitted
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 <[email protected]>
1 parent c86b9ec commit 81c19d9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

ports/mimxrt/machine_uart.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,18 @@ STATIC mp_obj_t machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args
288288
self->timeout_char = min_timeout_char;
289289
}
290290

291-
LPUART_Init(self->lpuart, &self->config, BOARD_BOOTCLOCKRUN_UART_CLK_ROOT);
291+
#if defined(MIMXRT117x_SERIES)
292+
// Use the Lpuart1 clock value, which is set for All UART devices.
293+
LPUART_Init(self->lpuart, &self->config, CLOCK_GetRootClockFreq(kCLOCK_Root_Lpuart1));
294+
#else
295+
// For baud rates < 1000000 divide the clock by 10, supporting baud rates down to 50 baud.
296+
if (self->config.baudRate_Bps > 1000000) {
297+
CLOCK_SetDiv(kCLOCK_UartDiv, 0);
298+
} else {
299+
CLOCK_SetDiv(kCLOCK_UartDiv, 9);
300+
}
301+
LPUART_Init(self->lpuart, &self->config, CLOCK_GetClockRootFreq(kCLOCK_UartClkRoot));
302+
#endif
292303
LPUART_TransferCreateHandle(self->lpuart, &self->handle, LPUART_UserCallback, self);
293304
uint8_t *buffer = m_new(uint8_t, rxbuf_len + 1);
294305
LPUART_TransferStartRingBuffer(self->lpuart, &self->handle, buffer, rxbuf_len);

0 commit comments

Comments
 (0)