Skip to content

Commit 2d20dbc

Browse files
robert-hhdpgeorge
authored andcommitted
mimxrt/machine_uart: Remove duplicate init and make IRQ optional.
Changes: - The duplicate LPUART_Init call was not needed, just an edit fail. - Allow a port to disable UART.irq(). Some code for configuration stays, but the respective UART IRQ is not enabled. Calling uart.irq() will cause an exception by extmod/machine_uart.c. Signed-off-by: robert-hh <[email protected]>
1 parent 2a5b97b commit 2d20dbc

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

ports/mimxrt/machine_uart.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,22 +326,23 @@ static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args,
326326
self->timeout_char = min_timeout_char;
327327
}
328328

329+
self->config.rxIdleType = kLPUART_IdleTypeStartBit;
330+
self->config.rxIdleConfig = kLPUART_IdleCharacter4;
329331
#if defined(MIMXRT117x_SERIES)
330332
// Use the Lpuart1 clock value, which is set for All UART devices.
331333
LPUART_Init(self->lpuart, &self->config, CLOCK_GetRootClockFreq(kCLOCK_Root_Lpuart1));
332334
#else
333335
LPUART_Init(self->lpuart, &self->config, CLOCK_GetClockRootFreq(kCLOCK_UartClkRoot));
334336
#endif
335-
self->config.rxIdleType = kLPUART_IdleTypeStartBit;
336-
self->config.rxIdleConfig = kLPUART_IdleCharacter4;
337-
LPUART_Init(self->lpuart, &self->config, BOARD_BOOTCLOCKRUN_UART_CLK_ROOT);
338337
LPUART_TransferCreateHandle(self->lpuart, &self->handle, LPUART_UserCallback, self);
339338
uint8_t *buffer = m_new(uint8_t, rxbuf_len + 1);
340339
LPUART_TransferStartRingBuffer(self->lpuart, &self->handle, buffer, rxbuf_len);
341340
self->txbuf = m_new(uint8_t, txbuf_len); // Allocate the TX buffer.
342341
self->txbuf_len = txbuf_len;
343342

343+
#if MICROPY_PY_MACHINE_UART_IRQ
344344
LPUART_EnableInterrupts(self->lpuart, kLPUART_IdleLineInterruptEnable);
345+
#endif
345346

346347
// The Uart supports inverting, but not the fsl API, so it has to coded directly
347348
// And it has to be done after LPUART_Init.
@@ -381,6 +382,7 @@ static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg
381382
self->timeout_char = 1;
382383
self->new = true;
383384
self->mp_irq_obj = NULL;
385+
self->mp_irq_trigger = 0;
384386

385387
LPUART_GetDefaultConfig(&self->config);
386388

@@ -427,6 +429,7 @@ void machine_uart_deinit_all(void) {
427429
}
428430
}
429431

432+
#if MICROPY_PY_MACHINE_UART_IRQ
430433
static mp_uint_t uart_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
431434
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
432435
self->mp_irq_trigger = new_trigger;
@@ -475,6 +478,7 @@ static mp_irq_obj_t *mp_machine_uart_irq(machine_uart_obj_t *self, bool any_args
475478

476479
return self->mp_irq_obj;
477480
}
481+
#endif
478482

479483
static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
480484
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);

ports/mimxrt/mpconfigport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ uint32_t trng_random_u32(void);
114114
#define MICROPY_PY_MACHINE_UART (1)
115115
#define MICROPY_PY_MACHINE_UART_INCLUDEFILE "ports/mimxrt/machine_uart.c"
116116
#define MICROPY_PY_MACHINE_UART_SENDBREAK (1)
117+
#ifndef MICROPY_PY_MACHINE_UART_IRQ
117118
#define MICROPY_PY_MACHINE_UART_IRQ (1)
119+
#endif
118120
#define MICROPY_PY_ONEWIRE (1)
119121
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
120122

0 commit comments

Comments
 (0)