Showing results for 
Search instead for 
Did you mean: 

How can I add TraceX support in STM32CubeIDE?

ST Employee

How can I add TraceX support in STM32CubeIDE?

To add TraceX support to a STM32CubeIDE project and properly use it you’ll need to follow a few steps, described in detail in this article.

Goal: Add TraceX support to STM32CubeIDE using X-CUBE-AZRTOS-H7
Although the example is using the NUCLEO-H723ZG, you can use the same steps for other STM32H7 based boards. The main differences are usually pinout and clock configuration.
This article will show you how to add TraceX support in a simple project that already uses ThreadX with the X-CUBE-AZRTOS-H7 software package.
TraceX allows a post mortem analysis of the thread sequence that occurred during firmware execution; here is a simplified block diagram flow:
  • How to make it work:

  1. Activate the feature in the firmware

Open the Software Package:
Enable ThreadX / TraceX support feature in the software packs component selector:
  1. Allocate the memory to store the trace during firmware execution

In the left panel of the STM32CubeIDE, select the software pack and click on the ThreadX tab. Change the value of configuration TX_ENABLE_EVENT_TRACE to enable it:
The trace timestamp source is setup by default on the cycle counter of the Cortex at address 0xE0001004.
Go to Project->Generate Code to update the generated code for TraceX support or use the ALT+K keyboard shortcut.
  1. Add small pieces of code to provide the memory allocation dedicated to trace

In the app_threadx.c file, create buffer inside STM32 for TraceX data. In file app_threadx.c add:
#define TRACEX_BUFFER_SIZE 64000
uint8_t tracex_buffer[64000];
Inside the function App_ThreadX_Init we enable the trace:
The code should look like this:
Add the trace buffer to AXI SRAM. In order to do this, open the STM32H723ZGTX_FLASH.ld file and add this code:
.trace (NOLOAD):
  . = ALIGN(4);
 } > RAM_D1
It should look like this:
Now the trace buffer will be in the known location 0x24000000 (RAM_D1). Upon building, you should be able to see the RAM_D1 now being used in the Build Analyzer, located at the lower right corner of the STM32CubeIDE:
We can also associate the *.trx-files with TraceX tools, for that, open the Window->Preferences menu:
Locate and open the File Association Section then clock in the "add" icon to create the *.trx file type support. Once applied, click in the second "add" button and the select the TraceX software:
To complete this step, click in the "Apply and Close"
Now all the steps to set-up de trace generation are done. Enter in Debug mode, let the application run for a while and then pause it. Open the ThreadX menu and select one (can be multiple), in the print screen below it was selected the ThreadX Thread List.
In the opened tab, click on the Export Trace option.
Another menu will appear, where you'll be able to change the file path/name and also select if you want to open the TraceX with the generated file.
Click in OK, and if all steps were done well the TraceX should be open with the generated trace according to the application behavior
Assuming the default file path was kept, you should be able to find the generated file inside the TraceX folder within the project folders:
  1. As an alternative, you can keep using Microsoft’s TraceX tool to display the result as well

Open the TraceX tool and click Open File. Locate the ThreadX_TraceX_Debug.trx created and import it (image is showing a different name - tracex_log.trx):
Now all the information is available for analyzes – as the code used had a single thread that was used to blink the LED every 200ms, the overall view is quite simple, but this is the overall analysis:
The TraceX also allows using time view:
  • Useful links:

  • Conclusion:

Adding TraceX in the application consists of:
    • Adding the ThreadX component in STM32CubeMX/STM32CubeIDE
    • Add TraceX support and apply minor configuration in STM32CubeMX/ STM32CubeIDE
    • Generate the code from STM32CubeMX/ STM32CubeIDE
      1. This will update the project structure with all needed files
    • Create the size of the buffer that will store the trace during firmware execution
    • Export this data to be analyzed on TraceX
    • Have fun 🙂

Associate II

This works perfectly if I use only ThreadX module, but when I tried to use TraceX in the application where ThreadX and USBx are used I receive always a "Precise data access violation" hard fault. As I figured out, it happens when USBx thread (registered in a separate byte pool than ThreadX threads) tries to register a traceX object (in _ux_trace_object_register function).

Can you, pls, give an example of how to set up a TraceX functionality for ThreadX used with USBx as well as other Azure modules?

p.s. I have tried this on Nucleo-L552.

ST Employee

Hello @QDot​ ,

Thank you for your feedback, we are working on an article covering TraceX and USBX and ThreadX that would be of interest for you.


Version history
Last update:
‎2021-09-30 09:43 AM
Updated by: