There is an ARM to Trace

When I added ‘support for ARM/Kinetis‘ to my bucket list in my Percepio+Trace post, I knew it will not be straight forward. But it was a lot harder than I thought. I had to burn many week-end hours. But finally I have Percepio Trace with FreeRTOS up and running for Kinetis and ARM Cortex-M4 with CodeWarrior for MCU10.2 :-).

The screenshot below shows an application on the Tower Kinetis K60 board:

Percepio Trace on Kinetis

Percepio Trace on Kinetis

The ARM Cortex-M4 specific SysTick required some tweaks, plus a re-organization of the include files because of the Processor Expert Low Level Driver concept. Initially the timing was off by a factor of two because of the SysTick scaling factor or 2, and I believe I even found a bug in the trace library (which I have reported). At least with my fix the timing is now shown correctly.

I had to upgrade FreeRTOS, FreeRTOSTrace and PercepioTrace Processor Expert components to make it working all together. The FreeRTOS port has now an additional header file portTicks.h:

* portTicks.h
*  Interface header file to the Processor Expert Tick counter.
*  This file is used to access the interface, especially for performance
*  counters (e.g. for Percepio Trace).
*  That way the a module can interface this wrapper header file instead
*  of one of the standard FreeRTOS header files.
*  Created on: 05.07.2012
*      Author: Erich Styger

#ifndef PORTTICKS_H_
#define PORTTICKS_H_

void vOnCounterRestart(void);
/* RTOS tick handler */

/* support for trace and access to tick counter */
#include "Inhr1.h"

* \brief Return the tick raw counter value. It is assumed that the counter register has been reset at the last tick time
* \return Tick counter value. The value is reset at tick interrupt time.
* */
portLONG uxGetTickCounterValue(void);

#define FREERTOS_HWTC_PERIOD           Inhr1_PERIOD_TICKS /* counter is decrementing from this value to zero */
#define FREERTOS_HWTC_PERIOD           Inhr1_PERIOD_TICKS /* counter is incrementing from zero to this value */

/* tick information for Percepio Trace */

/* undefine previous values, where dummy anyway: make sure this header file is included last! */

#define HWTC_PERIOD           FREERTOS_HWTC_PERIOD /* counter is decrementing from this value to zero */
#define HWTC_PERIOD           FREERTOS_HWTC_PERIOD /* counter is incrementing from zero to this value */
#define HWTC_DIVISOR 2

#define HWTC_COUNT (uxGetTickCounterValue())

#endif /* PORTTICKS_H_ */

This file is part of the FreeRTOS component, and is used by the Percepio Trace library. This header file was needed to deal with the way how Processor Expert includes other component header files.

The reason for the change is the way how Processor Expert has organized the header file includes for targets like Kinetis (using Logical Device Drivers): it pretty much includes all component header files in its common files. I don’t understand why they made that change? It caused a lot of headache because the FreeRTOS queue.c is using a private (non void pointer) type to access queues.

Wherever the Percepio Trace library needs access to the tick/timer information, I had to ensure that this new header file was included as last include, as shown below for trcPort.c:

#include "FreeRTOS.h"
#include "trcPort.h"
#include "trcUser.h"
#if 1 /* << EST */
#include "portTicks.h"

#if (configUSE_TRACE_FACILITY == 1)

static char* prvFileName = NULL;

With this now I can trace my applications on Kinetis, and given the 128K of RAM on the devices like K60 makes it possible to do long and extended trace runs.

Happy Tracing 🙂


One thought on “There is an ARM to Trace

  1. Thanks for your nice experience to share with us. Really awesome article with plenty of informative things to be known for us.


What do you think?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s