Skip to content

Commit

Permalink
cpu/nrf5x_common: fix uart_poweroff()
Browse files Browse the repository at this point in the history
Previously, uart_poweroff() and uart_poweron() were no-ops. This
replaces them with the logic to indeed power on and power off the UART
device.
  • Loading branch information
maribu committed Sep 15, 2023
1 parent 7336d9c commit e70e5c0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cpu/nrf5x_common/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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,
Expand Down Expand Up @@ -446,6 +460,7 @@ void uart_poweron(uart_t uart)

if (isr_ctx.rx_cb) {
NRF_UART0->TASKS_STARTRX = 1;
NRF_UART0->POWER = 1;
}
}

Expand All @@ -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,
Expand Down

0 comments on commit e70e5c0

Please sign in to comment.