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 <robert@hammelrath.com>
This commit is contained in:
@@ -326,22 +326,23 @@ static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args,
|
||||
self->timeout_char = min_timeout_char;
|
||||
}
|
||||
|
||||
self->config.rxIdleType = kLPUART_IdleTypeStartBit;
|
||||
self->config.rxIdleConfig = kLPUART_IdleCharacter4;
|
||||
#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
|
||||
LPUART_Init(self->lpuart, &self->config, CLOCK_GetClockRootFreq(kCLOCK_UartClkRoot));
|
||||
#endif
|
||||
self->config.rxIdleType = kLPUART_IdleTypeStartBit;
|
||||
self->config.rxIdleConfig = kLPUART_IdleCharacter4;
|
||||
LPUART_Init(self->lpuart, &self->config, BOARD_BOOTCLOCKRUN_UART_CLK_ROOT);
|
||||
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);
|
||||
self->txbuf = m_new(uint8_t, txbuf_len); // Allocate the TX buffer.
|
||||
self->txbuf_len = txbuf_len;
|
||||
|
||||
#if MICROPY_PY_MACHINE_UART_IRQ
|
||||
LPUART_EnableInterrupts(self->lpuart, kLPUART_IdleLineInterruptEnable);
|
||||
#endif
|
||||
|
||||
// The Uart supports inverting, but not the fsl API, so it has to coded directly
|
||||
// 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
|
||||
self->timeout_char = 1;
|
||||
self->new = true;
|
||||
self->mp_irq_obj = NULL;
|
||||
self->mp_irq_trigger = 0;
|
||||
|
||||
LPUART_GetDefaultConfig(&self->config);
|
||||
|
||||
@@ -427,6 +429,7 @@ void machine_uart_deinit_all(void) {
|
||||
}
|
||||
}
|
||||
|
||||
#if MICROPY_PY_MACHINE_UART_IRQ
|
||||
static mp_uint_t uart_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
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
|
||||
|
||||
return self->mp_irq_obj;
|
||||
}
|
||||
#endif
|
||||
|
||||
static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
@@ -114,7 +114,9 @@ uint32_t trng_random_u32(void);
|
||||
#define MICROPY_PY_MACHINE_UART (1)
|
||||
#define MICROPY_PY_MACHINE_UART_INCLUDEFILE "ports/mimxrt/machine_uart.c"
|
||||
#define MICROPY_PY_MACHINE_UART_SENDBREAK (1)
|
||||
#ifndef MICROPY_PY_MACHINE_UART_IRQ
|
||||
#define MICROPY_PY_MACHINE_UART_IRQ (1)
|
||||
#endif
|
||||
#define MICROPY_PY_ONEWIRE (1)
|
||||
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user