Skip to content

Commit

Permalink
nrf/modules/machine/uart.c: Allow changing the UART baud rate w/o reset.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
robert-hh committed Aug 26, 2024
1 parent 6654c27 commit 826f1a1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ports/nrf/modules/machine/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -299,7 +300,11 @@ static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg
#endif

// 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
Expand All @@ -310,7 +315,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.
Expand Down

0 comments on commit 826f1a1

Please sign in to comment.