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

Parents
  • 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
    }
Reply
  • 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
    }
Children
No Data
Related