Tutorial 3 Keil Debugger
Tutorial 3 Keil Debugger
Tutorial 3 Keil Debugger
ISBN 0982692625
Debug Control
You can program the STM32 flash by clicking the LOAD button
to start the debug and click it again to exit the debug. You can use the
breakpoint button
to set a break point in either disassembly or source windows.
STM32 allows up to six breakpoints during hardware debugging. When a program stops at a
breakpoint, the corresponding instruction has not been executed yet.
If the disassembly window is in focus, the debugger executes assembly instructions step by step. If
the source window is focused, the debugger then steps through the source lines instead.
Set a
Breakpoint
Run
Stop
Debug
Step In
Step Over
Step Out
Run: Continues the execution from the current position until you click Stop or the program is paused
by a breakpoint.
Step In: Execute one step and enter the function if the current step calls a function.
1
ISBN 0982692625
Step Over: Execute one step and run the function all at once if the current step calls a function.
Step Out: Execute until the current function returns.
Memory Window
The memory window is used to view the memory content in real time. By default, the address of data
memory (RAM) starts at 0x2000_0000. This is specified in the scatter-loading file (*.sct).
The following assembly program defines and allocates an array of four words. Each word consists of four
bytes. When we type the memory address 0x20000000, we can see the content of this array.
AREA
myData, DATA, READWRITE
ALIGN
array DCD
1, 2, 3, 4
The memory content is displayed in bytes by default.
By right click, we can select different display format. For example, we can show the content as unsigned
integers.
2
ISBN 0982692625
ISBN 0982692625
Processor Registers
Core Registers:
Program counter (PC) r15 holds the memory
address (location in memory) of the next
instruction to be fetched from the instruction
memory.
Stack point (SP) r13 holds a memory address
that points to the top of the stack. SP is a
shadow of either MSP or PSP.
xPSR (Special-purpose program status
registers) is a combination of the following
three processor status registers:
Application PSR
Interrupt PSR
Execution PSR
N
ISBN 0982692625
Peripheral Registers
From the menu: Peripherals System Viewer, we can view and update the control and data registers of all
available peripherals. The following figures show all registers for GPIO Port A, such as mode register
(MODER), output type register (OTYPER), Output Speed Register (OSPEEDER), Input Data Register (IDR) and
Output Data Register (ODR). This provides great conveniences for debugging.
ISBN 0982692625
Logic Analyzer
The Logic Analyzer can display the history values (trace) of static or global variables over runtime. Local
variables cannot be displayed. The value stored in a register cannot be analyzed.
In the following program, we use logic analyzer to monitor a variable output defined in the data area.
EXPORT output
output
In the Logic Analyzer, you can click Setup and add a variable (signed int)output to observe. Make sure to
adjust the data display range to show the curve. Logic analyzer can only monitor global variable. Thus you
need to add "EXPORT output" to make the output as a global variable.