8000 nrf/modules/machine/uart: Allow changing the UART baud rate w/o reset. · projectgus/micropython@4da5de9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4da5de9

Browse files
robert-hhdpgeorge
authored andcommitted
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>
1 parent a04a141 commit 4da5de9

File tree

1 file changed

+9
-1
lines changed
  • ports/nrf/modules/machine

1 file changed

+9
-1
lines changed

ports/nrf/modules/machine/uart.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ typedef struct _machine_uart_buf_t {
6262
#define nrfx_uart_tx nrfx_uarte_tx
6363
#define nrfx_uart_tx_in_progress nrfx_uarte_tx_in_progress
6464
#define nrfx_uart_init nrfx_uarte_init
65+
#define nrfx_uart_uninit nrfx_uarte_uninit
6566
#define nrfx_uart_event_t nrfx_uarte_event_t
6667
#define NRFX_UART_INSTANCE NRFX_UARTE_INSTANCE
6768

@@ -255,7 +256,11 @@ static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg
255256
self->buf.rx_ringbuf.iput = 0;
256257

257258
// Enable event callback and start asynchronous receive
259+
if (self->initialized) {
260+
nrfx_uart_uninit(self->p_uart);
261+
}
258262
nrfx_uart_init(self->p_uart, &config, uart_event_handler);
263+
self->initialized = true;
259264
nrfx_uart_rx(self->p_uart, &self->buf.rx_buf[0], 1);
260265

261266
#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
266271
}
267272

268273
static void mp_machine_uart_deinit(machine_uart_obj_t *self) {
269-
(void)self;
274+
if (self->initialized) {
275+
nrfx_uart_uninit(self->p_uart);
276+
}
277+
self->initialized = false;
270278
}
271279

272280
// Write a single character on the bus. `data` is an integer to write.

0 commit comments

Comments
 (0)
0