This article describes how to create a debug interface for various microcontrollers. At the moment, you can debug your program through jtag, having a special debugger (JLINK, FT232 JTAG, STLINK, etc.). My idea is to debug the program through any interface of the microcontroller, even emulated, including remote interfaces such as GPRS, Wifi, Lora, etc. A typical debugging scheme looks like this.

My debugging scheme looks like this.

A similar scheme is used to debug Xtensa l106 microcontrollers (ESP8266), where debugging is performed via the uart interface. My idea is more extensive. I came up with how to implement this scheme not only on Xtensa, Cortex-M microcontrollers that have hardware support, but also microcontrollers that do not have such support, for example, AVR. The general algorithm looks like this, we flash the microcontroller and debug our program through the interface that is implemented in the firmware. It is also possible to reprogram the microcontroller through the same interface, in my opinion this makes sense if the interface is remote, if it is wired interface, better program  through the programmer and you still need it at least once. The source code of the interface and the debugger core itself are compiled with the user program.

The main idea is to create a 2-threaded application, each thread has its own stack, I refused to use the heap in the debugger stream (because this creates additional problems associated with the intersection of the end of the heap pointer and the current pointer to the stack from the options of constantly switching to user thread when allocating memory or additionally writing your own heap for debugger thread, and most importantly, when problems like stack overflow arise, it will not be known which thread did this, from my own experience I tested this option in practice, it’s better not to use the heap when writing the debug kernel) threads switch by timer. One thread for debugging, another main program.

Site language: