{"id":1191,"date":"2018-10-01T21:19:42","date_gmt":"2018-10-01T20:19:42","guid":{"rendered":"http:\/\/EvertDekker.com\/?p=1191"},"modified":"2023-01-08T21:09:09","modified_gmt":"2023-01-08T20:09:09","slug":"esp32-jtag-debugger-with-sloeber","status":"publish","type":"post","link":"https:\/\/evertdekker.com\/wp\/?p=1191","title":{"rendered":"Esp32 jtag debugger with Sloeber"},"content":{"rendered":"<hr \/>\n<p>This is a step by step instruction to setup\u00a0<a href=\"http:\/\/eclipse.baeyens.it\/\">Sloeber<\/a> &#8220;The Eclipse Arduino Ide&#8221; with OpenOcd and a FTDI 2232HL as debugger. With this you can debug your Arduino sketch real time on an <a href=\"https:\/\/www.espressif.com\/\">Espressif<\/a> ESP32 in circuit with jtag.<\/p>\n<p>As hardware for the debugger I used 2232HL board from <a href=\"https:\/\/nl.aliexpress.com\/wholesale?catId=0&amp;initiative_id=SB_20180925131809&amp;SearchText=ft2232h\">Ali-express<\/a> , this one was around $14. However every board with a FTDI 2232hl will work.<br \/>\nThe 2232HL is a 3.3V device so don&#8217;t connect to 5V hardware or else the smoke will escape and the 2232HL will stop working.<\/p>\n<p>You need to connect it like this to your hardware:<br \/>\nAD0 &#8211; TCK (Gpio13)<br \/>\nAD1 &#8211; TDI (Gpio12)<br \/>\nAD2 &#8211; TDO (Gpio15)<br \/>\nAD3 &#8211; TMS (Gpio14)<br \/>\nGND &#8211; GND<br \/>\nOptional serial port:<br \/>\nCD0 &#8211; TXD (Gpio3)<br \/>\nCD1 &#8211; RXD (Gpio1)<\/p>\n<p><a href=\"https:\/\/evertdekker.com\/wp\/wp-content\/uploads\/slider52\/ftdi_ft2232hl.jpeg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/evertdekker.com\/wp\/wp-content\/uploads\/slider52\/ftdi_ft2232hl.jpeg\" alt=\"\" width=\"500\" height=\"343\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h4>Installing Sloeber \u201cThe Eclipse Arduino Ide&#8221;<\/h4>\n<ol>\n<li>Download <a href=\"http:\/\/eclipse.baeyens.it\/stable.php?OS=Windows\">Sloeber<\/a><\/li>\n<li>Extract the gz to the directory of your choice, in this tutorial we use <strong>c:\\sloeber<\/strong><\/li>\n<li>Let\u2019s setup some basic stuff for Sloeber.<\/li>\n<li><strong>Arduino<\/strong> -&gt; <strong>Preference<\/strong> -&gt; <strong>platform and boards<\/strong><\/li>\n<li>Check <strong>Arduino AVR boards<\/strong> and <strong>esp8266 2.4.2<\/strong> (or newer) both are not really necessary for the esp32, but it\u2019s nice to have some samples and libraries.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4>Installing Esp32 Arduino and Sdk<\/h4>\n<ol start=\"11\">\n<li>In Sloeber <strong>File<\/strong> -&gt; <strong>Import<\/strong> -&gt; <strong>Projects from git<\/strong> -&gt; <strong>Clone URI<\/strong> and copy the url\u00a0 <strong>https:\/\/github.com\/espressif\/arduino-esp32.git<\/strong> in the URI field.<\/li>\n<li>Press <strong>next<\/strong> and <strong>uncheck<\/strong> all the branches except <strong>master<\/strong>, press <strong>next<\/strong> again.<\/li>\n<li>Change the directory to <strong>C:\\sloeber\\arduino-esp32<\/strong> and press <strong>next<\/strong> again.<\/li>\n<li>Choose <strong>Import as general project<\/strong> and press <strong>next<\/strong> again.<\/li>\n<li>Let\u2019s add it to the ide, <strong>Arduino<\/strong> -&gt; <strong>Preferences<\/strong> -&gt; <strong>Platforms and boards<\/strong><\/li>\n<li>Press the <strong>new<\/strong> button next to the <em>Private hardware path<\/em> and enter <strong>C:\\sloeber\\arduino-esp32<\/strong> in the path box.<\/li>\n<li>Press <strong>Apply and close<\/strong><\/li>\n<li>Now we need to download the Esp32 sdk, browse with windows to <strong>C:\\sloeber\\arduino-esp32\\tools<\/strong> and click on <strong>get.exe<\/strong><\/li>\n<li>Done<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4>Replace the FTDI by Winusb driver<\/h4>\n<ol start=\"21\">\n<li>Download <a href=\"https:\/\/zadig.akeo.ie\/\">Zadig<\/a> , no need to install just run it.<\/li>\n<li>Click <strong>Options<\/strong> -&gt; <strong>List All devices<\/strong><\/li>\n<li>Choose in the dropdownbox <strong>USB &lt;-&gt; Serial Convertor (interface <span style=\"text-decoration: underline;\">0<\/span>)<\/strong>.Be careful here that you select the correct device.<strong><br \/>\n<\/strong><\/li>\n<li>Choose the <strong>WinUSB (V6.1.xxxx.xxxxx)<\/strong> driver and press the <strong>Install driver<\/strong> button<br \/>\n<em>Note: <\/em>For some reason sometimes (win update?, other usb port) windows will roll back to the original FTDI driver and you have to do this again.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4>Installing OpenOcd<\/h4>\n<ol start=\"31\">\n<li>Download OpenOcd for the Esp32 from <a href=\"https:\/\/github.com\/espressif\/openocd-esp32\/releases\">Github<\/a> (I have used 0.10.0 20180920 version)<\/li>\n<li>Extract the content to <strong>C:\\Sloeber\\Openocd<\/strong><\/li>\n<li>Download the <a href=\"http:\/\/evertdekker.com\/Joomla\/images\/stories\/Downloads\/quantum.zip\">cfg file<\/a> for the debugger and place it in <strong>C:\\sloeber\\openocd-esp32\\share\\openocd\\scripts\\interface\\ftdi<br \/>\n<\/strong><em>Note: <\/em>this file is for the Ftdi 2232HL based debugger that I have. For other debugger look in the C:\\sloeber\\openocd-esp32\\share\\openocd\\scripts\\interface directory. This cfg file can work with other Ftdi based hardware, but I can\u2019t guaranty nor support that.<strong><br \/>\n<a href=\"https:\/\/evertdekker.com\/wp\/wp-content\/uploads\/slider52\/debugdebuggertab.jpeg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/evertdekker.com\/wp\/wp-content\/uploads\/slider52\/debugdebuggertab.jpeg\" alt=\"\" width=\"400\" height=\"254\" \/><\/a><br \/>\n<\/strong><\/li>\n<li>Connect your debugger to the Esp32 hardware and let\u2019s see if it works by typing on the command line: <strong>C:\\sloeber\\openocd-esp32\\bin\\openocd.exe \u2013f c:\\sloeber\\openocd-esp32\\share\\openocd\\scripts\\interface\\ftdi\\quantum.cfg<strong><br \/>\n<\/strong><\/strong><a href=\"https:\/\/evertdekker.com\/wp\/wp-content\/uploads\/slider52\/cmdtestjtag.jpeg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/evertdekker.com\/wp\/wp-content\/uploads\/slider52\/cmdtestjtag.jpeg\" alt=\"\" width=\"400\" height=\"132\" \/><\/a><\/li>\n<li>If you get something as in the picture above with the \u201c<strong>device found \u2026..Tensilica<\/strong>\u201d in it you rock. The hardware and OpenOcd are working<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4>Setting up a new sketch<\/h4>\n<ol start=\"41\">\n<li>Lets start a new project, <strong>Arduino<\/strong> -&gt; <strong>new sketch<\/strong>, give the project a name and press <strong>next<\/strong><\/li>\n<li>Platform holder <strong>c:\/sloeber\/arduino-esp32<\/strong> , fill in the rest with the board etc you have. Port is the comport your board is connected to, not the jtag. Press <strong>next<br \/>\n<\/strong><a href=\"https:\/\/evertdekker.com\/wp\/wp-content\/uploads\/slider52\/newprojectsetting.jpeg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/evertdekker.com\/wp\/wp-content\/uploads\/slider52\/newprojectsetting.jpeg\" alt=\"\" width=\"402\" height=\"267\" \/><\/a><\/li>\n<li>Choose <strong>Sample sketch<\/strong> -&gt; <strong>example<\/strong> -&gt; <strong>01.basics<\/strong> and check <strong>blink<\/strong>. Press <strong>finish<br \/>\n<\/strong><\/li>\n<li>We need to set some build options for the debugger, <strong>right click<\/strong> on your project map, <strong>Arduino<\/strong> -&gt; tab <strong>compile options<\/strong> and enter in the <strong>append to C and C++<\/strong> field <strong>-ggdb -Og<\/strong>. These compiler options are not needed for a production version.<\/li>\n<li>Let\u2019s compile, press <strong>Arduino<\/strong> -&gt; <strong>verify<\/strong><\/li>\n<li>And upload it to your board <strong>Arduino<\/strong> -&gt; <strong>upload sketch<\/strong>. If you have a led connected to the pin as defined in the sketch is should blink now.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4>Setting up the debugger in Sloeber<\/h4>\n<ol start=\"51\">\n<li>Right click in the project explorer window on your project and choose <strong>Debug as<\/strong> -&gt; <strong>Debug configurations.<\/strong><\/li>\n<li>Choose <strong>GDB openOCD debugging<\/strong> and add a new configuration by clicking on the <strong>+<\/strong> at the left upper corner.<\/li>\n<li>On the debugger tab check <strong>Start OpenOCD locally<\/strong><\/li>\n<li>Executable path will be <strong>C:\\sloeber\\openocd-esp32\\bin\\openocd.exe<\/strong><\/li>\n<li>GDB port: <strong>3333<\/strong><\/li>\n<li>Add to Config options\u00a0<strong>-s C:\\sloeber\\openocd-esp32\\share\\openocd\\scripts -f interface\\ftdi\\quantum.cfg -f target\\esp32.cfg -c &#8220;adapter_khz 3000&#8221;<\/strong><\/li>\n<li>Check <strong>Start GDB session<\/strong><\/li>\n<li>Executable name for the GDB client will be <strong>C:\\sloeber\\arduino-esp32\\tools\\xtensa-esp32-elf\\bin\\xtensa-esp32-elf-gdb.exe<br \/>\n<\/strong><strong><br \/>\n<\/strong><\/li>\n<li>Select the <strong>Startup<\/strong> tab and set these settings<\/li>\n<li>Check<strong> Initial reset<\/strong>, Type: <strong>init<\/strong><\/li>\n<li>In the command box enter:<br \/>\n<strong>target remote:3333<\/strong><br \/>\n<strong>mon reset halt<\/strong><br \/>\n<strong>x $a1=0<\/strong><\/li>\n<li>Uncheck <strong>Enable ARM semihosting<\/strong><\/li>\n<li>Check<strong> load symbols<\/strong>, use project binary should be already have your project name<\/li>\n<li>Uncheck <strong>Load executable<\/strong>, <strong>debug in ram<\/strong>, <strong>Pre-run<\/strong>, <strong>Set program counter at (hex)<\/strong><\/li>\n<li>Set the checkbox <strong>Set breakpoint<\/strong> at and fill in textbox <strong>loop<\/strong><\/li>\n<li>Check <strong>Continue<br \/>\n<\/strong><strong><a href=\"https:\/\/evertdekker.com\/wp\/wp-content\/uploads\/slider52\/debugstartuptab.jpeg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/evertdekker.com\/wp\/wp-content\/uploads\/slider52\/debugstartuptab.jpeg\" alt=\"\" width=\"403\" height=\"302\" \/><\/a><br \/>\n<\/strong><\/li>\n<li>Press the Debug button and there you go<\/li>\n<\/ol>\n<p>You can also program the ESP32 automatic with the jtag before debugging, add in the command box as described in step 61. below the target remote:3333 line<br \/>\n<strong>monitor program_esp32 c:\/users\/evert\/Documents\/sloeber-workspace\/Testesp32\/release\/Testesp32.bin 0x10000 verify <\/strong><strong><br \/>\n<\/strong><em>Note<\/em><strong>: <\/strong>It was not possible to use in the command box Eclipse variable like {project_loc}, this would be handy so you don&#8217;t have to change every project the hard coded path. These variable like {project_loc} contains backslash &#8220;\\&#8221; and GDB expects forward slash&#8221;\/&#8221;. I did\u00a0 a lot of Google reading but couldn&#8217;t find a solution, if you have one let me know.<\/p>\n<p>&nbsp;<\/p>\n<h4>How to use it?<\/h4>\n<p>It&#8217;s a bit out of scope of this tutorial how to describe full the debug function in Sloeber. Because Sloeber is based on Eclipse there is enough videos etc available to help you out.<br \/>\nTo start a debug session you have to <strong>Right click your project<\/strong> -&gt; <strong>Debug As<\/strong> -&gt; <strong>Debug configuration<\/strong> and press <strong>debug<\/strong>. Sloeber will then switch to the debug perspective<br \/>\nAs a quick reference have a look at this:<\/p>\n<ol style=\"list-style-type: upper-alpha;\" start=\"A\">\n<li>Program code window, program is paused at loop(), this because we set this in step 65.<\/li>\n<li>Thread window, here you can see all the threads that are running on the Esp32.<\/li>\n<li>Control buttons, with these you can start, pause, stop and step in various ways trough your code.<\/li>\n<li>Perspective view, you can switch between code and debug perspective<\/li>\n<li>Various windows to see and influence variable, breakpoints etc. Peripherals is unfortunately not working yet.<\/li>\n<li>Some more windows here, cpu registers and Serial monitor view are the most used.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/evertdekker.com\/wp\/wp-content\/uploads\/slider52\/debugviewtxt.jpeg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/evertdekker.com\/wp\/wp-content\/uploads\/slider52\/debugviewtxt.jpeg\" alt=\"\" width=\"400\" height=\"217\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Note:<\/strong> If you copy the settings direct from this page watch out that punctuation marks\u00a0 like <strong>&#8220;<\/strong> and <strong>&#8216;<\/strong> are not copied correct (they have an other, wrong ascii value) and will give problems or error&#8217;s. Just retype them and it should work fine.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a step by step instruction to setup\u00a0Sloeber &#8220;The Eclipse Arduino Ide&#8221; with OpenOcd and a FTDI 2232HL as debugger. With this you can debug your Arduino sketch real time on an Espressif ESP32 in circuit with jtag. As hardware for the debugger I used 2232HL board from Ali-express , this one was around [&#8230;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[192],"tags":[196,157,197,194,195,193],"class_list":["post-1191","post","type-post","status-publish","format-standard","hentry","category-arduino","tag-eclipse","tag-esp32","tag-ftdi-2232hl","tag-jtag-debugger","tag-openocd","tag-sloeber"],"_links":{"self":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1191"}],"version-history":[{"count":84,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1191\/revisions"}],"predecessor-version":[{"id":1917,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1191\/revisions\/1917"}],"wp:attachment":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}