Using FreeRTOS+TRACE with Arduino DUE via SAM ICE

owaisfazal wrote on Saturday, September 28, 2013:

Hello everyone,

I am trying to use the trace feature of FreeRTOS ported on Arduino DUE using the FreeRTOS+ analysis tool TRACE from Precepio. I am having trouble getting things integrated as there are several files to be included into the development directory and finally to connect SAM ICE to the DUE board. I was wondering if there is anyone who has already tried this method of debugging before or has any knowledge as to how to do this please do let me know.


rtel wrote on Saturday, September 28, 2013:

You mention two things here:

  1. Getting the trace files integrated.

There are some examples in the FreeRTOS download that use FreeRTOS+Trace. You can use those as a reference. Probably the easiest one to look at will be this one:

as it is running on a Cortex-M3 so will use the same time source as the SAM3 device on the DUE.

  1. Connecting the SAM ICE.

Are you using Atmel Studio to build your project? If so, then you just select the SAM ICE as the debug interface in the project.


owaisfazal wrote on Sunday, September 29, 2013:

Hello Richard,

Thank you for your prompt response. Actually, I was trying to use Arduino IDE although I wasn’t sure if it would work but anyhow I gave it a try and tried to copy the source files from the Generic Recorder Library folder to the FreeRTOS library for Arduino IDE but with much effort I couldn’t get it to compile without errors. I will look into the example you mentioned and hopefully figure this out. Secondly, is it possible to use SAM ICE with the Arduino IDE? If so, it will be interesting otherwise I can always shift to Atmel Studio.


owaisfazal wrote on Monday, September 30, 2013:

I have looked into the above mentioned example but couldn’t figure out the integration process because;

None of the files mentioned for using TRACE on PERCEPIO website are included in the main code, Secondly in FreeRTOSConfig trcKernelPort.h is defined but is nowhere to be found inside the demo directory.

I have tried copying Base.c Hardwareport.c Kernel.c User.c from GenericRecorderLibSrc folder directly in libraries\FreeRTOS_ARM folder of Arduiono IDE as well as the contents of GenericRecorderLibSrc\KernelPorts\FreeRTOS , GenericRecorderLibSrc\Include and GenericRecorderLibSrc\ConfigurationTemplate. After this I have tried including all .c and .h files related to Recorder library into my sketch for Arduino DUE but I have been experiencing a list of errors.

Please advise how I should rectify this.


davedoors wrote on Monday, September 30, 2013:

As far as I can see the Visual Studio demo includes the following trace source files from the FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace directory -

It also has FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/include in its include path for the common trace header files (including trcKernelPort.h which you mention), and ./Trace_Recorder_Configuration which is relative to the visual studio project directory in its include path to pick up the demo’s own trcConfig.h and trcHardwarePort.h

Hope that helps. I have never tried building anything in the Arduio IDE so I can help there.

owaisfazal wrote on Friday, October 04, 2013:

Thank you Dave & Richard,

I have successfully included the necessary source files and am able to read the trace from the DUE board. Although once I start reading the trace a message pops up saying “This trace does not have a frequency set. Only sequential mode and native trace ticks can be used for timing” can anyone please elaborate what this message signifies.


johankraft wrote on Friday, October 04, 2013:

Hi Owais,

I’m happy that you got the build problem sorted out, as we discussed over email.

The error message you get from FreeRTOS+Trace (“This trace does not have a frequency set. Only sequential mode and native trace ticks can be used for timing”) is caused by the “frequency” property of the trace being zero (not initialized). This is the frequency of the timer/counter used for the event time-stamping, on Arduino Due (Cortex-M3) this is the SysTick timer. The frequency property is set in prvTraceGetDTS (trcBase.c) on the first event recorded after the FreeRTOS scheduler has been started.

This problem can be caused by two things:

  1. You have extracted the trace before FreeRTOS has been started, or before the first event has been recorded (e.g., a task-switch).

  2. You have missed to call vTraceInitTraceData(). This should be called early in your startup, before any calls to FreeRTOS are made.

I hope this solves your problem!

Best Regards,
Johan Kraft
Percepio AB

owaisfazal wrote on Tuesday, October 08, 2013:

Hello Mr. Kraft,

Thank you for your continuous support. I have tried the above mentioned points and still getting the same message once I start to read the trace. I have called the vTraceInitTraceData() at the very beginning of my code in setup to be exact and uiTraceStart() at the beginning of the very first task that is the task with the highest priority. Is there anything else that I need to ensure to avoid getting this message? Secondly, I want to ask whether I can see the data being transferred to/from the Queue in the trace?


johankraft wrote on Monday, October 14, 2013:

Hi Owais,

Do you mean the message “This trace does not have a frequency set. Only sequential mode and native trace ticks can be used for timing”?

This message is displayed when the frequency field of the trace header is zero, i.e., not initialized.

I suggest that you place a break point in prvTraceGetDTS (trcBase.c) where the frequency field should be assigned. This function is called on every event to calculate the timestamp of the event (time since last event), and the frequency field is set on the first call after the OS tick timer has started (init_hwtc_count != HWTC_COUNT). Is prvTraceGetDTS ever reached? If so, is the frequency field assigned? What value does it receive?

You may also double-check in trcHardwarePort.h that SELECTED_PORT is set to PORT_ARM_CortexM.

Best Regards,
Johan Kraft
Percepio AB

owaisfazal wrote on Friday, October 18, 2013:

Hello Mr. Kraft,

Yes I mean the message is still showing up when I start the TRACE. I have just moved to Atmel Studio 6 for programming and debugging Arduino DUE. I have not yet written the code for the FreeRTOS using Atmel Studio 6 but will get to it soon hopefully. I noticed one more this that FreeRTOS+TRACE library is not available in the ASF Wizard could you please guide me how to include the sources into Atmel Studio 6 Environment so that I may use them TRACE feature while programming with Atmel Studio 6. Moreover, I also wanted to know whether it is possible to see the items that are being sent to/from a Queue in FreeRTOS+TRACE as I noticed the macro xQueuePeek available in FreeRTOS which I used to simply see the data in serial monitor which was working as expected but is it also possible in FreeRTOS+TRACE?