Anda di halaman 1dari 101

Lab 4: PEx Device Initialization + SDK Drivers

TM

External Use

Lab 4 Overview
Objective:
In this lab we will create a KDS Project with Processor Expert support and use the SDK for
peripheral drivers. We will add several components and import a source file with
implementation code.

Lab Flow:
Create

a new Processor Expert + SDK Project in KDS


Add and Configure Components
Generate Code
Import Existing Implementation File
Build
Download Application to Target MCU
Debug

Required Hardware and Software:


FRDM-K64F

Board configured with PEMicro Debugger


Micro USB Cable
Kinetis Design Studio (v1.1.1 or newer)

TM

External Use

Project Definition
Hardware: FRDM-K64F
Clock Configuration
Internal PLL; set to 120MHz
Bus Clock; 60MHz
Flash Clock: 20MHz

Pin Muxing
GPIO; UART

Blink the Green LED


Interrupt timer; set at 1 HZ

Turn on/off Red LED


Switch 2; Press to activate; Release to de-activate

Turn on/off Blue LED


Switch 3; Press on; Press Off

TM

External Use

Create a new project to blink the LEDs

This hands-on lab shows you how to

Create a new project with the New Project Wizard


Configure Components with the Component Inspector
Use Processor Expert Components
Import existing files
Build the project
Test the applications functionality

Next up!

The lab uses the FRDM-K64F board

The application will blink an LED periodically, and light


LEDs with button presses.

TM

External Use

Start KDS & Set Workspace Location


1

Double-Click on Kinetis Design Studio IDE Icon on Desktop


Navigate to and select:
Desktop\DWF KDS Class\Lab Sandbox\Wksp4
3

Select workspace location by clicking


on Browse and select your sandbox

4
TM

External Use

Click OK

Create New Project


1

File Menu New Kinetis Design Studio Project

TM

External Use

Enter Project4

Click Next

Select Device
1

TM

External Use

Enter mk64f into Processor to be used:

Select MK64FN1M0xxx12

Click Next

Finalize Project Settings


1

Ensure Kinetis SDK And Processor Expert ARE both


checked

2
TM

External Use

Click Finish

Project displayed in C/C++ Perspective

Project View
Component Inspector

Editor View

Component View

Problem View

TM

External Use

Create a new project to blink the LEDs

This hands-on lab shows you how to

Create a new project with the New Project Wizard


Select & Configure Components
Generate Code
Import existing files
Build the project
Test the applications functionality

Next up!

The lab uses the FRDM-K64F board

The application will blink an LED periodically, and light


LEDs with button presses.

TM

External Use

Selecting Components

Components Needed:

Pin Muxing

Processor: CPU: MK64FNM0VLL (Base CPU Preselected based on project


wizard information)
Using the PinSettings Component

Components needed for project

fsl_uart: send text to the terminal


fsl_gpio: SW2, SW3, RED_LED, GREEN_LED, BLUE_LED
fsl_pit: Flashing the LED

TM

External Use

10

Component Inspector
1
Expand
Project4

2
Select the
Cpu

TM

External Use

11

Drag down to resize

Configure CPU Component

In the next few slides we will configure the CPU component


as follows:
Package

100 pin LQFP


System Oscillator Enabled
External Clock 50 MHz input
MCG Mode PEE
PLL Output 120MHz
Core Clock 120MHz
Bus Clock 60MHz
Flash Clock 24MHz

TM

External Use

12

Component Inspector Package

TM

External Use

13

Click

Select LQFP 100-pin package

Component Inspector System Oscillator

1 Scroll

Down

Select System oscillator 0 Tab

4
TM

External Use

14

Select
External reference clock

Enter 50 MHz

Component Inspector System Oscillator


1

Select Inspector till you can see Clock


Scroll back up in the Component
Clock configurations Tab
configurations go ahead and select it revealing:

Select
MCG Settings

Resize and scroll


Component Inspector
View and select MCG
settings
TM

External Use

15

Component Inspector System Oscillator

Scroll
Down

TM

External Use

16

Enter
120

Select
PEE

Component Inspector Clock Configuration


1

Scroll back up and stretch window to expose System clocks


2

Select System clocks

Enter 120
Enter 60

3
Enter 24

TM

External Use

17

Adjust settings accordingly

Component Inspector CPU Common Settings

Select:
pin_init:PinSettings

TM

External Use

18

Configure Pin Settings

1
2

Click Switch Configuration

Note: This will clear up the errors in the pin_init component.

TM

External Use

19

Configure Pin Settings per Schematic


GPIO LEDs
UART

GPIO Switches

TM

External Use

20

Hardware GPIO Pins to Configure


Port Number

Function Name

Direction

PTA4

SW3

Input

PTB21

LED_BLUE

Output

PTB22

LED_RED

Output

PTC6

SW2

Input

PTE26

LED_GREEN

Output

Function Name

Port Number

Direction

SW2

PTC6

Input

SW3

PTA4

Input

LED_BLUE

PTB21

Output

LED_GREEN

PTE26

Output

LED_RED

PTB22

Output

TM

External Use

21

Configure Pin Settings

Select
GPIO

TM

External Use

22

Configure Pin Settings : PTA 4

Click here
And
Select PTA4/

TM

External Use

23

Configure Pin Settings : PTA 4

TM

External Use

24

Right Click Here

Select Pin Functional Properties

Configure Pin Settings : PTA 4

TM

External Use

25

Select Up
Select Enabled

Click Done

Configure Pin Settings : PTA 4

Enter Input
Enter SW3

TM

External Use

26

Configure Pin Settings : PTB 21

Click here
Select Output

Click here
Select PTB21/

2
1

TM

External Use

27

Enter LED_BLUE

Configure Pin Settings : PTB 21


NOTE: After settings made, notice both Pin/Signal Selection
and User Pin/Signal Name indicate LED_BLUE

TM

External Use

28

Configure Pin Settings : PTB 22

Click here
Select Output

Click here
Select PTB22/

2
1

TM

External Use

29

Enter LED_RED

Configure Pin Settings: PTB 22


NOTE: After settings made, notice both Pin/Signal Selection
and User Pin/Signal Name indicate LED_RED

TM

External Use

30

Configure Pin Settings: PTC 6


1

Click here
Select CMP0_IN0/
Click here
Select Input

TM

External Use

31

Enter SW2

Configure Pin Settings: PTC 6

TM

External Use

32

Right Click Here

Select Pin Functional Properties

Configure Pin Settings

TM

External Use

33

Select Up
Select Enabled

Click Done

Configure Pin Settings : PTE 26

Click here
Select PTE26/
Click here
Select Output

TM

External Use

34

Enter LED_GREEN

Hardware GPIO Pins to Configure


Port Number

Function Name

Direction

PTA4

SW3

Input

PTB21

LED_BLUE

Output

PTB22

LED_RED

Output

PTC6

SW2

Input

PTE26

LED_GREEN

Output

Function Name

Port Number

Direction

SW2

PTC6

Input

SW3

PTA4

Input

LED_BLUE

PTB21

Output

LED_GREEN

PTE26

Output

LED_RED

PTB22

Output

TM

External Use

35

Hardware UART Pins to Configure

Function

Port Number

Pin Number

Uart0 TX

PTB17

62

Uart0 RX

PTB16

63

TM

External Use

36

Configure Pin Settings: UART


1

Click here - Select PTB16/

Click here - Select PTB17/

TM

External Use

37

Select UART

Pin Muxing is Complete, Time to select & set


up the Components

TM

External Use

38

Selecting Components - Switch to Component Library

1
Click on
Component Library
to bring up the library

3
Scroll down until you begin to see
fsl_xxx components

Click on
Alphabetical

TM

External Use

39

Selecting Components

Double Click on
fsl_gpio

Double Click on
fsl_pit

TM

External Use

40

Selecting Components

Scroll Down

Double Click on
fsl_uart

TM

External Use

41

Selecting Components

The component list should now look like this:

TM

External Use

42

Configure GPIO Driver Settings - Inputs

Double-Click
gpio1:fsl_gpio
to bring up
Component
Inspector

TM

External Use

43

Click on the Input pins tab

CAREFUL: Click + twice on


Input pins number for 2 input pins

Configure GPIO Driver Settings Input SW2


1

Scroll Down if necessary and


select Row #1

Enter SW2 in Pin 1 Pin Field

Enter
SW2

3
Notice how remaining fields
are filled in and problems
related to pin are resolved.
TM

External Use

44

Configure GPIO Driver Settings Input SW3

3
Notice how remaining fields
are filled in and problems
related to pin are resolved.
TM

External Use

45

Scroll Down if necessary and


select Row #2

Enter SW3 in Pin 2 Pin Field

Configure GPIO Driver Settings - Outputs


1
Scroll Back Up and
Select Tab
Output pins

2
CAREFUL: Click +
Three Times on
Output pins number
for 4 input pins

TM

External Use

46

Configure GPIO Driver Settings

Scroll
Down

Select row
1

TM

External Use

47

Configure GPIO Driver Settings

Enter
LED_BLUE

TM

External Use

48

Configure GPIO Driver Settings

Enter
1

TM

External Use

49

Configure GPIO Driver Settings

Select row
2

Enter
LED_GREEN
1

TM

External Use

50

Configure GPIO Driver Settings

Select row
3

Enter
LED_RED
1

TM

External Use

51

Configure PIT Driver Settings


1

Select pitTimer1:fsl_pit in Components View

TM

External Use

52

In the Component Inspector


adjust Period to 1000 msSelect

Configure UART Driver Settings


Select uartCom1:fsl_uart
in Components View
2

Set Baud rate to 115200

TM

External Use

53

In the Component Inspector


confirm PTB16 and PTB17 are set for RxD and TxD

Create a new project to blink the LEDs

This hands-on lab shows you how to

Create a new project with the New Project Wizard

Select & Configure Components


Generate Code

Import existing files


Build the project
Test the applications functionality

Next up!

The lab uses the FRDM-K64F board

The application will blink an LED periodically, and light


LEDs with button presses.

TM

External Use

54

Generate Code with Processor Expert


1

In the Components View Click on the Generate Processor Expert Code Icon

TM

External Use

55

Generate Code with Processor Expert


Code is then generated by Processor Expert for the components that have
been added and configured in the project

TM

External Use

56

Generate Code with Processor Expert

Expand
Generated_Code
folder in the Project
Explorer

The files in this folder contain


the initialization settings that
are provided to the KSDK
initialization routines.

TM

External Use

57

Generate Code with Processor Expert

Events.c contains the


ISR stubs for the
application
Expand
Generated_Code
folder in the Project
Explorer

main.c
enough said

Note: Go ahead and explore these files by double clicking on them and
use the Editor View to see how they are structured.
TM

External Use

58

Examine the Code

Expand the
edit window up

TM

External Use

59

Interrupt Routine: Blink the Green LED

Open
Events.c

2
Scroll down to
here

TM

External Use

60

Interrupt Routine: Blink the Green LED in PIT Timer ISR


2

Open Events.c in Editor View

1
Expand
gpio1:fsl_gpio

3
4

TRICK: Drag & Drop GPIO_DRV_TogglePinOutput


to a point just after the /* Write your code here */

Add the parameter LED_GREEN to the


call it should look like this when done
TM

External Use

61

Create a new project to blink the LEDs

This hands-on lab shows you how to

Create a new project with the New Project Wizard


Select & Configure Components
Generate Code
Import existing files
Build the project
Test the applications functionality

Next up!

The lab uses the FRDM-K64F board

The application will blink an LED periodically, and light


LEDs with button presses.

TM

External Use

62

Importing Files

TM

External Use

63

Drag and Drop

Use Windows Explorer to navigate to:


..\Desktop\DWF KDS Class\Lab Code\Lab4_main.c

TM

External Use

64

Drag Lab4_main.c to Sources Folder

TM

External Use

65

Drag Lab4_main.c to Sources Folder


1
Select Copy Files

Click OK

TM

External Use

66

Open Lab4_main.c and main.c

1
Double-Click
Lab4_main.c
and main.c

TM

External Use

67

Select main.c
for editing

Add Our Code to main

Add declaration here

Add call here

TM

External Use

68

Check Point: Create a New Project to Blink an LED

This hands-on lab shows you how to

Create a new project with the New Project Wizard

Select and setup High Level Components


Generate Processor Expert Code
Import existing files
Build the project

Select the project

Clean

Build

Test the applications functionality

TM

External Use

69

Next up!

Building the Project: Clean


Select the project Project4

Select Clean

TM

External Use

70

Select the Project menu

Building the Project: Clean


1

Click OK

TM

External Use

71

Building the Project: Clean

Clean complete

TM

External Use

72

Building the Project

1
Right Click
On
Project4

2
Select
Build Project

TM

External Use

73

Building the Project

TM

External Use

74

A look at the code

TM

External Use

75

Examine main.c
PEx
#includes here

main.c
Your declarations
here

Hardware initializations
Your code goes here

TM

External Use

76

Examine events.c

Timer callback code goes here

TM

External Use

77

Examine Lab4_main.c

#includes copied from


ProcessorExpert.c

Declarations needed for our code

TM

External Use

78

Examine Lab4_main.c
Main loop watch for switch presses

TM

External Use

79

Examine Lab4_main.c

Switch press
routines

Print routine

Delay loop

TM

External Use

80

Test the Application

This hands-on lab shows you how to

Create a new project with the New Project Wizard


Select & Configure Components

Generate Code

Import existing files

Build the project

Test the applications functionality

Next up!

Setup

Debug Configuration
Download the code
Debug the code

The lab uses the FRDM-K64F board

The application will blink an LED periodically, and light


LEDs with button presses.

TM

External Use

81

Prepare PEMicro Debug Configuration


1

IMPORTANT: First, select project root Project4 in Project Explorer


Select Debug Configurations
Two ways to get there
Option 1: Pull-Down Next
3a
to Bug icon then select
Debug
Configurations

- OR 3b Option 2: Select:

Run Debug
Configurations

TM

External Use

82

Select Debug Configuration


1

Double-Click on GDB PEMicro Interface Debugging

Note: Project Binary and Project


name populated automatically
TM

External Use

83

Select OpenSDA PEMicro Interface


1

Select Debugger tab and expand Interface: Drop Down List

Select: OpenSDA Embedded Debug USB Port from list


3

TM

External Use

84

Note: Port: is Auto-Filled if


board connected

Configure Debugger Options


1

Expand Device Name: Drop Down List

Select: K64FN1M0M12 from list

TM

External Use

85

Click Apply

Launching Debugger
1

First time: Debug from Debug Configurations Dialog

NOTE: Next time, select from pull-down list on the Debug Icon
(ALWAYS SELECT FROM LIST)

TM

External Use

86

Configure Automatic Debug Perspective


1

As the debugger starts up, you will see the following dialog:

Check the Remember my decision box and click Yes

TM

External Use

87

Test the Application

This hands-on lab shows you how to

Create a new project with the New Project Wizard


Select & Configure Components

Generate Code

Import existing files

Build the project

Test the applications functionality


Setup Debug Configuration

Download the code

Next up!

Debug the code

The lab uses the FRDM-K64F board

The application will blink an LED periodically, and light


LEDs with button presses.

TM

External Use

88

Application Test: Debug Perspective

Debug View
Variable View Stack

Editor/Source View
Disassembly
View

Breakpoint

Console View Stack

TM

External Use

89

Application Test: Single Step "Into"

Click Step Into

Editor moves
to this line

TM

External Use

90

Application Test: Single Step Step Return

Click Step Return

Editor moves back to next


executable line in main.c

TM

External Use

91

Application Test: Single Step Step Over

Click Step Over


twice
Instruction pointer advances to sendstring

TM

External Use

92

Application Test: Run/Resume

Click Resume

UART prints
message to
Termite

TM

External Use

93

Application Test: Inspect Registers

2
Expand General
Registers

TM

External Use

94

Click Suspend

Select Registers view

Application Test: Inspect Registers

Click Step Over

Changed registers
are highlighted

TM

External Use

95

Application Test: Setting Breakpoints

Double click in column at location


to set breakpoint indicated with blue dot

TM

External Use

96

Application Test: Setting Breakpoints

Breakpoints can be disabled by un-checking


them in the Breakpoints View

and re-enabled by checking the


associated box

TM

External Use

97

Application Test: Setting Breakpoints


1

Click Reset target and restart debugging

3
Notice the program
stopped at the
Breakpoint
TM

External Use

98

Click Resume

Lab 4 Summary

Using Processor Expert is an easy way to configure a


Kinetis MCU
Adding SDK peripheral drivers with Processor Expert takes
care of all of the under the hood stuff and properly
includes files.

TM

External Use

99

TM

www.Freescale.com

2014 Freescale Semiconductor, Inc. | External Use

Printed SEPT2014

Anda mungkin juga menyukai