{"id":4086,"date":"2018-07-18T14:14:48","date_gmt":"2018-07-18T21:14:48","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=4086"},"modified":"2025-09-09T19:29:28","modified_gmt":"2025-09-10T02:29:28","slug":"using-esp32-application-trace-with-visualgdb","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/esp32\/apptrace\/","title":{"rendered":"Using ESP32 Application Trace with VisualGDB"},"content":{"rendered":"<p>This tutorial shows how to use the ESP-IDF Application Trace feature (apptrace) to route the\u00a0debug output from your program into Visual Studio.\u00a0In this\u00a0tutorial we will create a basic &#8220;Blinking LED&#8221; project, extend it\u00a0to produce debug output and show how to view this output with VisualGDB. Before you begin, install VisualGDB 5.4 Preview 3 or later.<\/p>\n<ol>\n<li>Start Visual Studio and open the VisualGDB ESP-IDF Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/01-project.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4087\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/01-project.png\" alt=\"01-project\" width=\"941\" height=\"653\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/01-project.png 941w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/01-project-300x208.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/01-project-392x272.png 392w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/01-project-130x90.png 130w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/a><\/li>\n<li>Proceed with the default &#8220;Create a new project based on a sample project&#8221; setting:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/02-newproject.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4088\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/02-newproject.png\" alt=\"02-newproject\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/02-newproject.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/02-newproject-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><\/li>\n<li>On the next page select your ESP32 toolchain and the ESP-IDF checkout:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/03-toolchain.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4089\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/03-toolchain.png\" alt=\"03-toolchain\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/03-toolchain.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/03-toolchain-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><strong>Update:<\/strong> For better compatibility with the latest ESP32 tools, we recommend selecting the <a href=\"https:\/\/visualgdb.com\/documentation\/espidf\/consolidated\/\">consolidated toolchain<\/a> instead.<\/li>\n<li>Then select a sample you would like to\u00a0use to create your project.\u00a0In this tutorial we will use the simplest &#8220;blink&#8221; sample:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/04-blink.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4090\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/04-blink.png\" alt=\"04-blink\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/04-blink.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/04-blink-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><\/li>\n<li>Connect your\u00a0debug adapter to\u00a0the board and plug it into the USB port. VisualGDB will automatically detect it and pick the correct OpenOCD settings. Click &#8220;Test&#8221; to verify the connection:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/05-devkit.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4091\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/05-devkit.png\" alt=\"05-devkit\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/05-devkit.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/05-devkit-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; to create the project. Initially\u00a0the IntelliSense will show several errors due to missing sdkconfig and other files. Build the project to generate all\u00a0necessary files and resolve IntelliSense errors:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/06-created.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4092\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/06-created.png\" alt=\"06-created\" width=\"1264\" height=\"808\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/06-created.png 1264w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/06-created-300x192.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/06-created-1024x655.png 1024w\" sizes=\"(max-width: 1264px) 100vw, 1264px\" \/><\/a><\/li>\n<li>Now we will demonstrate how to modify the project to produce debug output. First, include the &lt;esp_app_trace.h&gt; and &lt;string.h&gt; files. Then modify the main program loop to have a counter and add the following code inside\u00a0it:\n<pre class=\"\"> char buffer[128];\r\n sprintf(buffer, \"Iteration %d\\n\", i);\r\n esp_apptrace_write(ESP_APPTRACE_DEST_TRAX, buffer, strlen(buffer), ESP_APPTRACE_TMO_INFINITE);\r\n esp_apptrace_flush(ESP_APPTRACE_DEST_TRAX, ESP_APPTRACE_TMO_INFINITE);<\/pre>\n<p>Note that\u00a0unless you\u00a0explicitly call esp_apptrace_flush() after\u00a0writing the debug output, it won&#8217;t be immediately sent to VisualGDB.<\/li>\n<li>If you\u00a0try building the project now, it\u00a0will fail due to missing implementations of the <strong>esp_apptrace_write()<\/strong> function:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/07-missing.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4093\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/07-missing.png\" alt=\"07-missing\" width=\"1264\" height=\"808\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/07-missing.png 1264w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/07-missing-300x192.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/07-missing-1024x655.png 1024w\" sizes=\"(max-width: 1264px) 100vw, 1264px\" \/><\/a><\/li>\n<li>In order to fix this, open VisualGDB Project Properties and set the &#8220;<strong>Data Destination<\/strong>&#8221; under &#8220;<strong>ESP-IDF Project -&gt; ESP-IDF Configuration -&gt; Component Config -&gt; Application Level Tracing<\/strong>&#8221; to &#8220;<strong>Trace memory<\/strong>&#8221; (ESP-IDF 4.x) or &#8220;<strong>Data Destination 1<\/strong>&#8221; to &#8220;<strong>JTAG<\/strong>&#8221; (ESP-IDF 5.x) :<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/08-tracemem1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4097\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/08-tracemem1.png\" alt=\"08-tracemem\" width=\"870\" height=\"627\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/08-tracemem1.png 870w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/08-tracemem1-300x216.png 300w\" sizes=\"(max-width: 870px) 100vw, 870px\" \/><\/a><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/08-tracemem.png\"><br \/>\n<\/a>This will enable the apptrace mechanism &#8211; any data\u00a0stored via <strong>esp_apptrace_write()<\/strong> function will be placed into a special trace buffer that could be read by VisualGDB without stopping your program.<\/li>\n<li>In order to view the debug output in VisualGDB, enable it via Embedded Debug Tweaking -&gt;\u00a0ESP32 Application Trace -&gt; Semihosting Console Support:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/09-semihost1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4098\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/09-semihost1.png\" alt=\"09-semihost\" width=\"963\" height=\"710\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/09-semihost1.png 963w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/09-semihost1-300x221.png 300w\" sizes=\"(max-width: 963px) 100vw, 963px\" \/><\/a><\/li>\n<li>Now you can build and start debugging your project. The output sent via the <strong>esp_apptrace_write()<\/strong> function will appear in the <strong>Debug-&gt;Windows-&gt;VisualGDB Output-&gt;ESP32 Semihosting <\/strong>window inside Visual Studio:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/semihosting.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8004\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/semihosting.png\" alt=\"\" width=\"1208\" height=\"867\" \/><\/a><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/07\/09-semihost.png\"><br \/>\n<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to use the ESP-IDF Application Trace feature (apptrace) to route the\u00a0debug output from your program into<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[142],"tags":[138,168],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4086"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=4086"}],"version-history":[{"count":4,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4086\/revisions"}],"predecessor-version":[{"id":9044,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4086\/revisions\/9044"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=4086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=4086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=4086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}