Skip to main content
Associate III
January 28, 2024
Question

FreeRTOS Runtime percentage calculations

  • January 28, 2024
  • 3 replies
  • 3792 views

Hi

 

Using FreeRTOS V11.0.1 and Stm32Cubeide 1.14.1 I was trying to read out the percentage information into the debugger.  Unfortunately I don't get the expected behavior

DreamOnDirac_0-1706483264013.png

As all of my tasks are either below 1% or at 1%, it does not seem correct.

I have followed the instructions in stm32CubeIDE user guide and if I make a call to 

uxTaskGetSystemState

 from the FreeRTOS API, i can calculate values that make more sense as the IDLE task now takes up about 99% of the time under no load.

Are there any other settings that needs to be fulfilled for this to work or are there any more needed configurations in FreeRTOS?

Best regards

Martin

    3 replies

    KnarfB
    Super User
    January 29, 2024

    How have you implemented portGET_RUN_TIME_COUNTER_VALUE and friends? A timer, is is running? What spped, what MCU?

    I often use the cycle counter on M4 like so. In FreeRTOSConfig.h:

    /* USER CODE BEGIN Includes */
    /* Section where include file can be added */
    #include "main.h"
    
    #include "tracer.h"
    
    #define configUSE_TRACE_FACILITY 1
    #define configGENERATE_RUN_TIME_STATS 1
    #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() \
    do { \
     CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; \
     ITM->LAR = 0xC5ACCE55; \
     DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; \
    } while(0)
    
    #define portGET_RUN_TIME_COUNTER_VALUE() (DWT->CYCCNT)
    
    #define configRECORD_STACK_HIGH_ADDRESS 1
    /* USER CODE END Includes */

     hth

    KnarfB

    Associate III
    January 29, 2024

    Hi KnarfB and thanks for the reply.

     

    I will dig in to my implementation and what I got later today. But I tested your variant, which I prefer since I dont need to assign a normal timer and have a timer update event interrupt that executes.

    When I run with your code instead get this:

    DreamOnDirac_0-1706514415005.png

    Which looks reasonable apart from the "CTR OVR" for the runtime.

     

    Best regards

    Martin

    KnarfB
    Super User
    January 29, 2024

    No idea, where the counter overflow comes from, maybe you have to add a

    DWT->CYCCNT = 0;

    in the init phase or the MCU clock is soo high (or tick rate so low)? Never seen that before.

    Even if you use a timer, you don't have to implement an interrupt handler, but read pass the CNT counter register of a running timer for the "run time variable" (STM32CubeIDE user manual) directly, either at register level or wrapped by the __HAL_TIM_GET_COUNTER macro.

    hth

    KnarfB

    Associate III
    February 13, 2024

    Does @mattias norlander or @B.Montanari have any input on this?

     

    // Martin

    Visitor II
    November 11, 2024

    This was broken by multicore support in FreeRTOS kernel, commit https://github.com/FreeRTOS/FreeRTOS-Kernel/commit/ae3a498e435cecdb25b889f2740ea99027dd0cb1.

    Since data from uxTaskGetSystemState looks correct, most likely Cube IDE needs to adapt.