diff options
| author | robert-hh <robert@hammelrath.com> | 2024-08-21 17:35:25 +0200 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-08-29 16:27:43 +1000 |
| commit | 4da5de94bbfa675fb59917827942074307694bde (patch) | |
| tree | 2b483363815262b48be433f5e8e5efdefe755b56 | |
| parent | a04a14163b79753c4c5ee16d80468ce475fd8b23 (diff) | |
nrf/modules/machine/uart: Allow changing the UART baud rate w/o reset.
This commit fixes a bug in the existing driver, that the UART baud rate
could not be changed without reset or power cycle. It adds as well
functionality to UART.deinit().
Signed-off-by: robert-hh <robert@hammelrath.com>
| -rw-r--r-- | ports/nrf/modules/machine/uart.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/ports/nrf/modules/machine/uart.c b/ports/nrf/modules/machine/uart.c index 90a67bcbc..b4fa0aff1 100644 --- a/ports/nrf/modules/machine/uart.c +++ b/ports/nrf/modules/machine/uart.c @@ -62,6 +62,7 @@ typedef struct _machine_uart_buf_t { #define nrfx_uart_tx nrfx_uarte_tx #define nrfx_uart_tx_in_progress nrfx_uarte_tx_in_progress #define nrfx_uart_init nrfx_uarte_init +#define nrfx_uart_uninit nrfx_uarte_uninit #define nrfx_uart_event_t nrfx_uarte_event_t #define NRFX_UART_INSTANCE NRFX_UARTE_INSTANCE @@ -255,7 +256,11 @@ static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg self->buf.rx_ringbuf.iput = 0; // Enable event callback and start asynchronous receive + if (self->initialized) { + nrfx_uart_uninit(self->p_uart); + } nrfx_uart_init(self->p_uart, &config, uart_event_handler); + self->initialized = true; nrfx_uart_rx(self->p_uart, &self->buf.rx_buf[0], 1); #if NRFX_UART_ENABLED @@ -266,7 +271,10 @@ static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg } static void mp_machine_uart_deinit(machine_uart_obj_t *self) { - (void)self; + if (self->initialized) { + nrfx_uart_uninit(self->p_uart); + } + self->initialized = false; } // Write a single character on the bus. `data` is an integer to write. |
