STMicroelectronics STM32:
Cortex™-M4 Lab
ARM
®
Keil
™
MDK Toolkit
featuring Serial Wire Viewer and ETM Trace
For the STM3240G-EVAL board
Version 0.72
Robert Boys
bob.boys@arm.com
Introduction:
For the ST STM3240G-EVAL Evaluation Board with STM32F407
The purpose of this lab is to introduce you to the STMicroelectronics Cortex™-M4 processor family using the ARM
®
Keil™
MDK toolkit featuring the IDE
μVision
®
. We will use the Serial Wire Viewer (SWV) and ETM trace on the STM3240G-
EVAL evaluation board from STMicroelectroncs. At the end of this tutorial, you will be able to confidently work with
STM32 processors and MDK. Keil offers a similar board: MCBSTM32F400™. Examples are provided for both boards.
Keil MDK comes in an evaluation version that limits code and data size to 32 Kbytes. Nearly all Keil examples will compile
within this 32K limit. The addition of a license number will turn it into the full, unrestricted version. Contact Keil sales for a
temporary full version license if you need to evaluate MDK with programs greater than 32K. MDK includes a full version of
Keil RTX
™
RTOS. No royalty payments are required. RTX source code is now included with all versions of Keil MDK
™
.
Why Use Keil MDK ?
MDK provides these features particularly suited for Cortex-M3 and
Cortex-M4 users:
µVision IDE with Integrated Debugger, Flash programmer
and the ARM
®
Compiler toolchain. MDK is a turn-key
product with included examples.
2. Serial Wire Viewer and ETM trace capability is included.
A full feature Keil RTOS called RTX is included with
MDK with source code.
3. RTX Kernel Awareness window is updated in real-time.
Kernel Awareness exists for Keil RTX, CMX, Quadros
and Micrium. All RTOSs can compile with MDK.
Awareness can be provided by the supplier.
4. Choice of adapters: ULINK2
™
, ULINK-ME
™
, ULINKpro
™
or Segger J-Link (version 6 or later). ST-Link is
supported but it has no SWV or ETM support at this time. SWV for ST-Link is planned for 4Q11.
5. Keil Technical Support is included for one year and is renewable. This helps you get your project completed faster.
This document details these features:
1.
2.
3.
4.
Serial Wire Viewer (SWV) with ULINK2, ULINK-ME and ULINKpro. ETM Trace using ULINKpro.
Real-time Read and Write to memory locations for Watch, Memory and RTX Tasks windows. These are non-
intrusive to your program. No CPU cycles are stolen. No instrumentation code is added to your source files.
Six Hardware Breakpoints (can be set/unset on-the-fly) and four Watchpoints (also called Access Breaks).
RTX Viewer: a kernel awareness program for the Keil RTX RTOS that updates while the program is running.
1.
Serial Wire Viewer (SWV):
Serial Wire Viewer
(SWV) displays PC Samples, Exceptions (including interrupts), data reads and writes, ITM (printf),
CPU counters and a timestamp. This information comes from the ARM CoreSight™ debug module integrated into the
Cortex-M4. SWV is output on the Serial Wire Output (SWO) pin found on the JTAG/SWD adapter connector.
SWV does not steal any CPU cycles and is completely non-intrusive except for ITM Debug printf Viewer. SWV is provided
by the Keil ULINK2, ULINK-ME, ULINKpro and the Segger J-Link. Best results are with a ULINK family adapter. The
STMicroelectronics ST-Link adapter does not support SWV at this time.
Embedded Trace Macrocell (ETM):
ETM adds all the program counter values to the data provided by SWV. This allows advanced debugging features including
timing of areas of code (Execution Profiling), Code Coverage, Performance Analysis and program flow debugging and
analysis. ETM requires a special debugger adapter such as the ULINKpro or Segger J-Trace. This document uses a
ULINKpro for ETM. A ULINK2 or ULINK-ME is used for the Serial Wire Viewer exercises in this lab.
1
STMicroelectronics Cortex-M3 Lab with STM3240G-EVAL board
Copyright © 2011 ARM Ltd. All rights reserved
www.keil.com
STM32 Evaluation Board list, 5 Steps, MDK Install, Useful Definitions
Part A: Connecting and Configuring to the target board:
1. Connecting ULINK2, ULINK-ME or ULINKpro to the STM3240G board:
2. ULINK2 or ULINK-ME and µVision Configuration:
3. ULINKpro and µVision Configuration:
4. ST-Link from STMicroelectronics and µVision Configuration:
5. Segger J-Link and µVision Configuration:
Part B: Blinky Example Programs using a ULINK2 or ULINK-ME:
1. Blinky Example Program using the STM32 and ULINK2 or ULINK-ME:
2. Hardware Breakpoints:
3. Call Stack + Locals Window
4. Variables for Watch and Memory Windows:
How to convert Local Variables to view in the Watch or Memory windows:
5. Watch and Memory Windows and how to use them:
6. Configuring the Serial Wire Viewer (SWV):
a. For ULINK2 or ULINK-ME:
b. For ULINKpro:
7. Using the Logic Analyzer (LA) with ULINK2 or ULINK-ME:
a.
Another use of the Logic Analyzer:
8. Watchpoints: Conditional Breakpoints
9. RTX_Blinky example program with Keil RTX RTOS:
10. RTX Kernel Awareness using Serial Wire Viewer (SWV):
11. Logic Analyzer Window: Viewing Variables in real-time in a graphical format:
12. Serial Wire Viewer (SWV) and how to use it: (with ULINK2)
a. Data Reads and Writes:
b. Exceptions and Interrupts:
c. PC Samples:
13. ITM (Instruction Trace Macrocell) a
printf
feature:
Part C: Using the ULINKpro with ETM Trace
1. Target Selector Box:
2. Blinky_Ulp Example
3. Code Coverage:
4. Performance Analysis:
5. Execution Profiling:
6. In-the-weeds Example:
7. Configuring the ULINKpro ETM Trace:
8. Serial Wire Viewer Summary:
9. Modifying the processor speed:
10. Keil Products and contact information:
2
STMicroelectronics Cortex-M3 Lab with STM3240G-EVAL board
3
4
5
6
7
8
9
9
10
10
10
11
12
12
13
14
15
16
17
18
19
20
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Copyright © 2011 ARM Ltd. All rights reserved
www.keil.com
STM32 Evaluation Boards:
Keil makes six STM32 evaluation boards plus several with STR7 and STR9 processors. Examples are provided.
Keil part number
MCBSTM32™
Processor
STM32F103VB
Characteristics Debug Connectors
monochrome LCD
color LCD
color LCD
color touch LCD
MCBSTM32F400™
JTAG/SWD
Cortex Debug and ETM
Cortex Debug and ETM
Cortex Debug and ETM
ST board equivalent
STM32F10X-128K-EVAL (color LCD)
STM3210E-EVAL
STM3210E-EVAL
STM3210C-EVAL
MCBSTM32E™
replaced by EXL
STM32F103ZE
MCBSTM32EXL™
MCBSTM32C™
MCBSTM32F200™
STM32F103ZG
STM32F107VC
Cortex-M4:
Keil MDK provides example projects for these STMicroelectronics boards:
CQ-STARM
STM32100E-EVAL
EK-STM32F
Cortex-M4:
STM32-Discovery
STM3240G-EVAL
STM32F10X-EVAL
STM32L152-EVAL
STM32F4-Discovery (MDK has examples for this board)
Five Steps to Get Connected and Configured:
1.
2.
3.
4.
5.
Physically connect a ULINK to the STM3240G or other target board. Power both of these appropriately.
Configure µVision to use a ULINK2, ULINK-ME or ULINKpro to communicate with the JTAG or SWD port.
Configure the Flash programmer inside µVision to program the STM32 internal flash memory.
If desired, configure the Serial Wire Viewer. Add the STM32F4xx_SWO.ini initialization file (see below).
If desired, configure the ETM trace with the ULINKpro. Add the STM32F4xx_TP.ini initialization file (see below).
STM32 processors need a special .ini file that configures the CoreSight Serial Wire Viewer and ETM trace. If you do not
intend to use SWV or ETM you do not need this file. It is entered in the Options for Target window under the Debug tab. It
can be configured for either SWO or 4 bit Trace Port operation. Instructions are provided on Page 30.
Software Installation:
This document was written for Keil MDK 4.22a or later which contains µVision 4. The evaluation copy of MDK is available
free on the Keil website. Do not confuse µVision4 with MDK 4.0. The number “4” is a coincidence.
To obtain a copy of MDK go to
www.keil.com/arm
and select the Download icon:
You can use the evaluation version of MDK and a ULINK2, ULINK-ME, ULINKpro or J-Link for this lab. You must make
certain adjustments for non-ULINK adapters such as the ST-Link and not all features shown here will be available.
The addition of a license number converts the evaluation into a full, unrestricted copy of MDK.
The ULINKpro adds Cortex-M3 ETM trace support. It also adds faster programming time and better trace display. Most
STMicroelectronics Cortex-M3/M4 parts are equipped with ETM. All have SWV.
JTAG and SWD Definitions:
It is useful to have an understanding of these terms:
JTAG:
JTAG provides access to the CoreSight debugging module located on the STM32 processor. It uses 4 to 5 pins.
SWD:
Serial Wire Debug is a two pin alternative to JTAG and has about the same capabilities except no Boundary Scan.
SWD is referenced as SW in the µVision Cortex-M Target Driver Setup. See page 5, middle picture.
SWV:
Serial Wire Viewer: A trace capability providing display of reads, writes, exceptions, PC Samples and printf.
SWO:
Serial Wire Output: SWV frames usually come out this one pin output. It shares the JTAG signal TDIO.
Trace Port:
A 4 bit port that ULINKpro uses to output ETM frames and optionally SWV (rather than the SWO pin).
ETM:
Embedded Trace Macrocell: Provides all the program counter values. Only the ULINKpro works with ETM.
Example Programs:
See
www.keil.com/st
for additional information.
Example projects for STMicroelectronics boards are found in C:\Keil\ARM\boards\ST and in C:\Keil\ARM\boards\Keil for
Keil boards. Most example projects are pre-configured to use a ULINK2 or a ULINK-ME. Serial Wire Viewer is not
usually configured: you can do this yourself easily. Projects that contain a Ulp in their name are configured to use a
ULINKpro and SWV and ETM are pre-configured. It is easy to select different debug adapters in µVision.
Most example projects will compile within the 32 K code and data limit of the evaluation version of MDK. An exception is
LCD_Blinky. A compiled executable called Blinky.axf file is provided to allow you to run, evaluate and debug these
programs. If you attempt to compile these projects, the Blinky.axf file will be erased. It is a good idea to back this file up.
3
STMicroelectronics Cortex-M3 Lab with STM3240G-EVAL board
Copyright © 2011 ARM Ltd. All rights reserved
www.keil.com
Part A)
1) Connecting ULINK2, ULINK-ME or ULINKpro:
The STM3240G is equipped with the new ARM standard 20 pin Hi-
Density connector for JTAG/SWD, SWO and ETM access as shown
pointed to by the pen. It is labeled
CN13: Trace
The legacy 20 pin JTAG connector is also provided. This provides
JTAG, SWD and SWO access. No ETM is available on this
connector.
A 10 pin connector in the same form factor as the 20 pin Hi-Density
exists but is not provided on the STM3240G. This 10 pin provides
JTAG, SWD and SWO access in a much smaller footprint. This
connector is supported by ULINK2 and ULINK-ME with a special
supplied cable. It is shown in the ULINK-ME photo below indicated
by the red arrow.
The 20 pin connector CN13 provides JTAG, SWD, SWO and adds 4 bit ETM support and connects to the ULINKpro.
Connecting a ULINK2 or ULINK-ME:
Legacy 20 Pin JTAG Connector:
A ULINK2 plugged to the STM3240G board is pictured on the first
page of this document.
The ULINK-ME is pictured here and the arrow points to the 10 pin
Hi-Density connector.
20 Pin Connector:
Keil does have a 10 pin to 20 pin adapter cable
available to connect to this connector and is supplied with ULINK-
ME. The first 10 pins on the 20 pin replicate the 10 pin.
The second 10 pins on the 20 pin contain the five ETM signals.
Connecting a ULINKpro:
The ULINKpro connects to a STM32 board with its standard 20 pin Hi—Density connector or the standard JTAG connector
with a supplied adapter.
In order to use ETM trace you must connect the ULINKpro to the 20 pin Hi-density connector as shown below:
If you use the legacy 20 pin connector you can use JTAG, SWD and SWV but not ETM.
Pictured is a ULINKpro with the STM3220F-EVAL from STMicroelectronics (below) and the Keil MCBSTM32C (right).
4
STMicroelectronics Cortex-M3 Lab with STM3240G-EVAL board
Copyright © 2011 ARM Ltd. All rights reserved
www.keil.com
2) ULINK2 or ULINK-ME and µVision Configuration:
It is easy to select a USB debugging adapter in µVision. You must configure the connection to both the target and to Flash
programming in two separate windows as described below. They are each selected using the Debug and Utilities tabs.
This document will use a ULINK2 or ULINK-ME as described. You can substitute a ULINKpro with suitable adjustments.
Serial Wire Viewer (SWV) is completely supported by these two adapters. They are essentially the same devices electrically
and any reference to ULINK2 in this document includes the ME. STM32 processors require an .ini file to configure the
SWV or ETM features. The ULINKpro, which is a Cortex-Mx ETM trace adapter, has all the features of a ULINK2 with the
advantages of faster programming time, adds ETM trace support and an enhanced Trace Data window.
Step 1) Select the debug connection to the target:
1.
Assume the ULINK2 is connected to a powered up STM32 target board, µVision is running in Edit mode (as it is
when first started – the alternative to Debug mode) and you have selected a valid project. The ULINK2 is shown
connected to the STM3240G-EVAL board on page 1.
or ALT-F7 and select the Debug tab.
Select Options for Target
In the drop-down menu box select ULINK as shown here:
Select Settings and the next window below opens up. This is the
control panel for the ULINK 2 and ULINK-ME (they are the same).
In
Port:
select SWJ and SW. Serial Wire Viewer (SWV) will not work with JTAG selected. If you are not going to
use SWV with the SWO port or will use it with the 4 bit trace port selected, you can use JTAG.
In the SW Device area: ARM CoreSight SW-DP
MUST
be displayed. This confirms you are connected to the
target processor. If there is an error displayed or it is blank this
must
be fixed before you can continue. Check the
target power supply. Cycle the power to the ULINK and the board.
2.
3.
4.
5.
TIP:
To refresh this screen select Port: and change it or click OK once to leave and then click on Settings again.
TIP:
You can do regular debugging using JTAG. SWD and JTAG operate at approximately the same speed. Serial Wire
Viewer (SWV) will not operate in JTAG mode.
Step 2) Configure the Keil Flash Programmer:
6.
7.
8.
9.
Click on OK once and select the Utilities tab.
Select the ULINK similar to Step 2 above.
Click Settings to select the programming
algorithm if it is not visible or is the wrong one.
Select STM32F4xx Flash as shown below or the
one for your processor:
10. Click on OK once.
TIP:
To program the Flash every time you enter Debug
mode, check Update target before Debugging.
11. Click on OK to return to the µVision main screen.
Select File/Save All.
12. You have successfully connected to the STM32
target processor and configured the µVision Flash
programmer.
TIP:
The Trace tab is where you configure the Serial
Wire Viewer (SWV) and ETM trace if you have a
ULINKpro. You will learn to do this later.
TIP:
If you select ULINK or ULINKpro, and have the
opposite ULINK physically connected to your PC; the
error message will say “No
ULINK device found”.
This
message actually means that µVision found the wrong Keil
adapter connected. Merely select the one connected.
5
STMicroelectronics Cortex-M3 Lab with STM3240G-EVAL board
Copyright © 2011 ARM Ltd. All rights reserved
www.keil.com