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

FreeRTOS power consumption and idle hook

Hi,

I'm developing a custom application starting from ble_hrm_freertos application. When NRF_LOG is enabled there is no way let the chip in low power consumption. I found the problem related to the following code in logger_thread function

#if NRF_LOG_ENABLED

/** **************************************************************************
 ** @brief    Logger task
 **
 ** This thread is responsible for processing log entries if logs are deferred.
 ** Thread flushes all log entries and suspends. It is resumed by idle task hook.
 **
 ** @param    arg   Task arguments (unused)
 ** *************************************************************************/

void TASK_Logger(void * arg)
{
    UNUSED_PARAMETER(arg);

    NRF_LOG_INFO("Logger task started");
    while (1)
    {
        NRF_LOG_FLUSH();
        vTaskSuspend(NULL);
    }
}

#endif
and the vApplicationIdleHook function
/** **************************************************************************
 ** @brief    Idle task hook
 **
 ** @note Idle hook must be enabled in FreeRTOS configuration (configUSE_IDLE_HOOK).
 ** *************************************************************************/

void TASK_Idle( void )
{
#if NRF_LOG_ENABLED

    vTaskResume(m_logger_task);

#endif
}

The following behavior is what happens:
  • When no other thread is scheduled the idle hook is called
  • The idle hook resumes the logger thread
  • After logger suspends, the idle hook is called again

This loop clearly prevents the device from going into low power. My question is the following: is there any other way to implement NRF_LOG flush without the side effect of increasing power consumption that much.

Best regards,

Andrea

Parents
  • Yes, you are right, and we have noticed it in this thread. The workaround is also given in my reply taken from the suggestion of other forum member.

    Please try the suggested changes to see if this can be something you can use?

  • I think this is fixed in the master branch but never got released as the nRF5 SDK is not frozen.

    In short you should apply this patch I showed in the link. Which do not need you to use ApplicationIdleHook for logger threads but instead have a new function that needs to be overridden by the application in main.c

    #if NRF_LOG_ENABLED && NRF_LOG_DEFERRED
     void log_pending_hook( void )
     {
         BaseType_t result = pdFAIL;
    
        if ( __get_IPSR() != 0 )
        {
            BaseType_t higherPriorityTaskWoken = pdFALSE;
            result = xTaskNotifyFromISR( m_logger_thread, 0, eSetValueWithoutOverwrite, &higherPriorityTaskWoken );
    
            if ( pdFAIL != result )
            {
            portYIELD_FROM_ISR( higherPriorityTaskWoken );
            }
        }
        else
        {
            UNUSED_RETURN_VALUE(xTaskNotify( m_logger_thread, 0, eSetValueWithoutOverwrite ));
        }
     }
    #endif

Reply
  • I think this is fixed in the master branch but never got released as the nRF5 SDK is not frozen.

    In short you should apply this patch I showed in the link. Which do not need you to use ApplicationIdleHook for logger threads but instead have a new function that needs to be overridden by the application in main.c

    #if NRF_LOG_ENABLED && NRF_LOG_DEFERRED
     void log_pending_hook( void )
     {
         BaseType_t result = pdFAIL;
    
        if ( __get_IPSR() != 0 )
        {
            BaseType_t higherPriorityTaskWoken = pdFALSE;
            result = xTaskNotifyFromISR( m_logger_thread, 0, eSetValueWithoutOverwrite, &higherPriorityTaskWoken );
    
            if ( pdFAIL != result )
            {
            portYIELD_FROM_ISR( higherPriorityTaskWoken );
            }
        }
        else
        {
            UNUSED_RETURN_VALUE(xTaskNotify( m_logger_thread, 0, eSetValueWithoutOverwrite ));
        }
     }
    #endif

Children
No Data
Related