KB 03: Keil Debugging Issue
Cannot Enter Debug Mode
If the system is not working as expected, you must use real-board debugging to track the code. Keil supports hardware debugger by selecting hardware debugging interface from Options for Target ➤ Debug as shown in Figure 1.
Figure 1: Selecting Hardware Debug
Next, you have to build the code. If there is no error, then click the debug button to start the debug and click it again to exit the debug.
When trying to enter hardware debugging mode on Keil μVision, the debugger immediately exits upon entering. Keil can still download object code, but will not run the debugger. Usually, this problem occurs after a while when the Keil debugger is working properly.
The following steps can fix the error:
- Open windows registry:
Open Command Prompt window. On the screen type regedit.exe to open Registry Editor. The contents should look similar to the image below:
- In the Registry Editor, search for the directory:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
- If there is a similar entry to the following items below (the name will depend on the version and the folder you installed Keil), and select the entry
C:\Keil_v5\UV4\UV4.exe REG_SZ $ IgnoreFreeLibrary <lmidk-agdi.dll>
then remove it.
- Reboot the computer and then try again.
Debugger Starts in Startup code, not main() code
You are trying to debug the code in Keil. When you click the Debug button, the debugger stop at the system_TM4Cxxx.s (Startup) or system_TM4Cxxx.s (Startup), not stop at your main code. No matter how much you press iterate, the debugger never moves to your main code to debug.
Solution:
- At first, make sure the Load Application at Startup and Run to main() both are checked in the Debug option. Then, rebuild the code and click Debug again.
- If the debugger still cannot stop at your main code, the possible reason is due to the following macro code in the system_TM4Cxxx.c is set to 1:
#define CLOCK_SETUP 1
This leads to the execution of the SystemInit(void) function first thing the debugger starts.
There are two solutions to solve this problem:
- Change the definition:
#define CLOCK_SETUP 1
to
#define CLOCK_SETUP 0 - Or open the system_TM4Cxxx.c file, click the Configuration Wizard tab, then uncheck the Clock Configuration item.
- Change the definition:
- Rebuild the code and click Debug again.