Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

suspend NRF_LOG to save power and then resume

Help, I want to run NRF_LOG_ENABLED builds but occasionally I want the device to sleep for (many) minutes, so I wish to turn off the NRF_LOG_UART backend since it consumes 200-300 uA, and then renable when back running, I have tried various hacks but to no avail, is there any easy way to achieve this - thanks

  • I tried the following and it sort of works... any thoughts
    #if (NRF_LOG_ENABLED && LOG_POWER_SAVE)
      #include "nrf_drv_uart.h"
      extern nrf_drv_uart_t m_uart;  // nb used by uart logger
      extern "C" void nrf_log_backend_uart_init(void);
      static bool nrf_log_disabled;
    #endif
    void Hardware::power_on()
    {
      // turn on LOGging - sneaky
    #if (NRF_LOG_ENABLED && LOG_POWER_SAVE)
      if ( nrf_log_disabled )
      {
        nrf_log_backend_uart_init();
        NRF_LOG_INFO("...logging enabled" );
      }
      nrf_log_disabled = false;
    #endif
      NRF_LOG_INFO(__PRETTY_FUNCTION__);
      //.....
    }

    void Hardware::power_off()
    {
      //....
     
      // disable logging very sneaky
      // outstanding nordic request but this seems to work
    #if (NRF_LOG_ENABLED && LOG_POWER_SAVE)
      // attempt to turn off LOG uart it consumes loads of power
      NRF_LOG_INFO("shutting down logging..." );
      NRF_LOG_FLUSH();
      NRF_LOG_FINAL_FLUSH();
      nrf_drv_uart_uninit( &m_uart);
      nrf_log_disabled = true;
    #endif
    }
  • Hi, have you tried to stop UART RX and TX before going to sleep? I was able to get the current down by adding the following two lines to the idle_state_handle. It seems stable to me. The function is from the hrs example in SDK 15.2.0

    static void idle_state_handle(void)
    {
        ret_code_t err_code;

        err_code = nrf_ble_lesc_request_handler();
        APP_ERROR_CHECK(err_code);

        if (NRF_LOG_PROCESS() == false)
        {
            NRF_UARTE0->TASKS_STOPRX = 1;
            NRF_UARTE0->TASKS_STOPTX = 1;
            nrf_pwr_mgmt_run();

        }
  • although that saves a few precious electrons, I found the maximum saving by turning off the usart, in sleep that saves 300 uA, also most of the time if an interrupt occurs I am tracing anyway, but thanks for the suggestion, I will play some more

Related