5 - Keil MDK Version 5 - Hands-On

Download as pdf or txt
Download as pdf or txt
You are on page 1of 82

Keil MDK Version 5

Component-based Software Development

Christopher Seidl
Technical Marketing Manager, DSG

1
Installing the Workshop Material

 Required software:
 DAVE™ 3.1.10 Including the latest Updates
 MDK Version 5.11: MDK511.exe
 MDK Add-On Installer: MDK-ARM_Pro_Eval_AddOn.exe
 Infineon XMC400 Device Family Pack: Infineon.XMC4500_DFP.2.0.0.pack

 DAVE Project:
 Please use the one that has been created in the morning session. If you do not have it, use:
 Project\Relax_kit.zip (can be imported into DAVE™ using the DAVE™ import functionality: File 
Import  DAVE Project; then browse to the project ZIP file)

2
Software Packs in Keil MDK Version 5
MDK Core

µVision IDE with Editor ARM C/C++ Compiler

Pack Installer µVision Debugger with Trace

Device CMSIS MDK-Professional Middleware


Software Packs

System/Startup CMSIS-CORE Network


Ethernet Driver
CMSIS-DSP USB Host File System
SPI Driver

USB Driver CMSIS-RTOS USB Device Graphics

3
Software Packs
Software Pack
 Software components are delivered in one
easy to install Software Pack Component
Libraries
Configuration Files
 A package description file (PDSC) contains: Header File (API)
 Supplier information Documentation

 Download URL Flash Algorithms


Device Parameter
 License
 Release version Component

 Dependencies on processors, devices, tool chains
or other components Component

4
Device Family Pack Device Family
Pack
Example: Infineon.XMC4500_DFP
System/Startup
 Device family and devices startup_device.s

 System and startup code, device header files system_device.c


device.h
 SVD files
 Flash algorithms Device Info
 Functional grouping of files SVD File(s)
Flash Algorithms
 Development board information (if available)
Parameters
 Usage of source code and library files for: Documentation
 Specific processors Debug Configuration

 Tool chains
CMSIS-Driver
 Example Projects USB, …

 User Code Templates Device (other)


HAL

5
MDK-Professional Middleware

 Specifically designed for ARM Cortex-M devices MDK-Professional Middleware


 Relies on CMSIS-Driver and CMSIS-RTOS
Network
 Several components available:
 Network USB Host File System
 USB (Host & Device)
 File System USB Device Graphics
 Graphics
 Part of MDK-Professional

6
6
Middleware: Network

 Add TCP/IP network connectivity via Ethernet or Serial


 Extensive range of service applications included
 Designed for Cortex-M devices with small memory footprint

7
Middleware: Graphic

 Add a graphical user interface (GUI) to an application quickly


 Compatible with hundreds of display controllers
 Touch-screen support for many TFT LCDs

8
Middleware: USB Host
USB Host Component
HID
Human Interface Device
CORE
Class

MSC
USB Host
Mass Storage
Driver

USBH High-Speed Full-Speed

 Connect common USB devices easily


 Support for various popular microcontroller host controllers
 High performance and small footprint
 USB 1.1 Low Speed (1.5 Mbit/s) and Full Speed (12 Mbit/s)
 Supports USB Flash drives and card storage devices

9
Middleware: USB Device

USB Device Component


HID MSC
CORE
Class

Human Interface Device Mass Storage

CDC ADC USB Device


Communication Device Audio Device
Driver

USBD High-Speed Full-Speed

 Standard USB Device classes supported


 Plug’N’Play: No need to develop a driver for Windows or Linux hosts
 USB 1.1 Low Speed (1.5 Mbit/s) and Full Speed (12 Mbit/s)

10
Middleware: File System

File System Component


RAM
USB MSC CORE
Mass Storage
Drive

Variants:
NAND Flash NOR Flash
Memory Card • Long File Names
SD/SDHC/MMC • Short File Names
Driver

MCI
NAND Flash NOR Flash
SPI

 Enable applications to work with locally stored data


 Storage devices: ROM, RAM, Flash, and SD/MMC/SDHC
 FAT32 file system supported
 Simultaneous access to multiple storage devices

11
Web Portal for Software Packs

12
Keil MDK Workflow using Software Packs

Install Select Configure Implement


• Download relevant • Choose device • Setup parameters • Use code templates
Software Packs from and select required of the Run-Time for faster software
Web Portal middleware Environment development

13
Component View and templates in Keil MDK Version 5

14
Advantages of Software Components in Keil MDK

Enhanced Long-term
Improved Flexibility
Productivity Project Maintenance
• Convenient • Software Packs • Support for new
selection of with update facility devices is provided
software and version by Software Packs
components management
• Easy access to • Open standard
documentation • Simplifies the allows adding third
• Code templates and replacement of the party components
examples to kick- target device
start development

15
Importing DAVE™ projects in MDK Version 5
Hands-On

16
Required Setting for GPDSC Generation

 Go to Window  Preferences and Dave  DAVE CE Preferences


 Make sure that Generate gpdsc file is enabled:

18
Resource Solving and Code Generation

 The project needs to be solved.


 Press the Solver button to run the resource solver:

 Next, the library code of the DAVE™ Apps needs to be generated. This will also trigger
the creation of the GPDSC file.
 Click the Generate Code button:

 Check if the GPDSC file has been generated:

19
Invoking µVision® from DAVE™

 To import the project to µVision, simply double-click the Relax_kit.gpdsc file in the
C/C++ Projects view.
µVision starts:

 Note: µVision will create a project in the same folder as the DAVE™ project
20
Add a Main.c File to the µVision® Project

 There is no main file in the project, so we need to add one manually


 Right click on Source Group 1, select Add Existing files to ‘Source Group 1’…

1. Click on Main.c
2. Click Add
3. Click Close

21
Explore the Project

 The Project window shows you the software components:


 CMSIS is representing the CMSIS-CORE framework
 DAVE3 contains generated files which are part of the GPDSC
 Device incorporates files for device support
 The Manage Run-Time Environment window reflects this:

22
Going Back to DAVE™

 Changing the DAVE™ project (add/remove Apps or adjust App settings) needs to be
done in DAVE™.
 The Play button in the Manage Run-Time Environment window invokes DAVE™ with
the correct project:

23
Open Target Options Dialog

 Go to Project  Options for Target ‘XMC4500-F100x1024’ (or press ALT+F7)


and click on the Debug tab:

24
Select the J-LINK Debugger

 The XMC4500 Relax Kit has an integrated J-LINK debug adapter


1. To change default adapter, click on ULINK2/ME Cortex Debugger and scroll down
until J-LINK/J-TRACE Cortex
2. Click on Settings, to check the connectivity between the target and your PC

25
Enable the SW Port

 µVision will try to connect to the J-LINK using a JTAG port. This is not available on the
Relax Kit
 Click on Port: JTAG and set to SW
 The connected device will be detected
automatically
 Click OK twice

26
Build the Project and Download to Target

 Go to Project  Build (or press F7) to start the build process


 You will see a lot of warnings (#188-D) which can be safely ignored. If you want to
suppress these warnings, press ALT+F7 again, click on the C/C++ tab and enter in the
Misc Controls field: --diag_suppress=188
 Rebuilding the project (Project  Rebuild all target files) will show no warnings

 Go to Flash  Download (or click on ) to download the program into the target’s
Flash memory

27
Start a Debug Session

 Go to Debug  Start/Stop
Debug Session (or press
CTRL+F5) to switch to the
µVision debugger.
 During the start of the debug
session, µVision loads the
application, executes startup
code, and stops at the main C
function
 Click Run on the toolbar. The
LED connected to P1.1 will start
flashing

28
printf Debugging using the
Instrumentation Trace Macrocell (ITM)

29
CoreSight
On-chip Debug and Trace Technology
 Debug Interface
 JTAG/Serial Wire Debug (SWD)
 Start/Stop/Single Step Debug
 Set/Reset Breakpoints
 Read/Write Memory and Peripheral Registers
 Trace Port Interface
 Serial Wire Trace Output (SWO) only in
SWD debug mode
 Instrumentation Trace Macrocell (ITM)
provides:
 Printf debugging
 RTOS information
 Interrupt execution information

30
Serial Wire Viewer (SWV) – Real-Time Trace

 The Serial Wire Viewer (SWV) provides real-time data trace information from various
sources within the Cortex-M3/M4 device. This is output via the single SWO pin while
your system processor continues running at full speed.
 Diagnostic system information is available from the ITM and DWT:
 Data read/write of selected variables
 PC values
 Exception and interrupt execution
 Timing statistics
 Periodic samples of the program counter
 Event counters display CPU statistics
 Indicates required device wait states or the idle time

31
SWV: Three Ways to View Variables

1. In the Watch window: 3. In the Debug (printf) Viewer window:

2. In the Memory window:

32
SWV Trace Windows

 Event Counters
 Real-time values of event counters
 Trace Exceptions
 Statistical information about
program exceptions
 Trace Data (with ETM Trace only)
 Time stamps, PC sample, r/w accesses
 Updated while target system is running

33
Event Counters

 Displays real-time values of the specific event counters


 Shows the number of times counter ‘rolls over’.
 Updated in real time
 Ability to Save Counter Data
 Right Click and select “Clear All” or “Clear Selection”

34
Trace Exceptions

 Displays statistical information about program exceptions


 Exception name and number, number of times entered
 Max and min time spent in and out of exceptions
 First and last time entered

35
ITM printf Debugging
Install Private.Debug_ITM.1.0.0.pack
 Double-click on Private.Debug_ITM.1.0.0.pack in the Packs directory of your USB
stick
 The Pack will automatically be installed:

 Open the Manage Run-Time Environment window in µVision and browse to the Debug
software component:

36
Setting the __DBG_ITM Define

 If not done, stop ( ) debugging and leave


the Debug view ( ).
 Go to Project  Options for
Target ‘XMC4500-F100x1024’ (or
press ALT+F7) and click on the C/C++
tab.
 Enter _ _DBG_ITM in the
Preprocessor Symbols  Define box

37
Enabling Trace in J-LINK
http://www.keil.com/support/man/docs/jlink/jlink_cortextrace.htm
 Click on the Debug tab.
 Click on Settings. A new window opens
(Cortex JLink/JTrace Target Driver Setup)
1. Click on the Trace tab
2. Check Enable
3. Enter the correct Core Clock:
120 MHz
4. Click OK twice

38
Add Code to Main.c

 At the top of the file add


#include <stdio.h>
 In the main function’s while loop, after the
CNT001_GetEvtCountValue(&CNT001_Handle0, &CountVal);
 Add
printf("Count value = %d\n\r", CountVal);

39
Rebuild the Project and Download to Target

 Go to Project  Build (or press F7) to start the build process


 Go to Flash  Download (or click on ) to download the program into the target’s
Flash memory
 Go to Debug  Start/Stop Debug Session (or press CTRL+F5) to switch to the
µVision debugger.
 Go to View  Serial Windows  Debug (printf) Viewer to open that window that
shows the printf output
 Run the program (press F5)

40
Debug (printf) Viewer

41
ULINKpro
Debug and Trace Adapter
 Programming + Run Control
 Memory + Breakpoint Access
 Serial Wire Trace (SWO)
 100 Mbps (Manchester Mode)
 ITM and Data Trace @ CPU speed
 ETM Streaming Trace
 Up to 800 Mbps
 100% Code Coverage and Performance Analysis

SWO ETM
JTAG SWD
100 Mpbs Streaming

42
ULINKpro
Fastest Data Trace
 100 x faster than most other MCU solutions
 Real-Time data trace analysis
 CPU operates at full speed
 No overflows or lost data
 MDK gives clear visibility into application
behaviour

SWO ETM
JTAG SWD
100 Mpbs Streaming

43
ULINKpro
Streaming Instruction Trace
 What is Streaming Trace?
 Trace data transferred in real-time to debug host
 Trace for minutes, hours, or longer
 Required for full code-coverage and
timing analysis
 ULINKpro
 Only solution to stream trace directly to PC
 Search trace data
 Save trace data
 Function trace
 Synchronized to source code
SWO ETM
JTAG SWD
100 Mpbs Streaming

44
ULINKpro
Advanced Debug Capability
 Streaming Instruction Trace  Code Coverage
 Debug historical sequences  Implement 100% accurate Code Coverage on
 Full details of execution history silicon
 Application Soak testing over long periods  Essential for validation and verification
of time  Fastest Data Trace
 Performance Analysis  100 times faster than any other solution
 Optimize and Profile Applications  CPU at full speed
 Identify hotspots quickly  No overflows or lost data

SWO ETM
JTAG SWD
100 Mpbs Streaming

45
Creating Applications using Software Packs

46
Objective: Blinky Project with RTOS

 We will create a new project from scratch, using:


 CMSIS-CORE
 Startup Files for CMSIS
 CMSIS-RTOS compliant Keil RTX

 Later, we will add a USB driver and Middleware to set and reset the LEDs from a PC

47
Create a New Project

 Open µVision and click


Project  New µVision Project…
1. Click New folder
2. Enter Name: RTOS_Blinky
3. Click Open

 Enter File Name: RTOS_Blinky


 Click Save

48
Select Device for Target: XMC4500-F100x1024

49
Manage Run-Time Environment
Select Software Components
 Expand CMSIS
 Select CORE
 Validation Output shows required
software components
 In Validation Output click on
Infineon::Device:Startup
 You will be automatically directed to the
required component
 Select the component
 Expand CMSIS:RTOS (API)
 Select Keil RTX
 Click OK

50
Add Code

 Copy the files main.c, LED.c, and LED.h from the Code directory on the USB stick to
your RTOS_Blinky project directory
 Expand Target 1 in the Project view
 Right click on Source Group 1 and select
Add Existing Files to Group ‘Source Group 1’…
 Click on main.c and LED.c
1. Click Add
2. Click Close

51
Work with the Code

 Double-click main.c. The file opens in the editor


 You’ll notice a lot of red x’s and warning signs
 Add required include files by right-clicking in the code (around line 10)
 Click on Insert ‘#include file’ and select XMC4500.h
 Repeat for cmsis_os.h

 Errors and warnings should disappear


 Press CTRL+S to save the file
52
Required RTOS Settings

 Double-click RTX_Conf_CM.c. The file opens


in the editor.
 Click Configuration Wizard tab (at the
bottom of the file)
 Graphical representation of the configuration
files appears. Click Expand All
 All available settings for Keil RTX are displayed
 We need to change the RTOS Kernel Timer
input clock frequency [Hz] to 120 MHz as this
is the core frequency
 Click on 12000000 and add a 0
 Press CTRL+S to save the file

53
Build the Project

 Press F7 or click Project  Build target to start the build process


 The project should build without and error or a warning

54
Select the J-LINK Debugger

 The XMC4500 Relax Kit has an integrated J-LINK debug adapter


1. To change default adapter, click on ULINK2/ME Cortex Debugger and scroll down
until J-LINK/J-TRACE Cortex
2. Click on Settings, to check the connectivity between the target and your PC

55
Enable the SW Port

 µVision will try to connect to the J-LINK using a JTAG port. This is not available on the
Relax Kit
 Click on Port: JTAG and set to SW
 The connected device will be identified
automatically

56
Enabling Trace in J-LINK

1. Click on the Trace tab


2. Check Enable
3. Enter the correct Core Clock:
120 MHz
4. Click OK twice

57
Start a Debug Session

 Go to Debug  Start/Stop
Debug Session (or press
CTRL+F5) to switch to the
µVision debugger.
 During the start of the debug
session, µVision loads the
application, executes startup
code, and stops at the main C
function
 Click Run on the toolbar.
LED1 and LED2 will start flashing
alternately

58
Add more Debug Information

 End the session by clicking Stop


 Go to Debug  OS Support 
System and Thread Viewer
 Go to Debug  OS Support 
Event Viewer
 Go to View  Trace  Trace
Exceptions
 Go to Peripherals  System
Viewer  PORTS  PORT1

59
Kernel-Aware Debugging

 System and Thread Viewer


together with Event Viewer helps
to track the progress of the
program

60
Trace Exceptions

 Displays statistical information about


program exceptions
 Exception name and number, number
of times entered
 Max and min time spent in and out of
exceptions
 First and last time entered

61
System Viewer

 Displays information about peripheral


registers
 Allows on-the-fly debugging of Special
Function Registers (SFRs)
 Use it to:
 View peripheral register property values
 View additional information about a property
 Change properties at runtime (click into the value
field and enter a new value)

62
Extending the Project with USB

63
Adding USB Functionality to the Project

 To control the LEDs via a PC based


program, we will use the Micro USB port
next to the RJ45 connector

64
CMSIS-Driver 2.0 Software Packs
Microcontroller Device Middleware
Control
Startup/System
 API describing peripheral Structs

driver interfaces for USB USB Controller USB Device Driver USBD0 USB Device

middleware stacks and Rx1/Tx1 USART USART Driver USART1

user applications Ethernet Ethernet PHY Ethernet PHY ETH_PHY0


TCP/IP
Networking
 Generic and independent
Ethernet MAC Ethernet MAC ETH_MAC0
of a specific RTOS
SPI1 SPI #1
 Covers a wide range of SPI Driver
SPI1 Graphics
SPI2
use cases for the SPI2 SPI #2

supported peripheral SDIO0 SDIO MCI Driver MCI0 File System


types I/O Memory Controller NAND Flash Driver NAND0

 Infineon::XMC4000_DFP USB USB Controller USB Host Driver USBH0 USB Host
provides compliant drivers
RTE_Device.h
for USB Configuration File

65
Manage Run-Time Environment
Select USB Middleware Components
 Stop the Debug session
 Click on
 Expand USB
 Select CORE
 Expand USB:Device
 Set HID to 1
 Click Resolve
 Click OK

66
Add USB HID Template File

 Right click on Source Group 1 and select


Add New Item to Group ‘Source Group 1’…
1. Click on User Code Template
2. Scroll down until you see
Device:HID. Click on it
3. Click Add

67
USBDUser_HID_0.c Template File (1)

 It implements the application specific functionality of the HID class and is used to
receive and send data reports to the USB Host
 The implementation must match the configuration file USBD_Config_HID_0.h
 Add the following:
 #include "LED.h"

68
USBDUser_HID_0.c Template File (2)

 It contains function prototypes that need to be adapted to the user application:


 bool USBD_HID0_SetReport (uint8_t rtype, uint8_t req, uint8_t rid, const
uint8_t *buf, int32_t len) {
uint8_t i;
switch (rtype) {
case HID_REPORT_OUTPUT:
for (i = 0; i < 4; i++) {
if (*buf & (1 << i))
LED_On (i);
else
LED_Off (i);
}
break;
case HID_REPORT_FEATURE:
break;
}
return true;
}
69
Using the Push-buttons

 BUTTON1 and BUTTON2 can be used in the HID program as well


 Copy Keyboard.c and Keyboard.h to your project directory
 Add Keyboard.c to the project:
 Right click on Source Group 1 and select
Add Existing Files to Group ‘Source Group 1’…
1. Click on Keyboard.c
2. Click Add
3. Click Close

70
Implement the Application

 Copy USBmain.c to your project directory


 Add USBmain.c to the project:
 Right click on Source Group 1 and select
Add Existing Files to Group ‘Source Group 1’…
1. Click on USBmain.c
2. Click Add
3. Click Close
 Right-click main.c and select Remove File ‘main.c’

71
RTOS Configuration

 USB demands additional resources for the RTOS


 Change the following in RTX_Conf_CM.c:
 Default Thread stack size (OS_STKSIZE): 512 bytes (value: 128)
 Main Thread stack size (OS_MAINSTKSIZE): 512 bytes (value: 128)
 Number of threads with user-provided stack size (OS_PRIVCNT): 4
 Total stack size [bytes] for threads with user-provided stack size (OS_PRIVSTKSIZE): 2048 bytes
(value: 512)
 RTOS Kernel Timer input clock frequency [Hz] (OS_CLOCK): 120000000

72
Run the Application

 Build the application (F7)


 Download it into Flash ( )
 Unplug the USB cable
 Plug it into the Micro-USB port X3 next to the RJ45
 You might see a notification from Windows that drivers are being installed

73
HID Client Application
C:\Keil\ARM\Utilities\HID_Client\Release\HIDClient.exe
 A Windows program is available to test the functionality of the code
 The HIDClient.exe utility is located in "C:\Keil\ARM\Utilities\HID_Client\Release" and
can run stand-alone without the need to install the software
 To check the client utility with your board, do the following:
 Download the application to your board.
 Verify all jumper settings on the board.
 Connect the board to a Windows PC. The PC should recognize the HID device and install the
correct driver automatically.
 Run "C:\Keil\ARM\Utilities\HID_Client\Release\HIDClient.exe".
 Select the Device to establish the communication channel.
 Test the application by enabling the correct LEDs (here 0 and 1)
and by pressing the push-buttons on the development board

74
MDK Professional Evaluation License

 The license you have received today will expire 2nd July, 2014
 If you want to test the Middleware longer, please visit
https://www.keil.com/trial
 You will receive a 30-Day Free Trial License for MDK Professional

75
µVision IDE Features

76
Context Sensitive F1 Help

 Pressing F1 with cursor on any keyword will bring up the related help page:

77
Code Completion

 List showing all program symbols that contain the currently


typed characters
 List appears after typing:
 3 characters (default)
 A trigger character:
. For structures or classes
-> For pointer structures
:: For symbols within a specific scope
 CTRL+<space>
 Insert the highlighted list-item into the code by pressing:
 Tab, space, or enter
 Typing a bracket
 Any trigger character

78
Parameter Information

 For a function or method Parameter Information shows:


 Parameter names
 Amount of parameters
 Parameter types

 While typing, the bolded text indicates the next required parameter

79
Dynamic Syntax Checking while Typing

 Validates program syntax


 Alerts to potential code violations before compilation
 Errors/warnings shown by:
 Squiggly red lines in the editor
 Icons next to the line number
 Hover the mouse on an icon for details about the syntax violation
 Also in:
 View  Error List Window

80
Feature Configuration

 Go to Edit  Configuration, click on the Text Completion tab

81
Collaterals on USB Stick

 AN258 - Using DAVE3 with MDK Version 5


 AN260 - Infineon XMC1100 2Go Lab for uVision V5
 AN263 - Infineon XMC1200 Boot Kit Lab for uVision V5
 Getting Started – Create Applications with MDK Version 5
 µVision Keyboard Shortcuts

82
Links on USB Stick

 MDK Version 5 Overview: http://www2.keil.com/mdk5


 MDK Version 5 Download: https://www.keil.com/demo/eval/arm.htm
 Infineon on keil.com: http://www2.keil.com/infineon
 Keil MDK for Infineon XMC1000: http://www2.keil.com/infineon/mdk
 Support: www.keil.com/support
 Forums: http://www.keil.com/forum
 Application Notes: http://www.keil.com/appnotes
 Keil Tools on ARM Connected Community: http://community.arm.com/groups/tools

83

You might also like