esp-idf/examples/system/app_trace_basic
2023-08-24 12:51:19 +08:00
..
main example/system: add generic apptrace example with pytest support 2023-02-15 10:30:08 +01:00
CMakeLists.txt example/system: add generic apptrace example with pytest support 2023-02-15 10:30:08 +01:00
pytest_app_trace_basic.py example/apptrace_basic: remove port parameter from pytest 2023-03-13 11:56:47 +03:00
README.md feat(ci): Enable p4 example, test_apps and unit tests CI build 2023-08-24 12:51:19 +08:00
sdkconfig.defaults example/system: add generic apptrace example with pytest support 2023-02-15 10:30:08 +01:00

Supported Targets ESP32 ESP32-C2 ESP32-C3 ESP32-P4 ESP32-S2 ESP32-S3

Application Level Tracing Example (Basic)

(See the README.md file in the upper level 'examples' directory for more information about examples.)

This example demonstrates how to use the Application Level Tracing Library (henceforth referred to as App Trace) to log messages to a host via JTAG instead of the normal method of logging via UART.

UART logs are time consuming and can significantly slow down the function that calls it. Therefore, it is generally a bad idea to use UART logs in time-critical functions. Logging to host via JTAG is significantly faster and can be used in time-critical functions. For more details regarding logging to host via JTAG, refer to the Logging to Host Documentation.

Hardware Required

To run this example, you need a supported target dev board connected to a JTAG adapter, which can come in the following forms:

This example will assume that an ESP-WROVER-KIT is used.

Connections:

  1. Connect the JTAG interface to the target board. For details about how to set up JTAG interface, please see JTAG Debugging. Power up both the JTAG debugger and target board.

  2. After connecting JTAG interface, you need to Run OpenOCD.

  3. Open a separate terminal window and run telnet by entering the command below. The telnet terminal window is used to feed commands to OpenOCD:

    telnet localhost 4444
    

Configure the project

idf.py menuconfig
  • To enable application tracing, select the (X) Trace memory option under Component config > Application Level Tracing. This option should have been selected by default.

Build, Flash, and Run

Build the project and flash it to the board, then run monitor tool to view serial output:

idf.py -p PORT flash monitor

(Replace PORT with the name of the serial port to use.)

Start App Trace: In the telnet session window, trigger OpenOCD to start App Trace on the target by entering the command below. This command will collect 9000 bytes of JTAG log data and save them to the file file://apptrace.log (note file:// depends on where OpenOCD was started). Assuming that OpenOCD was started in this example's directory, apptrace.log will be saved here as well.

esp apptrace start file://apptrace.log 0 2000 3 0 0

Note: For more details on OpenOCD commands regarding App Trace, refer to the OpenOCD Application Level Tracing Commands

(To exit the serial monitor, type Ctrl-].)

See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.

Troubleshooting

Unable to flash when OpenOCD is connected to the target

On ESP32 boards, one likely cause would be an incorrect SPI flash voltage when starting OpenOCD. Suppose a target board/module with a 3.3 V powered SPI flash is being used, but the configuration file (ex. board/esp32-wrover.cfg for ESP32) is selected when starting OpenOCD which can set the SPI flash voltage to 1.8 V. In this situation, the SPI flash will not work after OpenOCD connects to the target as OpenOCD has changed the SPI flash voltage. Therefore, you might not be able to flash to the target when OpenOCD is connected.

To work around this issue, users are suggested to use board/esp32-wrover.cfg for ESP32 boards/modules operating with an SPI flash voltage of 1.8 V, and board/esp-wroom-32.cfg for 3.3 V. Refer to ESP32 Modules and Boards and Set SPI Flash Voltage for more details.

(For any technical queries, please open an issue on GitHub. We will get back to you as soon as possible.)