DWF-KDS-KSDK - Lab 4

101
TM External Use 0 Lab 4: PEx Device Initialization + SDK Drivers

description

frdm k64f

Transcript of DWF-KDS-KSDK - Lab 4

Page 1: DWF-KDS-KSDK - Lab 4

TM

External Use 0

Lab 4: PEx Device Initialization + SDK Drivers

Page 2: DWF-KDS-KSDK - Lab 4

TM

External Use 1

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)

Page 3: DWF-KDS-KSDK - Lab 4

TM

External Use 2

Project Definition

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

Hardware: FRDM-K64F

Clock Configuration Internal PLL; set to 120MHz Bus Clock; 60MHz Flash Clock: 20MHz

Pin Muxing GPIO; UART

Page 4: DWF-KDS-KSDK - Lab 4

TM

External Use 3

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 application’s functionality

• The lab uses the FRDM-K64F board

• The application will blink an LED periodically, and light

LEDs with button presses.

Next up!

Page 5: DWF-KDS-KSDK - Lab 4

TM

External Use 4

Start KDS & Set Workspace Location

Double-Click on “Kinetis Design Studio IDE” Icon on Desktop

Select workspace location by clicking

on “Browse” and select your sandbox

Navigate to and select:

Desktop\DWF – KDS Class\Lab Sandbox\Wksp4

Click “OK”

1

2

3

4

Page 6: DWF-KDS-KSDK - Lab 4

TM

External Use 5

Create New Project

File Menu New Kinetis Design Studio Project 1

Enter “Project4”

Click “Next”

2

3

Page 7: DWF-KDS-KSDK - Lab 4

TM

External Use 6

Select Device

Enter “mk64f” into “Processor to be used:”

Select “MK64FN1M0xxx12”

Click “Next”

2

3

1

Page 8: DWF-KDS-KSDK - Lab 4

TM

External Use 7

Finalize Project Settings

Ensure “Kinetis SDK…” And “Processor Expert…” ARE both

checked

Click “Finish” 2

1

Page 9: DWF-KDS-KSDK - Lab 4

TM

External Use 8

Project displayed in C/C++ Perspective

Component Inspector

Component View

Project View

Editor View

Problem View

Page 10: DWF-KDS-KSDK - Lab 4

TM

External Use 9

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 application’s functionality

• The lab uses the FRDM-K64F board

• The application will blink an LED periodically, and light

LEDs with button presses.

Next up!

Page 11: DWF-KDS-KSDK - Lab 4

TM

External Use 10

• Components Needed:

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

wizard information)

• Pin Muxing

− 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

Selecting Components

Page 12: DWF-KDS-KSDK - Lab 4

TM

External Use 11

Component Inspector

Drag down to resize

Select the

Cpu

Expand

“Project4”

1

2

3

Page 13: DWF-KDS-KSDK - Lab 4

TM

External Use 12

• 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

Configure CPU Component

Page 14: DWF-KDS-KSDK - Lab 4

TM

External Use 13

Component Inspector – Package

Select “LQFP 100-pin package”

Click 1

2

Page 15: DWF-KDS-KSDK - Lab 4

TM

External Use 14

Component Inspector – System Oscillator

Enter “50” MHz

Select “System oscillator 0” Tab

Select

“External reference clock”

Scroll

Down 1

2

3

4

Page 16: DWF-KDS-KSDK - Lab 4

TM

External Use 15

Component Inspector – System Oscillator Select

“Clock configurations” Tab

Select

“MCG Settings”

Scroll back up in the Component Inspector till you can see “Clock

configurations” – go ahead and select it revealing: 1

Resize and scroll

Component Inspector

View and select “MCG

settings”

2

Page 17: DWF-KDS-KSDK - Lab 4

TM

External Use 16

Component Inspector – System Oscillator

Select

“PEE”

Enter

“120”

Scroll

Down

1

2

3

Page 18: DWF-KDS-KSDK - Lab 4

TM

External Use 17

Component Inspector – Clock Configuration

Select “System clocks”

Enter “120”

Enter “60”

Enter “24”

1 Scroll back up and stretch window to expose “System clocks”

2

3 Adjust settings accordingly

Page 19: DWF-KDS-KSDK - Lab 4

TM

External Use 18

Component Inspector – CPU Common Settings

Select:

“pin_init:PinSettings”

1

Page 20: DWF-KDS-KSDK - Lab 4

TM

External Use 19

Configure Pin Settings

Click “Switch Configuration” 1

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

Page 21: DWF-KDS-KSDK - Lab 4

TM

External Use 20

Configure Pin Settings – per Schematic

GPIO Switches

GPIO LED’s

UART

Page 22: DWF-KDS-KSDK - Lab 4

TM

External Use 21

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

Page 23: DWF-KDS-KSDK - Lab 4

TM

External Use 22

Configure Pin Settings

Select

“GPIO”

Page 24: DWF-KDS-KSDK - Lab 4

TM

External Use 23

Configure Pin Settings : PTA 4

Click here

And

Select “PTA4/…”

Page 25: DWF-KDS-KSDK - Lab 4

TM

External Use 24

Configure Pin Settings : PTA 4

Select “Pin Functional Properties”

Right Click Here

2

1

Page 26: DWF-KDS-KSDK - Lab 4

TM

External Use 25

Configure Pin Settings : PTA 4

Select “Up”

Select “Enabled”

Click “Done”

1

2

Page 27: DWF-KDS-KSDK - Lab 4

TM

External Use 26

Configure Pin Settings : PTA 4

Enter “SW3”

Enter “Input”

Page 28: DWF-KDS-KSDK - Lab 4

TM

External Use 27

Configure Pin Settings : PTB 21

Click here

Select “PTB21/…”

Click here

Select “Output” Enter “LED_BLUE”

1 2

3

Page 29: DWF-KDS-KSDK - Lab 4

TM

External Use 28

Configure Pin Settings : PTB 21

NOTE: After settings made, notice both “Pin/Signal Selection”

and “User Pin/Signal Name” indicate “LED_BLUE” 1

Page 30: DWF-KDS-KSDK - Lab 4

TM

External Use 29

Configure Pin Settings : PTB 22

Click here

Select “PTB22/…”

Click here

Select “Output” Enter “LED_RED”

1 2

3

Page 31: DWF-KDS-KSDK - Lab 4

TM

External Use 30

Configure Pin Settings: PTB 22

NOTE: After settings made, notice both “Pin/Signal Selection”

and “User Pin/Signal Name” indicate “LED_RED” 1

Page 32: DWF-KDS-KSDK - Lab 4

TM

External Use 31

Configure Pin Settings: PTC 6

Click here

Select “CMP0_IN0/…”

Click here

Select “Input” Enter “SW2”

1

2 3

Page 33: DWF-KDS-KSDK - Lab 4

TM

External Use 32

Configure Pin Settings: PTC 6

Select “Pin Functional Properties”

Right Click Here

2

1

Page 34: DWF-KDS-KSDK - Lab 4

TM

External Use 33

Select “Up”

Select “Enabled”

Click “Done”

1

2

Configure Pin Settings

Page 35: DWF-KDS-KSDK - Lab 4

TM

External Use 34

Configure Pin Settings : PTE 26

Click here

Select “PTE26/…”

Click here

Select “Output” Enter “LED_GREEN”

1

2 3

Page 36: DWF-KDS-KSDK - Lab 4

TM

External Use 35

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

Page 37: DWF-KDS-KSDK - Lab 4

TM

External Use 36

Hardware UART Pins to Configure

Function Port Number Pin Number

Uart0 TX PTB17 62

Uart0 RX PTB16 63

Page 38: DWF-KDS-KSDK - Lab 4

TM

External Use 37

Configure Pin Settings: UART

Click here - Select “PTB16/…”

Select “UART” 1

2

Click here - Select “PTB17/…” 3

Page 39: DWF-KDS-KSDK - Lab 4

TM

External Use 38

Pin Muxing is Complete, Time to select & set

up the Components

Page 40: DWF-KDS-KSDK - Lab 4

TM

External Use 39

Selecting Components - Switch to Component Library

Click on

“Component Library”

to bring up the library

Scroll down until you begin to see

“fsl_xxx” components

1

Click on

“Alphabetical” 2

3

Page 41: DWF-KDS-KSDK - Lab 4

TM

External Use 40

Selecting Components

Double Click on

“fsl_gpio”

Double Click on

“fsl_pit”

Page 42: DWF-KDS-KSDK - Lab 4

TM

External Use 41

Selecting Components

Scroll Down

Double Click on

“fsl_uart”

Page 43: DWF-KDS-KSDK - Lab 4

TM

External Use 42

Selecting Components

• The component list should now look like this:

Page 44: DWF-KDS-KSDK - Lab 4

TM

External Use 43

Configure GPIO Driver Settings - Inputs

Double-Click

“gpio1:fsl_gpio”

to bring up

“Component

Inspector”

Click on the “Input pins” tab

1

2

CAREFUL: Click “+” twice on

“Input pins number” for 2 input pins 3

Page 45: DWF-KDS-KSDK - Lab 4

TM

External Use 44

Configure GPIO Driver Settings – Input SW2

Enter

“SW2”

Scroll Down if necessary and

select “Row #1” 1

Enter “SW2” in Pin 1 – Pin Field

Notice how remaining fields

are filled in and problems

related to pin are resolved.

3

2

Page 46: DWF-KDS-KSDK - Lab 4

TM

External Use 45

Configure GPIO Driver Settings – Input SW3

Scroll Down if necessary and

select “Row #2” 1

Enter “SW3” in Pin 2 – Pin Field

Notice how remaining fields

are filled in and problems

related to pin are resolved.

2

3

Page 47: DWF-KDS-KSDK - Lab 4

TM

External Use 46

Configure GPIO Driver Settings - Outputs

Scroll Back Up and

Select Tab

“Output pins”

1

CAREFUL: Click “+”

Three Times on

“Output pins number”

for 4 input pins

2

Page 48: DWF-KDS-KSDK - Lab 4

TM

External Use 47

Configure GPIO Driver Settings

Select row

“1”

Scroll

Down

Page 49: DWF-KDS-KSDK - Lab 4

TM

External Use 48

Configure GPIO Driver Settings

Enter

“LED_BLUE”

Page 50: DWF-KDS-KSDK - Lab 4

TM

External Use 49

Configure GPIO Driver Settings

Enter

“1”

Page 51: DWF-KDS-KSDK - Lab 4

TM

External Use 50

Configure GPIO Driver Settings

Select row

“2”

Enter

“LED_GREEN”

“1”

Page 52: DWF-KDS-KSDK - Lab 4

TM

External Use 51

Configure GPIO Driver Settings

Select row

“3”

Enter

“LED_RED”

“1”

Page 53: DWF-KDS-KSDK - Lab 4

TM

External Use 52

In the Component Inspector –

adjust “Period” to “1000 ms”Select

Configure PIT Driver Settings

Select “pitTimer1:fsl_pit” in Components View 1

2

Page 54: DWF-KDS-KSDK - Lab 4

TM

External Use 53

Configure UART Driver Settings

In the Component Inspector –

confirm PTB16 and PTB17 are set for RxD and TxD

Select “uartCom1:fsl_uart”

in Components View 1

2

Set “Baud rate” to “115200” 3

Page 55: DWF-KDS-KSDK - Lab 4

TM

External Use 54

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 application’s functionality

• The lab uses the FRDM-K64F board

• The application will blink an LED periodically, and light

LEDs with button presses.

Next up!

Page 56: DWF-KDS-KSDK - Lab 4

TM

External Use 55

Generate Code with Processor Expert

In the Components View – Click on the “Generate Processor Expert Code” Icon 1

Page 57: DWF-KDS-KSDK - Lab 4

TM

External Use 56

Generate Code with Processor Expert

Code is then generated by Processor Expert for the components that have

been added and configured in the project

Page 58: DWF-KDS-KSDK - Lab 4

TM

External Use 57

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.

Page 59: DWF-KDS-KSDK - Lab 4

TM

External Use 58

Generate Code with Processor Expert

main.c …

enough said…

Events.c contains the

ISR stubs for the

application

Expand

“Generated_Code”

folder in the Project

Explorer

Note: Go ahead and explore these files by double clicking on them and

use the “Editor View” to see how they are structured.

Page 60: DWF-KDS-KSDK - Lab 4

TM

External Use 59

Examine the Code

Expand the

edit window up

Page 61: DWF-KDS-KSDK - Lab 4

TM

External Use 60

Interrupt Routine: Blink the Green LED

Scroll down to

here

Open

Events.c

1

2

Page 62: DWF-KDS-KSDK - Lab 4

TM

External Use 61

Interrupt Routine: Blink the Green LED in PIT Timer ISR

TRICK: Drag & Drop “GPIO_DRV_TogglePinOutput”

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

Expand

“gpio1:fsl_gpio”

Open “Events.c” in Editor View 1

2

3

Add the parameter “LED_GREEN” to the

call – it should look like this when done

4

Page 63: DWF-KDS-KSDK - Lab 4

TM

External Use 62

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 application’s functionality

• The lab uses the FRDM-K64F board

• The application will blink an LED periodically, and light

LEDs with button presses.

Next up!

Page 64: DWF-KDS-KSDK - Lab 4

TM

External Use 63

Importing Files

Page 65: DWF-KDS-KSDK - Lab 4

TM

External Use 64

Drag and Drop

Use Windows Explorer to navigate to:

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

Page 66: DWF-KDS-KSDK - Lab 4

TM

External Use 65

Drag Lab4_main.c to Sources Folder

Page 67: DWF-KDS-KSDK - Lab 4

TM

External Use 66

Drag Lab4_main.c to Sources Folder

Click “OK”

Select “Copy Files”

1

2

Page 68: DWF-KDS-KSDK - Lab 4

TM

External Use 67

Open “Lab4_main.c” and “main.c”

Double-Click

“Lab4_main.c”

and “main.c”

1 Select “main.c”

for editing 2

Page 69: DWF-KDS-KSDK - Lab 4

TM

External Use 68

Add “Our” Code to main

Add declaration here

Add call here

Page 70: DWF-KDS-KSDK - Lab 4

TM

External Use 69

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 application’s functionality

Next up!

Page 71: DWF-KDS-KSDK - Lab 4

TM

External Use 70

Building the Project: Clean

Select the project “Project4” 1 Select the “Project” menu 2

Select “Clean…” 3

Page 72: DWF-KDS-KSDK - Lab 4

TM

External Use 71

Building the Project: Clean

Click “OK” 1

Page 73: DWF-KDS-KSDK - Lab 4

TM

External Use 72

Building the Project: Clean

Clean complete…

Page 74: DWF-KDS-KSDK - Lab 4

TM

External Use 73

Building the Project

Right Click

On

“Project4”

1

Select

“Build Project”

2

Page 75: DWF-KDS-KSDK - Lab 4

TM

External Use 74

Building the Project

Page 76: DWF-KDS-KSDK - Lab 4

TM

External Use 75

A look at the code

Page 77: DWF-KDS-KSDK - Lab 4

TM

External Use 76

Examine main.c

PEx

#includes here

main.c

Hardware initializations

Your code goes here

Your declarations

here

Page 78: DWF-KDS-KSDK - Lab 4

TM

External Use 77

Examine events.c

Timer callback code goes here

Page 79: DWF-KDS-KSDK - Lab 4

TM

External Use 78

Examine Lab4_main.c

#includes copied from

ProcessorExpert.c

Declarations needed for our code

Page 80: DWF-KDS-KSDK - Lab 4

TM

External Use 79

Examine Lab4_main.c

Main loop – watch for switch presses

Page 81: DWF-KDS-KSDK - Lab 4

TM

External Use 80

Examine Lab4_main.c

Switch press

routines

Delay loop

Print routine

Page 82: DWF-KDS-KSDK - Lab 4

TM

External Use 81

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 application’s functionality

− 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.

Next up!

Page 83: DWF-KDS-KSDK - Lab 4

TM

External Use 82

Option 1: Pull-Down Next

to Bug icon then select

“Debug

Configurations…”

Prepare PEMicro Debug Configuration

Select “Debug Configurations…”

Two ways to get there…

3a

Option 2: Select:

“Run Debug

Configurations”

IMPORTANT: First, select project root “Project4” in Project Explorer 1

3b

- OR -

2

Page 84: DWF-KDS-KSDK - Lab 4

TM

External Use 83

Select Debug Configuration

1 Double-Click on “GDB PEMicro Interface Debugging”

Note: Project Binary and Project

name populated automatically

2

Page 85: DWF-KDS-KSDK - Lab 4

TM

External Use 84

Select OpenSDA PEMicro Interface

Select “Debugger” tab and expand “Interface:” Drop Down List

Select: “OpenSDA Embedded Debug – USB Port” from list 2

1

Note: “Port:” is Auto-Filled if

board connected 3

Page 86: DWF-KDS-KSDK - Lab 4

TM

External Use 85

Configure Debugger Options

Expand “Device Name:” Drop Down List

Select: “K64FN1M0M12” from list 2

1

Click “Apply” 3

Page 87: DWF-KDS-KSDK - Lab 4

TM

External Use 86

Launching Debugger

First time: “Debug” from Debug Configurations Dialog

NOTE: Next time, select from pull-down list on the Debug Icon

(ALWAYS SELECT FROM LIST)

1

Page 88: DWF-KDS-KSDK - Lab 4

TM

External Use 87

Configure Automatic Debug Perspective

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

Check the “Remember my decision” box and click “Yes”

1

2

Page 89: DWF-KDS-KSDK - Lab 4

TM

External Use 88

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 application’s functionality

− 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.

Next up!

Page 90: DWF-KDS-KSDK - Lab 4

TM

External Use 89

Application Test: Debug Perspective

Console View Stack

Editor/Source View

Debug View

Variable View Stack

Breakpoint Disassembly

View

Page 91: DWF-KDS-KSDK - Lab 4

TM

External Use 90

Application Test: Single Step "Into"

Click “Step Into”

Editor moves

to this line

Page 92: DWF-KDS-KSDK - Lab 4

TM

External Use 91

Application Test: Single Step – Step Return

Editor moves back to next

executable line in main.c

Click “Step Return”

Page 93: DWF-KDS-KSDK - Lab 4

TM

External Use 92

Application Test: Single Step – Step Over

Click “Step Over”

twice

Instruction pointer advances to “sendstring…”

Page 94: DWF-KDS-KSDK - Lab 4

TM

External Use 93

Application Test: Run/Resume

UART “prints”

message to

Termite

Click “Resume”

Page 95: DWF-KDS-KSDK - Lab 4

TM

External Use 94

Application Test: Inspect Registers

Click “Suspend”

Expand “General

Registers”

1

Select “Registers” view 2

2

Page 96: DWF-KDS-KSDK - Lab 4

TM

External Use 95

Application Test: Inspect Registers

Changed registers

are highlighted

Click “Step Over”

Page 97: DWF-KDS-KSDK - Lab 4

TM

External Use 96

Application Test: Setting Breakpoints

Double click in column at location

to set breakpoint -

indicated with blue dot

Page 98: DWF-KDS-KSDK - Lab 4

TM

External Use 97

Application Test: Setting Breakpoints

Breakpoints can be disabled by un-checking

them in the “Breakpoints View”

… and re-enabled by checking the

associated box…

Page 99: DWF-KDS-KSDK - Lab 4

TM

External Use 98

Click “Reset target and restart debugging”

Application Test: Setting Breakpoints

Notice the program

stopped at the

Breakpoint

Click “Resume” 2 1

3

Page 100: DWF-KDS-KSDK - Lab 4

TM

External Use 99

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.

Page 101: DWF-KDS-KSDK - Lab 4

TM

© 2014 Freescale Semiconductor, Inc. | External Use

www.Freescale.com

Printed SEPT2014