
R&D FIELD APPLICATION ENGINEER
Many people working on embedded systems have rarely encountered programs coded for their projects that function without errors the first time. The debugging method that we need to code a program that runs error-free and stable is called “debug”, and every compiler has this feature in its own structure. Keil is one of these compilers. The number of lines of code written varies according to the scope of the project. In projects with a broad scope and multiple scenarios, the number of lines can be thousands. It will not be possible to find the source of the error among thousands of lines by trial and error method. In this case, the debug feature meets our needs to the fullest. With this feature, it is possible to solve errors and reach results quickly by debugging the code line by line. Nuvoton, which Ozdisan Elektronik is a distributor of, offers 2 types of debugger solutions as NU-LINK and NU-LINK-PRO. In the near future, the NU-LINK2 option developed by the company will also be offered to consumers. In order for the debug feature to be used, the “VCC-DATA-CLOCK-RESET-GND” pins of the processor and the debugger need to be connected to each other. In the following sections, we will talk about the parts related to debugging via the Keil compiler using NU-LINK-PRO.
Debugging in Keil

In order to activate the debug feature in Keil, after launching the program press CTRL + F5 or follow the “Debug” à “Start/Stop Debug Session” steps in the upper section.
If you want the program to stop on a line during debugging, you can set a “breakpoint” by left-clicking on that line twice in a row. In the following example, the program will stop on 46th line while it is running.

The “RST” option on the upper left is used to reset the program, the “RUN” option to start the program, the “STOP” option to stop the program, the “STEP” option to enter the function and run it line by line, the “STEP OVER” option to run it in a single step without entering the function and to move on to the next function, and the “STEP OUT” option to exit the running function.


The variables to be observed during debugging can be selected and added to the Watch1 window by following the “Add ‘variable name’ to Watch1” step with the right click. Also, whichever UART channel is activated can be selected from the “Serial Window” section and the value of the variable whose change will be observed can be followed from this window with the “printf” command.
Non-Reset Debug Mode

If an unexpected resetting problem occurs during the operation of the program, the source of the problem can be found and resolved thanks to this feature. What needs to be done to activate this mode:
- Follow “Options for target→debug → Nuvoton Nu-Lınk Debugger Settings → Reset Options →Reset” steps and select “None”.
- Go to “Options for target → Utilities”, and select “Update Target Before Debugging” to cancel.

Once these steps are completed, the program is executed and when it resets unexpectedly the cause of the reset can be accessed via the “System Reset Source Register”. To access this register, Memory1 is selected via Memory Windows and the value 0x50000004, which is the register address, is entered. Then the value of the register is displayed, and according to this value, the source of the reset is detected.
As can be seen in the figure below, the first byte value of the register is 43. In order to interpret this value, we look at which definitions the first byte of the register corresponds to. These definitions are given in Figure 8.

The value 43 means that 0, 1st and 6th bits are 1. Based on this, it can be assumed that the reset source of the system is the low-level withdrawal of the “nRST” pin. Thanks to the non-reset debugging feature by Nuvoton, many projects where reset problems could not be detected can now be easily detected and resolved.




