From ec1e7a03b38c625664a4615e60d26956205d7a67 Mon Sep 17 00:00:00 2001 From: Phil Underwood Date: Sat, 17 Jun 2023 22:42:12 +0100 Subject: [PATCH 1/2] Reset UART on deinit, reduces power consumption --- ports/nrf/common-hal/busio/UART.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ports/nrf/common-hal/busio/UART.c b/ports/nrf/common-hal/busio/UART.c index 10a34e09df38..94201774dea9 100644 --- a/ports/nrf/common-hal/busio/UART.c +++ b/ports/nrf/common-hal/busio/UART.c @@ -266,8 +266,15 @@ bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) { } void common_hal_busio_uart_deinit(busio_uart_obj_t *self) { + volatile uint32_t *power_cycle = (void*)(self->uarte->p_reg) + 0xFFC; if (!common_hal_busio_uart_deinited(self)) { + nrfx_uarte_rx_abort(self->uarte); + nrfx_uarte_tx_abort(self->uarte); nrfx_uarte_uninit(self->uarte); + // power cycle the peripheral as per https://devzone.nordicsemi.com/f/nordic-q-a/26030/how-to-reach-nrf52840-uarte-current-supply-specification/102605#102605 + *power_cycle = 0; + *power_cycle; + *power_cycle = 1; reset_pin_number(self->tx_pin_number); reset_pin_number(self->rx_pin_number); reset_pin_number(self->rts_pin_number); From 4bb475b930d4237f09f26ac3a6f841fbd690d026 Mon Sep 17 00:00:00 2001 From: Phil Underwood Date: Sat, 17 Jun 2023 22:49:47 +0100 Subject: [PATCH 2/2] formatting --- ports/nrf/common-hal/busio/UART.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/nrf/common-hal/busio/UART.c b/ports/nrf/common-hal/busio/UART.c index 94201774dea9..626956946f8a 100644 --- a/ports/nrf/common-hal/busio/UART.c +++ b/ports/nrf/common-hal/busio/UART.c @@ -266,7 +266,7 @@ bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) { } void common_hal_busio_uart_deinit(busio_uart_obj_t *self) { - volatile uint32_t *power_cycle = (void*)(self->uarte->p_reg) + 0xFFC; + volatile uint32_t *power_cycle = (void *)(self->uarte->p_reg) + 0xFFC; if (!common_hal_busio_uart_deinited(self)) { nrfx_uarte_rx_abort(self->uarte); nrfx_uarte_tx_abort(self->uarte);