From 798c390f667fa78af7d53f37c5dbe20758cc7a52 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 18 Aug 2021 13:00:33 +0700 Subject: [PATCH 1/2] gracefully end() uart, wait for TX & RX phy to power down before disable it this save around 900uA of power consumption --- cores/nRF5/Uart.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cores/nRF5/Uart.cpp b/cores/nRF5/Uart.cpp index ac952f5b..bbe84cbe 100644 --- a/cores/nRF5/Uart.cpp +++ b/cores/nRF5/Uart.cpp @@ -156,9 +156,15 @@ void Uart::end() nrfUart->INTENCLR = UARTE_INTENSET_ENDRX_Msk | UARTE_INTENSET_ENDTX_Msk; + nrfUart->EVENTS_RXTO = 0; + nrfUart->EVENTS_TXSTOPPED = 0; + nrfUart->TASKS_STOPRX = 0x1UL; nrfUart->TASKS_STOPTX = 0x1UL; + // Wait for TXSTOPPED event and for RXTO event + while ( !(nrfUart->EVENTS_TXSTOPPED && nrfUart->EVENTS_RXTO) ) yield(); + nrfUart->ENABLE = UARTE_ENABLE_ENABLE_Disabled; nrfUart->PSEL.TXD = 0xFFFFFFFF; From 5688870eefe8543b36a1e5b8b19567b6fc625155 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 18 Aug 2021 13:04:41 +0700 Subject: [PATCH 2/2] add comment for uart transceiver power --- cores/nRF5/Uart.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cores/nRF5/Uart.cpp b/cores/nRF5/Uart.cpp index bbe84cbe..9b598219 100644 --- a/cores/nRF5/Uart.cpp +++ b/cores/nRF5/Uart.cpp @@ -163,6 +163,8 @@ void Uart::end() nrfUart->TASKS_STOPTX = 0x1UL; // Wait for TXSTOPPED event and for RXTO event + // This is required before disabling UART to fully power down transceiver PHY. + // Otherwise transceiver will continue to consume ~900uA while ( !(nrfUart->EVENTS_TXSTOPPED && nrfUart->EVENTS_RXTO) ) yield(); nrfUart->ENABLE = UARTE_ENABLE_ENABLE_Disabled;