cancel
Showing results for 
Search instead for 
Did you mean: 

How can I add TraceX support in STM32CubeIDE?

B.Montanari
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:
154.png
   
  • How to make it work:

 
  1. Activate the feature in the firmware

Open the Software Package:
155.png
Enable ThreadX / TraceX support feature in the software packs component selector:
157.png
 
  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:
159.png
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.
161.png
 
  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:
tx_trace_enable(&tracex_buffer,TRACEX_BUFFER_SIZE,30);
The code should look like this:
163.png
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);
     *(.trace)
 } > RAM_D1
It should look like this:
165.png
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:
167.png
We can also associate the *.trx-files with TraceX tools, for that, open the Window->Preferences menu:
169.png
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:
170.png
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.
 
172.png
In the opened tab, click on the Export Trace option.
 
174.png
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.
176.png
 
Click in OK, and if all steps were done well the TraceX should be open with the generated trace according to the application behavior
178.png
 
Assuming the default file path was kept, you should be able to find the generated file inside the TraceX folder within the project folders:
 
179.png
 
  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):
180.png
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:
181.png
The TraceX also allows using time view:
182.png
 
  • 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 :)

 
Comments
QDot
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.

LauraCx
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: