#274 Free Inline Debugging for ESP32 and Arduino Sketches

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Debugging is the missing link in Arduino development.

👍︎︎ 1 👤︎︎ u/Nexustar 📅︎︎ Jun 26 2019 🗫︎ replies
Captions
my maker world changed last week when I started my first inline debugging tool for an Arduino sketch free of charge nada bene you do not know what I'm talking about then you must watch at least the beginning of this video if you know what I'm talking about I'm sure you also want to have it create the youtubers here is the guy with the Swiss accent with a new episode and fresh ideas around sensors and microcontrollers remember if you subscribe you will always sit in the first row in this video we will end the cumbersome Arduino debugging process at least if we use the ESP 32 I will show you what inline debugging is and how it works and how it is done with an ESP 32 we all know how we debug our Arduino projects we use serial print statements to print values of variables or to mark positions in the sketch to find out the way you program travels through the code this is okay but has some severe disadvantages each time we want to look at another variable or the same variable in a different place we have to create new print statements and recompile the code very time-consuming if your sketch runs fast we cannot easily trace all information in serial monitor it's just too much finding out which way the Arduino travels through our sketch is really hard we cannot change variables when our code runs this would sometimes be a very efficient debugging method also here we have to recompile our sketch and most important we cannot stop our sketch in the middle of execution if it loops forever to find out the cause for that behavior inline debugging ends all this pain it is old technology I remember we used it in early 1980 with Intel's 8080 processors and assembly which back then such a development station costed a fortune already then the industry started to develop a standard called cheytac one of its purposes was to enable inline debugging but what is inline debugging it makes that we can stop the CPU in the middle of program execution and read or write variables registers and other stuff in short we get a window into what happens inside our microcontrollers and we can remotely start and stop program execution you think this is a minor thing then let me show how it works here I have a simple sketch it loops switches an LED on and off and increments three different variables a global one one defined in the loop section and one initialized in a function if we run the code the LED blinks and only one of three variables count up strange what is the problem we clearly see the increment commands in each loop and also the function is called in each loop let's use our new inline debugger to find the reason yes I know that the experienced amongst you already see the problem anyway we press start debugging and after uploading the sketch the debugger stops right at the beginning of setup yes you see right the ESP stopped the execution the LED is not blinking anymore and serial does not print we can now examine our variables global variable is already defined and its value is zero the other two variables are not yet initialized because our sketch did not reach the respective statements here we have our control center for debugging if I press Continue the LED starts to blink and serial prints precisely the same values as before it immediately stops if I press pause during running I do not see the content of the variables if I hit pause the ESP stops blinking and we see this screen because the processor stopped immediately we see here assembler code this yellow arrow shows at which address it stopped we have no idea where this is but still we were able to stop the processor from the outside if we go back to our sketch we can insert a breakpoint wherever we want the red dot says your sketch will stop here of course we can add more breakpoints if we wish if we press continue it stops at line 39 and should show a yellow arrow this does not always happen sometimes I had to press switch to code a few times maybe it's my fault or even and his crew from platform IO has some work to correct that anyway we see now also the local variable the functional variable is not in scope here and therefore not shown if I press continue we can watch what happens the loop is executed once the LED blinks the variable change and the sketch stops again at the breakpoint how cool is that the next thing is called step over you could also call it single step if we press it the sketch executes one line and we can watch what happens and really the local variable is incremented to one if we continue pressing step over we suddenly discover something strange we leave our sketch and arrive in a sketch from the ESP 32 core people who remember the video about dual cores of the ESP 32 remember the ESP 32 runs a artists operating system and the Arduino framework runs on that and really here we see artists asked by the way we see also how the watchdog reset is created we can't forget this excursion and press step over or f10 a few times until we are in the loop statement now we have to step into loop again and we are back in our main sketch after incrementing local variable it is 1 again which seems to be wrong but it is right if you define a variable even without assigning a value it forgets its value from before a beginner's mistake so we know that we have to shift this statement outside the loop after this change we should be able to restart debugging unfortunately this is the next item on Iran's list but when we stop and start debugging it works and local variable comes up of course it is no more a local variable now by the way delete all breakpoints before you start debugging they will no more work in the new session even if they are displayed if you are on a line with a function we can either press step over as before to stay on the current level or we can press step into to enter the function as soon as we are in we have to use step over to continue on this level because the function contains an if statement we can see which way the program selects according to led status the then or the else statements are chosen if you are interested in what our ESP does in the digital write statement you press step into and you are in the bowels of the Arduino platform you can dig as deep as you want down to the assembler code if you are fed up with the details you press step out and you're back where you were one level higher this also works with Europe functions like that you can navigate through running program and always watch what happens to the variables you even can change variables for example the LED blinks faster if we change Dell to 200 milliseconds to show you that effect I want that the sketch continuously run for five loops and then stops therefore I create a conditional breakpoint with the condition global variable equals 5 then I set global variable to zero this has to be done here you immediately see the result in the watch zone if I press continue the LED blinks five times and the sketch stops again really cool we only scratched at the surface but I hope you see that chasing errors is fun with such a tool no more unnecessary print statements and other tricks to influence the behavior of your ESP but what do you have to do to get this functionality first we need hardware inside the microcontrollers and then we need a software on our IDE and an adapter to connect them when I started Arduino I missed inline debugging the Atmel 328 chips used in arduino z' had no hardware to support debugging we shall micro once tried a compromise for the Arduino hardware they created a debugging software which before compiling automatically inserted certain statements into the code and used the output in the IDE with this we were able to get the feeling of inline debugging but still with a lot of compromises they were not able to change the flow of the Atmel chips no hardware support for cheytac debugging other platforms like arm offered such tools but they were very costly often too expensive for makers and like most of us I wanted to stick with all the Arduino advantages and not move to another ecosystem the esp8266 and the ESP 32 had built-in cheytac debugging functionality from the beginning up till now I never used it because I did not know of software which supported this interface until I made the video about platform IO there I discovered that platform IO offered a so-called Pio unified debugger based on the open source gdb project again what is gdb no it's not a wrongly written gross domestic product a favorite word of economists it stands for new debugger it is the de facto standard debugger for lino systems and a quite powerful tool it not only supports our es piece it supports many other architectures like arm and x86 now I only needed a jtag debug interface patreon restore mati suggested using the arm USB OCD module from the Bulgarian company Olympics it is not exactly cheap and back then platform IO also wanted a service fee for the debugger all in all still not very mega friendly but now it comes last Wednesday I got this mail from even the CEO of platform IO thanks to an investment of Western Digital the platform IOT bugger is now free of charge for makers cool maybe next time you buy one of their disk drives instead of another brand to say thank you to them and I found a much cheaper cheytac debugger which seems to be from expressive and is also supported by platform a o it only costs $20 including shipping and is available on Aliexpress so I had no excuses had to roll up my sleeves and invest a night or two with some help of Valerie and even from the platform IOT m-- i was able to prepare what i showed you before and as usual if you follow the instructions in this video you should be able to avoid most of the problems I encountered first we have to look at the jtag connector all Emacs uses a twenty pin and the expressive board uses a ten pin header fortunately we only need five or six pins they are called TDI TD o TC k TMS and reset of course we also need grant reset is only required for the olymic sport the expressive part has a readable silkscreen and you know which pins are which only makes provides only a drawing of the connector unfortunately it is mirrored so pay attention pin one is here I created a connector for each port with an IDC connector on one side and DuPont pins on the other the ESP 32 uses pins 12 to 15 for the JTAG interface and you must not use these pins in your sketch otherwise you create big trouble I know what I'm talking about and here you see why it would not make a lot of sense to use JTAC debugging for the esp8266 you would not have many pins left for your project if the debugging interface already takes four of them now you connect your cheytac programmer to your pc the device manager does not show it because it has the wrong drivers assigned we have to use static to replace these drivers pay attention if you change the USB location you plucked your cheytac programmer in maybe you have to repeat the procedure you find a link in the description if you have to install static in static click show all devices in options and search for all Emacs or for dual rs-232 and replace the drivers with when USB drivers theoretically you only need to do it for interface 0 but I did it for both interfaces both programmers offer an additional serial connection on interface 1 which can be used to program your es piece but this is stuff for another video now you should see two new USB devices in your device manager next you have to connect the two point pins to your ESP 32 check it twice it will not work with the slightest mistake as said before I know what I'm talking about next you have to install platform io you can watch my video if you want to save time create a small project as shown before or use an existing one and check that you do not use pins 12 to 15 the last thing you have to do is to add two lines in the file platform IO dot ini' yes you heard right only add two lines and your debugger should work for the Ahly makes you add this line and for the expressive port that one for both you add this line to start debugging right at the start of your sketch otherwise you start debugging somewhere in our toes that's it as Neil Armstrong said after he landed on the moon that's one small step for a man one giant leap for mankind one last thing newer Arduino x' seemed to also support JTAC maybe we will be able to use this tool also for them in the future I hope this video was useful or at least interesting for you if true please consider supporting the channel to secure its future existence you find the links in the description thank you bye you
Info
Channel: Andreas Spiess
Views: 116,730
Rating: 4.9623961 out of 5
Keywords: arduino, arduino project, diy, do-it-yourself, electronics, esp32, esp32 datasheet, esp32 project, esp32 tutorial, esp8266, esp8266 project, how to, iot, lorawan, nodemcu, project, simple, smart home, ttgo, wemos, wifi, platformio, inline debugger, inline debugging, Inline debugging ESP32, Inline debugging Arduino, Inline debugging ESP8266, debugging arduino, debugging ESP32, debugging ESP8266, JTAG, JTAG debugger, JRAG arduino, JTAG esp32, JTAG esp8266
Id: psMqilqlrRQ
Channel Id: undefined
Length: 17min 45sec (1065 seconds)
Published: Sun Jun 23 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.