Embedded system program debugging [Recommendation: Serial Monitor]
Table of contents
Debugging as an operation check
After the program transfer is successfully completed, the program operation is checked on the actual device configured with hardware as an embedded system. For those who are familiar with programming, this is called debug, which probably does not need to be explained again. If the program size is too large, debugging will be difficult, so it is advisable to do it at a good interval.
If the program is single-functional and simple, it is almost complete at this stage. However, for applications with a certain degree of multifunctionality and complexity, it is necessary to check whether the functions envisioned in the design are being carried out correctly. This work is called Debugging.
Debugging is a very simple, delicate, and patient process. It is also a battle against yourself. It can take several days to solve one problem. Programs are digital technologies that are structured logically, so even a single character error can prevent the program from working properly. There is always a cause for a bug, so please do your best to pursue it.
In the case of embedded systems, debugging with hardware operation is required, so we also make full use of our knowledge of hardware.
Unlike PC programming, embedded systems do not have a display monitor, so debugging using the so-called printf statement for Windows and other operating systems is not possible. Nevertheless, there are times when you want to somehow check the contents of a variable that contains the result of an operation.
To achieve this, a debugger that comes with the integrated development environment may be used, but its drawback is that it is difficult or impossible to use for interrupt processing, which is often used in embedded systems.
This debugger is useful for checking normal program flow and variable contents. The tools are the same as those used for writing.
Therefore, the method that I relied on the most when debugging is called Serial Monitor. This can be easily achieved if MCU is capable of using USART.
A peripheral UART is prepared for serial monitoring, and information such as numerical values and characters to be checked in the program are output to the PC via serial communication for display. Although it is necessary to be familiar with the use of serial communication to use this method, it is quite useful.
The only hardware preparation required is a UART-USB conversion cable to connect the microcontroller to the PC. On the PC side, general-purpose terminal emulator is prepared to display characters sent from MCU via serial communication.
Another effective way to check whether a program is progressing normally as expected is to insert some output (e.g., turn on an LED) immediately after a certain conditional branch.
Although a program can only work as written, it often does not work as expected because of a lack of interpretation of various conditions or the use of standard functions themselves.
I know you may get stuck in debugging, but don't compromise, trusting that there is always a cause.
Although there is no information that cannot be obtained from the Internet today, do not adopt information from others without understanding it. Use the information only as a hint, and be sure to understand and improve it so that you can use it yourself.
If you leave it as a black box, you may not be able to avoid unexpected pitfalls later on. If you always get into the habit of thinking for yourself, you will gain wisdom and power. This is what skill improvement means.