This tutorial will show you how to use the built-in logic analyzer in Kail.
We can view up to 4 variables graphically in the logic analyzer.
These variables must be global, static, or raw addresses.
This is the STM32L4 discovery kit.
It has an on-board ST-Link debugger and L4 ARM Cortex-M4F microcontroller.
Let's see how these two components communicate with each other.
Arm Cortex-M micro-controllers use the Arm CoreSight debug module.
The CoreSight module provides powerful debug and trace capabilities.
It has two interfaces: the debug interface and the trace interface.
The debug interface can be used to start and stop a program, execute one line of source
code, set hardware breakpoints, read and write memory and peripheral registers on-the-fly.
The trace interface provides program counter sampling, data trace, and event trace information.
This trace interface does not steal any CPU cycles and is completely non-intrusive
except for printf.
A serial wire debugger gives the host PC full access to the CoreSight debug module.
The debugger connects to the debug interface via two wires: SW Data Input/Ouput, and SW Clock
The debugger connects to the trace interface via a single wire: SW Output.
ST-Link V2 is a serial wire debugger.
The ST-Link debugger is connected to the STM32L4 microcontroller via pin PA 13, PA 14, and PB 3.
If software mistakenly changes the mode or alternate function of these pins, the debugger
will fail to program or debug the microcontroller.
Unfortunately, the SWO pin of the microcontroller is not connected to the ST-Link on the board.
The SWO pin, PB.3, is connected to T_SWO via the solder bridge 14, which is disconnected
by default.
Therefore, we need to do a little soldering work to connect two soldering pads of Solder Bridge 14.
Here is what SB14 looks like after we solder it.
Now, let's demo how to use the logic analyzer in Keil.
This is a simple program.
After setting up SysTick and GPIO, the main program repeatedly toggles the red LED every second.
The delay() function is implemented by using SysTick interrupts.
To use the logic analyzer, we need to enable tracing in the debug setting first.
Click the icon Options for Target,
Select the debug page,
Make sure ST-Link debugger is selected,
Click settings,
Go to the trace page, enter the core clock frequency.
Make sure that this frequency matches the processor core frequency set by your software.
The debugger uses this value to calculate timings for trace capturing and displaying.
Since my software sets the Cortex-M4 core to run at 8MHz, I put 8MHz here.
Next, select Trace Enable to capture traces via SWO pin.
Click OK to save and exit the debug configuration.
Next we will configure logic analyzer.
The logic analyzer can only be configured in the debug process.
Click the debug icon to start the debug.
Go to menu View
Analysis Windows
select Logic Analyzer
click the button Set up.
We can view up to 4 variables graphically in the logic analyzer.
These variables must be global, static, or raw addresses.
First, let's get the trace of a global variable defined in my C program.
This variable is called msTicks.
Click New, type msTicks, hit enter
Highlight this variable,
change the maximum value to 1000
because that is the maximum we can give.
click close
click run
I have shown you how to trace a global variable.
We can also trace data stored at a raw address.
Supposed we want to trace the output on the red LED, which is connected to GPIO pin PB 2.
Let's pause the simulation.
Click setup
click New
Let's add this expression.
The numeric value is the memory address of the
output data register (ODR) of GPIO port B.
enter
And let's select Bit.
Since we are only interested in bit 2 of the ODR register,
we want to set up the mask and shift operation.
click close
For comparison, we add another one.
new
GPIOB->ODR
enter
highlight this,
change to bit
Set up the mask
shift right by 2 bits
Click OK
Let's restart the simulation
click run
zoom in
Let's pause the simulation
Now you can measure the time span between different
data points
See, the time span is approximately 1 second.
Thank you for watching.
Please visit the book website for more information and tutorials.