<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nRF52840 UART0 sleep current behavior</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/51042/nrf52840-uart0-sleep-current-behavior</link><description>I have a custom board built around the nRF52840, which spends most of its life sleeping. I&amp;#39;m able to achieve ~3uA current draw when it is sleeping, but I&amp;#39;ve recently started running into corner cases where the current draw is much higher. I suspect that</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 06 Sep 2019 19:33:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/51042/nrf52840-uart0-sleep-current-behavior" /><item><title>RE: nRF52840 UART0 sleep current behavior</title><link>https://devzone.nordicsemi.com/thread/208530?ContentTypeID=1</link><pubDate>Fri, 06 Sep 2019 19:33:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5951d0c-445a-4f2f-b3ca-969cfe15caa3</guid><dc:creator>dwanninger</dc:creator><description>&lt;p&gt;Thanks for your feedback.&amp;nbsp; I tried the TX and RX abort suggestions, but they did not work.&amp;nbsp; I can also confirm that I&amp;#39;m using UART0.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve been struggling to be able to consistently repeat the issue, and I think I might have landed on a way to reproduce.&amp;nbsp; The key seems to be tied to using the bootloader with a soft device.&amp;nbsp; Using the setup and code described below, I&amp;#39;ve found that the ~620uA issue appears when I&amp;#39;m both using the bootloader AND printing to the UART before sleep.&amp;nbsp; If I remove the UART printf OR ditch the bootloader and load the app directly to address 0x00, then the sleep current is ~3uA.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s my hardware setup:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;nRF52840 USB dongle&lt;/li&gt;
&lt;li&gt;SB1 jumpered&lt;/li&gt;
&lt;li&gt;SB2 cut&lt;/li&gt;
&lt;li&gt;3.0V applied to VDD_nRF&lt;/li&gt;
&lt;li&gt;UART TX - P0.26&lt;/li&gt;
&lt;li&gt;UART RX - P0.22&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Software setup:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;15.3 SDK&lt;/li&gt;
&lt;li&gt;Using example bootloader: secure_bootloader_ble_s140_pca10056 - nrf52840_xxaa_s140&lt;/li&gt;
&lt;li&gt;Loading S140 soft device&lt;/li&gt;
&lt;li&gt;IAR 8.40, full optimization&lt;/li&gt;
&lt;li&gt;Loading code at address 0x26000&lt;/li&gt;
&lt;li&gt;All code contained in main.c:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

#include &amp;quot;nordic_common.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrfx.h&amp;quot;
#include &amp;quot;nrfx_clock.h&amp;quot;
#include &amp;quot;nrfx_uarte.h&amp;quot;
#include &amp;quot;nrfx_systick.h&amp;quot;

#define PIN_UART_TX         NRF_GPIO_PIN_MAP(0,26)
#define PIN_UART_RX         NRF_GPIO_PIN_MAP(0,22)

uint8_t rxByte;
nrfx_uarte_t uartInstance = NRFX_UARTE_INSTANCE(0);

int fputc(int ch, FILE *f)
{
    while(nrfx_uarte_tx_in_progress(&amp;amp;uartInstance)); 
    nrfx_uarte_tx(&amp;amp;uartInstance, (uint8_t *)&amp;amp;ch, 1);
    return ch;
}

static void ClockEventHandler(nrfx_clock_evt_type_t event)
{
    
}

static void UartEventHandler(nrfx_uarte_event_t const * p_event, void *p_context)
{
    if(NRFX_UARTE_EVT_RX_DONE == p_event-&amp;gt;type) {
        nrfx_uarte_rx(&amp;amp;uartInstance, &amp;amp;rxByte, 1);
    } else if(NRFX_UARTE_EVT_TX_DONE == p_event-&amp;gt;type) {
        // do nothing
    } else if(NRFX_UARTE_EVT_ERROR == p_event-&amp;gt;type) {
        nrfx_uarte_rx(&amp;amp;uartInstance, &amp;amp;rxByte, 1);
    }
}

void ClockInit()
{
    nrfx_clock_enable();
    
    ret_code_t err_code = nrfx_clock_init(ClockEventHandler);
    ASSERT((err_code == NRF_SUCCESS) || (err_code == NRF_ERROR_MODULE_ALREADY_INITIALIZED));

    nrfx_clock_hfclk_start();
    while (!nrfx_clock_hfclk_is_running());

    nrfx_clock_lfclk_start();
    while (!nrfx_clock_lfclk_is_running());
    
    nrfx_systick_init();
}

int32_t UartInit()
{
    nrfx_uarte_config_t uartConfig = NRFX_UARTE_DEFAULT_CONFIG;

    uartConfig.pseltxd = PIN_UART_TX;
    uartConfig.pselrxd = PIN_UART_RX;
    uartConfig.hwfc = NRF_UARTE_HWFC_DISABLED;
    uartConfig.parity = NRF_UARTE_PARITY_EXCLUDED;
    uartConfig.baudrate = NRF_UARTE_BAUDRATE_115200;
    
    nrfx_err_t e = nrfx_uarte_init(&amp;amp;uartInstance, &amp;amp;uartConfig, UartEventHandler);
    if(NRFX_SUCCESS==e) e = nrfx_uarte_rx(&amp;amp;uartInstance, &amp;amp;rxByte, 1);
    
    return NRFX_SUCCESS == e ? 0 : -1; 
}

void UartDeinit()
{
    nrfx_uarte_rx_abort(&amp;amp;uartInstance);
    nrfx_uarte_uninit(&amp;amp;uartInstance);
    
    *(volatile uint32_t *)0x40002FFC = 0;
    *(volatile uint32_t *)0x40002FFC;
    *(volatile uint32_t *)0x40002FFC = 1;
}


int main(void)
{
    UartInit();

    // Commenting out these 4 lines fixes the sleep current issue
    printf(&amp;quot;Going to sleep...\r\n&amp;quot;);
    while(nrfx_uarte_tx_in_progress(&amp;amp;uartInstance)); 
    nrfx_uarte_tx_abort(&amp;amp;uartInstance);
    nrfx_uarte_rx_abort(&amp;amp;uartInstance);
    
    UartDeinit();
    
    __SEV();
    __WFE();
    __WFE();
    
    UartInit();
    
    printf(&amp;quot;Awake again!\r\n&amp;quot;);
        
    while(1);
}



&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART0 sleep current behavior</title><link>https://devzone.nordicsemi.com/thread/205657?ContentTypeID=1</link><pubDate>Thu, 22 Aug 2019 14:02:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ad294eb1-5bfb-49d2-b6ff-13e5a7042cf0</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;Actually I think it&amp;#39;s just a matter of stopping RX and TX to get the consumption down.&lt;/p&gt;
&lt;p&gt;Try to add this after transactions are finished, instead of uninitializing the UART:&lt;/p&gt;
&lt;p&gt;nrfx_uarte_tx_abort(&amp;amp;uartInstance);&lt;/p&gt;
&lt;p&gt;nrfx_uarte_rx_abort(&amp;amp;uartInstance);&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART0 sleep current behavior</title><link>https://devzone.nordicsemi.com/thread/205642?ContentTypeID=1</link><pubDate>Thu, 22 Aug 2019 13:34:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:495a56d5-ed05-4164-9dd0-0c2d9ac17aa7</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;I tried your code here now, but I can&amp;#39;t really reproduce the exact same behavior. First I changed the printf to nrfx_uarte_tx, since I don&amp;#39;t know how you are doing the mapping to printf. Then I added some delays since the nrfx_uarte_tx is returning right away, and the TX does not finish. Also it seems like the rx_abort function returns right away so I added a delay between this and the uninit call.&lt;/p&gt;
&lt;p&gt;The 40002FFC workaround seems to be working here. Are you sure that you are using UARTE0, not 1?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART0 sleep current behavior</title><link>https://devzone.nordicsemi.com/thread/205380?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2019 15:10:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:56968406-f976-49d9-a233-001313bd86b6</guid><dc:creator>dwanninger</dc:creator><description>&lt;p&gt;I am disabling the UART, so I expect the MCU power consumption to be &amp;lt;3uA.&amp;nbsp; In some FW builds, it is.&amp;nbsp; In other cases, it is &amp;gt;600uA.&amp;nbsp; Something inconsistent is happening behind the scenes.&amp;nbsp; Perhaps a clock or DMA is not always being properly shutdown, or internal pulldowns are being enabled when they shouldn&amp;#39;t be. &lt;/p&gt;
&lt;p&gt;It&amp;#39;s also possible that this isn&amp;#39;t a UART issue at all.&amp;nbsp; But it seems to be the most likely culprit.&amp;nbsp; And again, in a stripped down version of the code running on the USB dongle with the UART as the only peripheral, I&amp;#39;m able to reproduce the issue.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART0 sleep current behavior</title><link>https://devzone.nordicsemi.com/thread/205372?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2019 14:53:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c8d64495-1103-41a2-b71f-9b583e1a0740</guid><dc:creator>Jimmy Wong</dc:creator><description>&lt;p&gt;HI ,&lt;/p&gt;
&lt;p&gt;if you use the UART, it needs to turn on the UART (50uA) from the Product spec + high frequency clock.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://jimmywongbluetooth.wordpress.com/2019/04/17/overview-uart-driver-handling-at-nrf52/"&gt;https://jimmywongbluetooth.wordpress.com/2019/04/17/overview-uart-driver-handling-at-nrf52/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I did some measurement on the Legacy UART or UART with DMA.&lt;/p&gt;
&lt;p&gt;if you see more than 6xx uA, it should have other things on top of it.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;if you need to optimize the currrent consumption with UART particular on the UART RX, you may need to use extra gpio pin for control or use the timer to stop it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART0 sleep current behavior</title><link>https://devzone.nordicsemi.com/thread/205351?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2019 13:57:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a01499a-8e4c-47fd-8523-841e119d615f</guid><dc:creator>dwanninger</dc:creator><description>&lt;p&gt;It turns out that the problem can still occur even if I do not transmit any data on the UART immediately before going to sleep.&amp;nbsp; I would immediately assume this to be a FW issue if not for the fact that it can be reproduced in trivial applications.&amp;nbsp; The sleep current of ~620 uA seems very suspicious - I&amp;#39;m using a supply voltage of 3V, so it would correspond nicely with 2 pulldown resistors being enabled.&amp;nbsp; Explicitly initializing the UART pins as GPIOs with no pulls before going to sleep doesn&amp;#39;t change anything though.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UART0 sleep current behavior</title><link>https://devzone.nordicsemi.com/thread/204772?ContentTypeID=1</link><pubDate>Mon, 19 Aug 2019 12:53:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:632f7e8b-b94e-4d47-ad99-f9f9ff611c6b</guid><dc:creator>dwanninger</dc:creator><description>&lt;p&gt;Also - I&amp;#39;ve reproduced the problem on the nRF52840 Dongle, so it is not an issue with the rest of the board.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>