tutorial_ enlightning the freedom kl25z board _ mcu on eclipse

17
23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse 1/17 mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/ Tutorial: Enlightning the Freedom KL25Z Board Posted on September 7, 2012 8 Votes The schematics for the Freedom board is now available on the element14 Freedom Board site (you need to log into the element14 community first) as FRDM-KL25Z Schematics (SPF-27556_D).pdf (314.7 K)). So time to write a tutorial how to use the LED on that board. In “FreeRTOS with GCC, Cortex-M0+ and Kinetis KL25Z Freedom Board” and “A Shell for the KL25Z Freedom Board” I have used that board with an RTOS: FreeRTOS. But it is really easy to use that board without an RTOS (‘bare metal’) too. In this tutorial I’m providing step by step instructions to use the RGB LED on the Freedom KL25Z board with Processor Expert and the open source LED component. I’m using CodeWarrior which has the ARM gcc build tools integrated for the Kinetis family. This tutorial features the Freedom KL25Z board with the version 10.3 of CodeWarrior, but is applicable with minor changes for any other Kinetis board and as well for CodeWarrior for MCU10.2. Note: This post shows screenshots of the upcoming CodeWarrior for MCU 10.3 which is not publicly available yet, but will be soon. Additional Processor Expert Component Installation In this tutorial I’m using additional open source Processor Expert components which are not part of the CodeWarrior Eclipse standard distribution: LED: Universal LED driver Wait: Universal waiting functions Both *.PEupd files can be downloaded from the above links. To import them into CodeWarrior, I use the menu Processor Expert > Import Package: Then I browse to the *.PEupd files and select them to import. Hint: it is possible to import multiple components in a single step with selecting multiple files to import. After importing the components, it might be necessary to refresh the components list. To make sure all Processor Expert Views are loaded, I use the menu Processor Expert > Show Views: After importing, the LED and Wait component should show up in the Alphabetical tab of the Component Library view: Importing Processor Expert Package Show Processor Expert Views

Upload: kiqe-cid

Post on 30-Nov-2015

201 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

1/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

Tutorial: Enlightning the Freedom KL25Z Board

Posted on September 7, 2012

8 Votes

The schematics for the Freedom board is now available on the element14 Freedom Board site (you need to log into the element14 community first) as

FRDM-KL25Z Schematics (SPF-27556_D).pdf (314.7 K)). So time to write a tutorial how to use the LED on that board.

In “FreeRTOS with GCC, Cortex-M0+ and Kinetis KL25Z Freedom Board” and “A Shell for the KL25Z Freedom Board” I have used that board with an RTOS:

FreeRTOS. But it is really easy to use that board without an RTOS (‘bare metal’) too. In this tutorial I’m providing step by step instructions to use the RGB

LED on the Freedom KL25Z board with Processor Expert and the open source LED component.

I’m using CodeWarrior which has the ARM gcc build tools integrated for the Kinetis family. This tutorial features the Freedom KL25Z board with the version

10.3 of CodeWarrior, but is applicable with minor changes for any other Kinetis board and as well for CodeWarrior for MCU10.2.

Note: This post shows screenshots of the upcoming CodeWarrior for MCU 10.3 which is not publicly available yet, but will be soon.

Additional Processor Expert Component Installation

In this tutorial I’m using additional open source Processor Expert components which are not part of the CodeWarrior Eclipse standard distribution:

LED: Universal LED driver

Wait: Universal waiting functions

Both *.PEupd files can be downloaded from the above links. To import them into CodeWarrior, I use the menu Processor Expert > Import Package:

Then I browse to the *.PEupd files and select them to import.

Hint: it is possible to import multiple components in a single step with selecting multiple files to import.

After importing the components, it might be necessary to refresh the components list. To make sure all Processor Expert Views are loaded, I use the

menu Processor Expert > Show Views:

After importing, the LED and Wait component should show up in the Alphabetical tab of the Component Library view:

Importing Processor Expert Package—

Show Processor Expert Views—

Page 2: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

2/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

If not, a Refresh of the components might be needed:

Creating the Project

I use the menu File > New > Bareboard Project:

Next, I need to specify a name for my project:

LED and Wait Components—

Refresh Components—

File New to create a new project—

Page 3: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

3/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

Next, I select the MKL25Z128 as my device:

Hint: I can use the filter field to at the top of the dialog to filter the devices. In MCU10.3 I can simply type ‘kl25′, where in MCU10.2 I need

‘*kl25*’ as filter text.

Next, to select the debug connection. As the Freedom Board has the new OpenSDA on it, this is my choice:

Naming the project—

Selecting KL25Z1 28—

Page 4: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

4/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

In the next dialog, nothing has (or can) be changed. the ARM GNU GCC is the only (and default) tool-chain for Kinetis L (Cortex M0+) family:

Next, I select Processor Expert for my project:

OpenSDA as Debug Connection—

ARM gcc Build Tools—

••

Page 5: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

5/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

Pressing ‘Finish’ creates the project for me:

Page 6: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

6/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

In case the Processor Expert component are not shown, I need to open the components for the selected project:

CodeWarrior Projects View with Components—

Open Components for Project—

Page 7: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

7/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

Note: Now in MCU10.3 the project view and the Processor Expert Components view are clearly separate.

LED

To add the LED component, I select it and use the ‘Add to project’ context menu:

Hint: instead of using the context menu, I can double click on the component to add it.

I do this 3 times, one for red, blue and green color. As I have missing settings, they show up with an error marker in the Components view:

I’m changing the settings in the Component Inspector for the three LED’s:

1. Changing the Component name: this is an arbitrary name, and is used for the generated driver source files (.c and .h file). I name it LEDR, LEDG and

LEDB for the three colors

2. I specify a Field Name: this is an arbitrary name, and same name I used in the LDD (Logical Device Driver name)

3. As according to the schematics the cathode of the LED is connected to the microcontroller pin, I specify ‘no’ for this property

Adding LED Component—

3 LED’s in Components View—

Page 8: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

8/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

Linking to GPIO_LDD

According to the FRDM-KL25Z Schematics (SPF-27556_D).pdf, the RGB LED is connected to following pins:

Red: PTB18

Green: PTB19

Blue: PTD1

The LED’s need to be linked to the a GPIO_LDD component. For this I click into GPIO LDD property and use the drop down box to add a new component

for it:

This will create a new shared component:

As two of the LED’s are on the Port B (PTB18 and PTB19), I configure it as such. I specify the port (PTB) and press on the plus sign to add bit fields:

LEDR Settings—

New component GPIO_LDD—

Creating Shared Component—

Page 9: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

9/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

Next I configure the pin as output, and mark it for auto initialization so I do not need to call the initialization of it in my application:

The Field Name has to match the field name I used in the LED component.

Hint: If I specify the optional ‘Pin Signal’ name, then Processor Expert will document it in the list of pins used.

As the green LED is on the same port, I simply link to it:

As the blue LED is on port D (PTD1), I create a new shared component for it:

Setting up port and adding bit fields—

PTB1 8 and PTB1 9—

Green Led Settings—

Page 10: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

10/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

Similar to the other LED’s, I set up the properties for PTD1 and the blue LED:

With this, the blue LED settings look like this:

New shared component for blue LED (PTD1 )—

Settings for Blue LED—

Blue Led—

Page 11: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

11/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

Wait Component

As I want to busy wait between the LED toggling, I add the ‘Wait’ component to the project:

Generating Code

Now I have all my components together, time to generate code. For this I use the toolbar button:

This generates the code for my components:

Adding LED Code

The application main() is inside ProcessorExpert.c, where add my LED demo code:

Adding Wait Component—

Generate Processor Expert Code—

Generating Code—

Page 12: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

12/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

Hint: An easy way to add code and function calls to components is to use drag & drop.

Build

I build the project with the menu Project > Build Project or using the ‘hammer’ icon:

At this point there should be no problems, so the Problems view should just show empty:

Debug

To download and debug, I press the debug toolbar icon. An annoying thing in Eclipse is I first need to *select* the project first to select the right debug

configuration:

So I select the project, then hover over the icon to make sure my project is selected. Otherwise I use the small drop down of the debug toolbar icon to

select the right configuration:

LED Code—

Building Project with Hammer Icon—

Empty Problems v iew with no problems—

Page 13: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

13/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

30 THOUGHTS ON “TUTORIAL: ENLIGHTNING THE FREEDOM KL25Z BOARD”

Pingback: S-Record Generation with gcc for ARM/Kinetis | MCU on Eclipse

Pingback: OpenSDA on the Freedom KL25Z Board | MCU on Eclipse

Pingback: Tutorial: Accelerating the KL25Z Freedom Board | MCU on Eclipse

Pingback: Tutorial: Freedom with FreeRTOS and Kinetis-L | MCU on Eclipse

Pingback: Tutorial: Touching the Freedom KL25Z Board | MCU on Eclipse

Pingback: Tutorial: USB CDC with the KL25Z Freedom Board | MCU on Eclipse

Share this:

Like this: Be the first to like this.

This will start the debugger, and I can use the toolbar items in the Debug view to step through my code:

Source Code

The project I have created in above steps can be downloaded from this link.

Summary

The steps presented here are really generic, and work for many boards and microcontrollers, especially for the Kinetis family. All what I need to know is the

information to which pin the LED’s are connected. With this it is very easy to create a bare board (without RTOS) application blinking LED’s.

Happy enlightning

This entry was posted in Boards, Embedded Components, Kinetis, KL25Z Freedom Board, Processor Expert, Tips & Tricks and tagged Building,

Debugging, Embedded Component, KL25Z Freedom Board, Processor Expert, Tips&Tricks by Erich Styger. Bookmark the permalink

[http://mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/] .

Starting Debugger—

debugging the application—

Twitter Facebook Email LinkedIn Google +1

Like★★

Patrick Menter

on October 2, 2012 at 18:04 said:

This is an excellent example, shows how to use CW 10.3 and Processor Expert both on a small easy to understand example.

Pawel

on October 8, 2012 at 22:10 said:

Great! But OK board is super. The question is where to buy alone microcontroller? Is possible to buy in Poland?

Page 14: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

14/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

Erich Styger

on October 8, 2012 at 22:15 said:

Hello, not sure, but you should be able to get it through Farnell or any other distributor. They should have a Presence in Poland.

smiffytech

on October 10, 2012 at 03:33 said:

Have you changed the LED bean since you wrote this? I’m not seeing the LED at all under the alphabetical list, but LOTS of what look like board-

specific LEDs including FRBD_KL25Z_LEDRGB_RED (and GREEN and BLUE.) I guess I should be using these logical device drivers?

Erich Styger

on October 10, 2012 at 05:45 said:

No, the LED bean has not changed, but Freescale added their own LED LDD components now. So you could use these if you want, they

are using a similar approach as my bean. My bean is universal (works for all architectures), while the Freescale LDD LED ones are only

working for Kinetis and ColdFire+.

smiffytech

on October 10, 2012 at 03:37 said:

Further to above, I have imported the Wait package, and can’t see that in the list, either. This is CW 10.3, build ID 120924.

Erich Styger

on October 10, 2012 at 05:46 said:

Maybe your component list has not been updated. It does it automatically for me (Windows 7). Can you try to right click on the Component

Library view and use the ‘Refresh’ menu? then it should show up.

smiffytech

on October 12, 2012 at 02:29 said:

Ah, should have thought of that. I couldn’t see any obvious way to refresh (didn’t know about right-click.) I’ve got this on a WinXP

VM. As it happens, I’d shut it down; now I’ve fired it up again, it’s all there. I now have a copy of Win7 – is there any benefit to

moving over to that? (Both VMs have access to the CW workspace.)

Erich Styger

on October 12, 2012 at 08:31 said:

I’m using Win7 32bit and 64bit, but natively (no VM). I think that using Win7 vs XP there is no real benefit, apart of that all the new

stuff is focusing on Win7.

smiffytech

on October 12, 2012 at 07:33 said:

I’ve got all this building just fine – tried it on WinXP and Win7. HOWEVER (and it’s a big however) I’m unable to get CW to see the

board. I’ve picked up and installed the latest PE Micro drivers but when I plug in the board (I’ve tried two different ones) on both XP

and 7, I get a thing popup which finds USB storage on there, but P&E Connection Assistant always comes up (No Device Available)

Page 15: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

15/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

Pingback: Removal of Processor Expert for a Project | MCU on Eclipse

Pingback: Tutorial: printf() and “Hello World!” with the Freedom KL25Z Board | MCU on Eclipse

even with re-connections and re-boots. I know this isn’t an Erich Problem, but I’m not entirely sure where I should be looking for help

as P&E Micro’s support proved utterly useless when I had a similar problem with the Multilink for HCS08. (It took two lots of new

drivers to fix that.) Any pointers as to a half-decent support channel would be most welcome! I’m certainly stuck playing with 8-bit

stuff for the time being. (And my TI Stellaris LaunchPad, but I’m probably not allowed to say that here

Erich Styger

on October 12, 2012 at 08:37 said:

The LaunchPad is a fantastic board! Freedom of speech (in good sense) is important to me . I published a while back a how-to-

install tutorial in https://community.freescale.com/thread/93204, but looks with the migration to the new forum this is lost. I see if I

can dig this out.

luismgc

on October 20, 2012 at 20:11 said:

Hello.

I can see from the CPU component properties that the core clock is working at 20.97152 MHz in FEI MCG mode. With this configurtion, I believe

the crystal is not used at all.

The FRDM-KL25Z is advertised as being able to work up to 48 MHz. For this, the setting would have to be to use the PEE mode using the 8 MHz

external crystal with 22pF capacitor load. Is this correct?

I tried this setting but Processor Expert tells me that the max core clock is 20 MHz.

Do you have any information on the settings to use the MCU at 48 MHz?. Is there any source code for the out-of-the-box project that comes pre-

programmed?

Thank you.

Erich Styger

on October 21, 2012 at 08:48 said:

Hello,

yes, 48 MHz are possible. Have a look at my other FRDM post which is using 48 MHz:

https://mcuoneclipse.wordpress.com/2012/10/07/tutorial-usb-cdc-with-the-kl25z-freedom-board/

I hope this helps,

Erich

luismgc

on October 22, 2012 at 16:01 said:

Great.

Thanks. I just received my Freedom board a few days ago and discovered this blog while searching for information. Haven’t looked

at all the posts, but it looks great. Real good step-by-step instructions.

Thanks for the reply. I’ll take a look at the post.

Page 16: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

16/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

Pingback: Copy my CodeWarrior Project | MCU on Eclipse

Pingback: Tutorial: Bits and Pins with Kinetis and the FRDM-KL25Z Board | MCU on Eclipse

Pingback: Arduino Data-Logger Shield with the FRDM-KL25Z Board | MCU on Eclipse

Royce

on December 2, 2012 at 17:14 said:

Hello,

I’m trying out my FRDM-KL25Z, and selected this tutorial as my 1st project.

However, you have stopped short of explaining the debugging procedure.

There are several settings upon clicking the debug button,…when does one select a particular setting ? What are the right settings for this project?

Some issues:

1. In your photo, hovering over the debug button shows the tip: ‘Debug Freedom_LED_FLASH_OpenSDA. When I do the same (with the project

selected) I just get ‘Debug’ as the tool-tip.

2. When I try to debug anyway, I get an error message with a ‘No device available’ message.

However my board is connected, and I could drag other binaries to the board and run them.

3. After I do a build /build all, should I get some executable like bin/srec/s19 etc (not sure which one is the default)? But I can’t see any. When and

where are the produced ?

Sorry if my questions are ‘noobish’ but I have only used 8 bit MCUs & All this is new to me.

Thank You.

Royce

on December 2, 2012 at 18:04 said:

Well, I got point (2) sorted out from this thread:

https://community.freescale.com/thread/301232

and

http://mcuoneclipse.com/2012/09/20/opensda-on-the-freedom-kl25z-board/

This should really be made more clear by Freescale …. it is not mentioned even in the ‘Sample Code Package’ which I tried to use & had

this same error – threafter I found this blog.

But I’m still curious about (1) & (3).

Thanks

Erich Styger

on December 2, 2012 at 19:20 said:

about point 1: the hover shows the active debug configuration. In Eclipse, make sure you have selected the project root folder in the

project view, then the ‘debug’ icon will know which project to debug (this is one of the few Eclipse things which really is not done

very well). So always select the project to make it ‘active’. If you just have ‘Debug’, this means that you do not have launched a

debug configuration yet. Click on the small triangle on the right side of the ‘debug’ icon and select the configuration you want. If the

list is empty (Eclipse populates it with your history), select the sub menu ‘Debug as…’ > CodeWarrior Download. This should lead

you to the correct configuration.

As for point 3: this post explains how to generate S19 files with gcc: http://mcuoneclipse.com/2012/09/13/s-record-generation-with-

gcc-for-armkinetis/

Hope this helps,

Erich

Page 17: Tutorial_ Enlightning the Freedom KL25Z Board _ MCU on Eclipse

23/12/12 Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

17/17mcuoneclipse.com/2012/09/07/tutorial-enlighting-the-freedom-kl25z-board/

Erich Styger

on December 2, 2012 at 19:15 said:

Hello,

looks like you have sorted out point 1 and 2: you need to load the Debug Application.

For point 3: the output binaries are placed in the output folder as specified in the build settings. For KL25Z it should be a folder named

‘FLASH’.

As for generating the S19 file: see this post:

http://mcuoneclipse.com/2012/09/13/s-record-generation-with-gcc-for-armkinetis/

Hope this helps,

Erich

Royce

on December 3, 2012 at 11:06 said:

Thank you for your answers!

I finally got my 1st project working on the board.