diff --git a/cpu/nrf5x_common/periph/uart.c b/cpu/nrf5x_common/periph/uart.c index 80d7b29ee1767..fa30c5ca93770 100644 --- a/cpu/nrf5x_common/periph/uart.c +++ b/cpu/nrf5x_common/periph/uart.c @@ -276,6 +276,10 @@ static void _write_buf(uart_t uart, const uint8_t *data, size_t len) void uart_write(uart_t uart, const uint8_t *data, size_t len) { assert(uart < UART_NUMOF); + if (!dev(uart)->ENABLE) { + /* Device is powered down. Writing anyway would deadlock */ + return; + } #ifdef MODULE_PERIPH_UART_NONBLOCKING for (size_t i = 0; i < len; i++) { /* in IRQ or interrupts disabled */ @@ -337,6 +341,11 @@ void uart_poweron(uart_t uart) assert(uart < UART_NUMOF); if (isr_ctx[uart].rx_cb) { +#if !defined(CPU_MODEL_NRF52832XXAA) && !defined(CPU_FAM_NRF51) + dev(uart)->ENABLE = UARTE_ENABLE_ENABLE_Enabled; +#else + NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Enabled; +#endif dev(uart)->TASKS_STARTRX = 1; } } @@ -346,6 +355,11 @@ void uart_poweroff(uart_t uart) assert(uart < UART_NUMOF); dev(uart)->TASKS_STOPRX = 1; +#if !defined(CPU_MODEL_NRF52832XXAA) && !defined(CPU_FAM_NRF51) + dev(uart)->ENABLE = UARTE_ENABLE_ENABLE_Disabled; +#else + NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Disabled; +#endif } int uart_mode(uart_t uart, uart_data_bits_t data_bits, uart_parity_t parity, @@ -446,6 +460,7 @@ void uart_poweron(uart_t uart) if (isr_ctx.rx_cb) { NRF_UART0->TASKS_STARTRX = 1; + NRF_UART0->POWER = 1; } } @@ -454,6 +469,7 @@ void uart_poweroff(uart_t uart) (void)uart; NRF_UART0->TASKS_STOPRX = 1; + NRF_UART0->POWER = 0; } int uart_mode(uart_t uart, uart_data_bits_t data_bits, uart_parity_t parity,