vTaskGetRunTimeStats on a Cortex M3 with IAR

anonymous wrote on Tuesday, July 27, 2010:


I am unable to make vTaskGetRunTimeStats() work on a Cortex M3 with IAR. First I followed the instructions in the FreeRTOS Reference Manual, but found that declaring the counting variable extern in FreeRTOSConfig.h gave a assembly error (in portasm.s) which I could not understand nor fix.

After declaring the variable in port.h (which I assume is not OK due to the license) I was able to get everything seemingly working. However, upon calling vTaskGetRunTimeStats(buffer) the buffer isn’t filled. (I verified this by giving the first buffer bytes a known value before calling vTaskGetRunTimeStats()).

Does anybody know what I may be doing wrong?

jamesstanley wrote on Thursday, July 29, 2010:

The build error in portasm.s is due to the assembler trying to interpret the C keyword ‘extern’ which it can’t do. The trick is to include the extra code only when FreeRTOSConfig.h is included from FreeRTOS.h.

For the CORTEX_LM3Sxxxx_IAR_Keil demo, the code you need to add to FreeRTOSConfig.h is:

#define configGENERATE_RUN_TIME_STATS		1
	extern volatile unsigned long ulHighFrequencyTimerTicks;
	/* ulHighFrequencyTimerTicks is already being incremented at 20KHz.  Just
	set its value back to 0. */
	#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() ( ulHighFrequencyTimerTicks = 0UL )
	#define portGET_RUN_TIME_COUNTER_VALUE()	ulHighFrequencyTimerTicks

You will also need to add the following definition to timertest.c:

/* Counts the total number of times that the high frequency timer has 'ticked'.
This value is used by the run time stats function to work out what percentage
of CPU time each task is taking. */
volatile unsigned portLONG ulHighFrequencyTimerTicks = 0UL;

and add the following lines to the end of the function Timer0IntHandler():

/* Keep a count of the total number of 20KHz ticks.  This is used by the
run time stats functionality to calculate how much CPU time is used by
each task. */

You should now find that calling vTaskGetRunTimeStats() collects the required data.

anonymous wrote on Friday, July 30, 2010:

Thank you for your advice jamesstanley. With that information it works like a charm.