{"id":1782,"date":"2026-09-18T15:33:14","date_gmt":"2026-09-18T15:33:14","guid":{"rendered":"https:\/\/socmaker.com\/?p=1782"},"modified":"2026-10-01T18:21:35","modified_gmt":"2026-10-01T18:21:35","slug":"mac-esp32-platformio-jlink-esp-prog2","status":"publish","type":"post","link":"https:\/\/socmaker.com\/?p=1782","title":{"rendered":"Mac: ESP32 &#8211; PlatformIO &#8211; JLink &#8211; ESP-PROG2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This post is for you if you can get the esp32 blink project to load and run and blink the blue light, but debugging with hardware  is a problem, and using printf has issues with the &#8220;monitor.&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I was able to get the blink program to run under Arduino, but debugging was a pain.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With the older ESP32, you have to use an external JTAG Debugger.  Unfortunately, the latest ESP32 units cannot handle classic bluetooth.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Quick Note: VSCodium will work with platformio, but the clangd massively errors out.  I was getting 18 to 36 errors from clangd (similar in features to Intellisense C\/C++), along with no ability to look at library header files (even though the compile was error free).  Switching to VSCode fixed that.  Turn off Telemetry if you use VSCode (in settings), unless you are ok with MS getting real time snapshots of what you are doing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Under PlatformIO, I loaded the bluetooth example and had garbage print on the &#8220;monitor&#8221; before the Serial.println() came out, when using a classic bluetooth example project. I never saw that with the standard blink project.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> I saw several posts out there that had that particular issue.  The solution for me was to add a couple of lines to the platform.ini file for my esp32 board.  Those lines are monitor_dtr and monitor_rts.  Once I did this, it appeared to stop the garbage printing before my debug printf() lines were able to print my messages.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Inside the PlatforIO.ini file for jlink:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;env:esp32doit-devkit-v1]\nplatform = espressif32\nframework = arduino\nboard = esp32doit-devkit-v1\nmonitor_speed = 115200\nmonitor_dtr =0\nmonitor_rts = 0\n# JLINK to ESP32 pins\n# Signal. JlinkPin  ESP32Pin\n#  TDI.     5         D12\n#. TMS.     7         D14\n#  TCK.     9         D13\n#. TDO.     13.       D15\n#JLINK CAN INTERRUPT.  PROG2 CAN also\ndebug_tool = jlink\n#leave upload_protocol undefined to use UART upload\nupload_protocol = jlink<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">NOTE1: (deja vu:) If jlink does not initially work to upload or debug, upload a beginning program to the ESP32 using the serial port. I use the arduino Blink example for my board, because there is an LED on it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">NOTE2: If you have a SECOND VSCode (or VSCodium) window open, jlink debugging will fail.  I have also seen esp-prog2 debugging fail.  Close VSCode or VSCodium and run a terminal window.  In the terminal, run <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ps ax | grep code<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you see a lot of <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>12632   ??  S      0:01.42 \/Users\/me\/.platformio\/penv\/bin\/python -m platformio -c vscode home --port 45359 --host 127.0.0.1 --session-id 1977e5a6f3ba6a985ea3fa538cad367ec1382c6c --shutdown-timeout 3600 --no-open\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">then use <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kill 12632<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">to stop those python sessions, where 12632 is the number at the far left of the line that grep showed.  Run VSCod* again and then you should be able to debug.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Currently Programmed ESP being Repurposed<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For some reason, a lot of the programs available for the ESP32 seem to disable jlink. This may be due to a pin being use as an output (where JTAG needs it as an input), and the reset on the EN line may or may not overcome that preset. It could also be that jlink sees activity and refuses to operate. (I have also been able to use the &#8220;boot&#8221; button, but that is a pain and not always available or reliable.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To fix this, upload the blink program (or the hello world program) over the usb serial port and restart the esp32.  You may or may not need to restart VSCode.   VSCode can get lost to the point the whole machine needs to be rebooted.   The upload of a simple demo progarm has fixed jlink debugging for me nearly every time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once the garbage printout was resolved, I started working on debugging hardware.  Note that garbage is probably due to the echo of the Serial Port firmware update.  Once you switch to jlink or esp-bridge (or esp-builtin) the garbage does not seem to show up.  The PlatformIO still has a way to go.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I used jumper wires to go from the jlink connector to the ESP32 on a plugin breadboard. After many trials, I finally was able to get jlink working with PlatformIO at home.   I brought the project to the office, and it worked. The project I created at the office still does not work with jlink. Don&#8217;t know why, and don&#8217;t care.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PlatformIO does not know about ESP-PROG2, but no worries.  Use esp-bridge.  That worked for me.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br>Again, inside the PlatformIO.ini file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;env:esp32doit-devkit-v1]\nplatform = espressif32\nframework = arduino\nboard = esp32doit-devkit-v1\nmonitor_speed = 115200\n# esp-bridge allows ESP-PROG2 to work\n# esp-prog2 allows for breakpoint setting while running.\n# that does appear to work with jlink, also.\ndebug_tool = esp-bridge\n#upload_protocol = esp-bridge\ndebug_init_break = tbreak setup\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The &#8220;tbreak setup&#8221; causes a temporary breakpoint at the setup() function in the blink project.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Warning About Bluetooth<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">I loaded the Arduino bluetooth project and compiled it and loaded it. Disaster. Monitor program showed lots of trash. Serial.println() did not work well. Single Step failed a lot. Bluetooth did not work. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There were lots of posts on the internet complaining that Bluetooth Classic did not work.  Some complaints of trash on the monitor.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After about a dozen search queries, I found a github page that I should have located from the beginning with bluetooth classic functionality for Arduino. The project linked below contained an ino file that I was able to pull from.  I ignored it at the beginning because I was using ESP-IDF and had not yet understood the .ino file format.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(For you classic &#8220;C++&#8221; programmers, a file with .ino ending is a CPP file that is managed by the Arduino project manager. It is simply another way to package a source code file. Underneath that file is a &#8220;main.cpp&#8221; that sets up the base environment in the app_main() function which calls setup() and loop(). For ESP32, the environment running the &#8216;system&#8217; is FreeRTOS. You can immediately start using FreeRTOS calls, etc. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The main difference between original FreeRTOS and this version (which was modified to support dual-core processors) is a processor core affinity. You chose which core you want your task to run on.  Be mindful to use flags and semaphores to coordinate data transfers.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Include the &lt;Arduino.h&gt; in your file and the correct bluetooth includes, and you can start using Bluetooth. You may or may not have to use PlatformIO to bring in libraries. After a certain amount of mucking around, stumbling in the dark, I was able to get bluetooth to work.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the page and project link: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/espressif\/arduino-esp32\/blob\/master\/libraries\/BluetoothSerial\/examples\/DiscoverConnect\/DiscoverConnect.ino\">https:\/\/github.com\/espressif\/arduino-esp32\/blob\/master\/libraries\/BluetoothSerial\/examples\/DiscoverConnect\/DiscoverConnect.ino<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I took that code and put it piecemeal into the Arduino Blink project, a few lines at at time, compiling as I went.  It is much easier to get bugs out that way, and with 2 to 3 seconds per compile on my iMac, not a time waster.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It worked.  Printout worked.  No trash on the monitor.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I believe the Arduino Bluetooth example project is misconfigured and fails quite a bit.  I suspect stack overflows and other issues.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once I started modifying the Arduino Blink, I was able to get the Bluetooth stack to connect to an OBDII mini, query it, and get a response.  I found that when I re-ran the project, the name of the OBDII mini sometimes disappeared. That may be a stack bug or a mini bug.  Regardless, if you don&#8217;t find the bluetooth unit you are looking for, re-run the Async Discover.  It almost always works the second time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you use ESP32-S3 for anything, the built in debugger is accessed by the following line in the PlatformIO.ini file, replacing the jlink or esp-bridge.  The ESP32-S3 does NOT do classic bluetooth with SPP.   (The brand new S31 will in the future, but it is still in beta as of August 2026, and I understand it has bugs.)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>debug_tool = esp-builtin<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Fini<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The ESP32 is a remarkable and cheap system. The FCC approval on the module allows you to use the project without having the expense of dealing with FCC testing, and without breaking the law. I&#8217;ve been down that FCC Testing road and if you get a bad testing facility in, for example, Texas, you can be beating your head against the wall with no success. That facility had external signals bleeding into the test room.  We never passed in that facility.  We passed the first time in a California facility&#8230;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Some California testing facilities are better and cheaper, and go the extra steps to make sure your product works without having more &#8220;test fees&#8221; added on top of your development costs. We received cable modification hints, etc.  You have been warned.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The main problem you will have in dealing with the ESP32 is the large amount of information you have to process before you can get the unit to do what you want. The official information is fragmentary and sometimes not quite right. The unofficial forums that provide information can be fairly acerbic, so you need a thick skin for some of the more biting replies.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bluetooth works, just don&#8217;t use the official projects.  Make your own and test step by step so you can verify each section as not being a problem.  Especially when using asynchronous&#8230;..<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">NOTE: BLUETOOTH HATES SINGLE STEPPING.   If you have a bluetooth connection, single stepping after a breakpoint will disconnect you and ruin your evening.  Restart the processor completely after each breakpoint is triggered.  You are welcome.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ENJOY!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post is for you if you can get the esp32 blink project to load and run and blink the blue light, but debugging with hardware is a problem, and using printf has issues with the &#8220;monitor.&#8221; I was able to get the blink program to run under Arduino, but debugging was a pain. With [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1782","post","type-post","status-publish","format-standard","hentry","category-blogposts"],"_links":{"self":[{"href":"https:\/\/socmaker.com\/index.php?rest_route=\/wp\/v2\/posts\/1782","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/socmaker.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/socmaker.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/socmaker.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/socmaker.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1782"}],"version-history":[{"count":19,"href":"https:\/\/socmaker.com\/index.php?rest_route=\/wp\/v2\/posts\/1782\/revisions"}],"predecessor-version":[{"id":1811,"href":"https:\/\/socmaker.com\/index.php?rest_route=\/wp\/v2\/posts\/1782\/revisions\/1811"}],"wp:attachment":[{"href":"https:\/\/socmaker.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/socmaker.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/socmaker.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}