element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Freedom development platform
  • Products
  • Dev Tools
  • Freedom development platform
  • More
  • Cancel
Freedom development platform
Blog [FRDM-KL05Z - mbed] Chapter 1: Create your first mbed project !!
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Freedom development platform to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: FreescaleTools_and_Software
  • Date Created: 23 Jul 2014 8:43 AM Date Created
  • Views 1159 views
  • Likes 0 likes
  • Comments 9 comments
  • cortex-m0+
  • Cortex-M
  • kinetis
  • frdm-kl05z
  • mbed
  • kinetis-l
  • cortex-m0
  • arm
  • freedom
  • kl05
Related
Recommended

[FRDM-KL05Z - mbed] Chapter 1: Create your first mbed project !!

FreescaleTools_and_Software
FreescaleTools_and_Software
23 Jul 2014

image

 

This document is part of a series:

[FRDM-KL05Z] Full-Review and Getting-Started

[FRDM-KL05Z - mbed] Chapter 1: Create your first mbed project !!

[FRDM-KL05Z - mbed] Chapter 1 bis: Create more mbed projects !!

 

 

Hello Freedom Lovers

 

I recently published a full-review of the FRDM-KL05Z including a Getting-Started guide to identify the compatible Software enablement and play with the Project Examples of the Sample Code package that Freescale delivers with its Freedom boards.

 

In order to facilitate your evaluation of the toolchains compatible with the Freedom boards, I will publish several tutorials to guide you from your first project creation until its debug.

 

ee9afd.jpg

 

Let's begin with the mbed online toolchain.

 

Following Freedom boards are also compatible with this ARM tool, FRDM-KL05Z, FRDM-KL25Z, FRDM-KL46Z and FRDM-K64F, so same instructions apply.
 
 
1. Introduction: What is the mbed proposal ?
 
The mbed platform provides free software libraries, hardware designs and online tools for professional rapid prototyping of products based on ARM microcontrollers.

 

The platform includes a standards-based C/C++ SDK, a microcontroller HDK and supported development boards, an online compiler and online developer collaboration tools.

Here are some details of what you'll get for basing your next ARM microcontroller powered product on the mbed platform:

 

- Software Development Kit (SDK)

The mbed Software Development Kit (SDK) is an open source C/C++ microcontroller software platform relied upon by tens of thousands of developers to build projects fast. We've worried about creating and testing startup code, C runtime, libraries and peripheral APIs, so you can worry about coding the smarts of your next product.

The SDK is licensed under the permissive Apache 2.0 licence, so you can use it in both commercial and personal projects with confidence.

The mbed SDK has been designed to provide enough hardware abstraction to be intuitive and concise, yet powerful enough to build complex projects. It is built on the low-level ARM CMSIS APIs, allowing you to code down to the metal if needed. In addition to RTOS, USB and Networking libraries, a cookbook of hundreds of reusable peripheral and module libraries have been built on top of the SDK by the mbed Developer Community.

 

- Hardware Development Kit (HDK)

The mbed Hardware Development Kit (HDK) provides full microcontroller sub-system design files and firmware for building development boards and custom products that benefit from the native support of the mbed SDK and free mbed Online Compiler and mbed Developer Platform.

The HDK specifies all support components and circuits including the mbed Onboard Interface design that provides simple USB drag-n-drop programming and CMSIS-DAP debug interface for the target microcontroller.

Development boards that are already based on the HDK are the quickest way to get started with the mbed platform. We manufacture official mbed Microcontroller modules that are specifically optimised for flexible rapid prototyping, and are available from distributors worldwide. Our partners are now also creating mbed-enabled hardware such as ultra low-cost ARM evaluation boards in the popular Arduino form-factor.

 

- Free Online Development Tools

The mbed Compiler is a powerful online IDE that is free for use with hardware implementing the mbed HDK, and tightly integrated with the mbed SDK and Developer Website. Under the hood, it relies on the industry standard ARM professional C/C++ compiler, pre-configured and tested to generate fast, efficient code without fuss.

Login anywhere to get instant access to your development environment, on Windows, Mac, Linux. You can even work from tablets!

Whilst the mbed Compiler provides you your own private workspace, it is also fully integrated with the mbed.org Developer Website so you can easily import libraries and examples. If you choose to, publishing your own code and collaborating with other mbed users is just a few clicks too. The mbed Compiler also supports full export to different toolchains, in case your project demands it as you go to production.

 

- Worldwide Developer Community

Using mbed means a huge shared context with other developers, and that means when you have a question, there is less pre-amble, less explanation and less time reproducing issues, and more time getting answers. We're proud that this has helped us grow an active and friendly community of skilled developers that are collectively helping get prototypes made even faster.

But where it really gets interesting is with code. Our developers are sharing thousands of open source repositories and building an extensive cookbook of recipes that you can reuse to build your products.

We've also made contributing back is easy; you can publish a library to mbed.org with a few clicks in the IDE, and let others build on your hard work. In fact, this is how some of our users end up collaborating on hard problems, and even getting contract work.

   

  

2. Prepare your FRDM-KL05Z for the mbed tool

 

First, you need to create an user account at www.mbed.org which is 100% free and quick.

 

90f1b2.jpg

 
Go to www.mbed.org/teams/Freescale/ and select the FRDM-KL05Z in the right panel below 'Platforms'

  

160553.jpg

  

You will find precious information about the board including the pinout of the embedded components (RGB LED, accelerometer, touch slider) and the Arduino headers.

 

1b0c3f.jpg   e16153.jpg

 

As mentioned in the FRDM-KL05Z full-review, the board embeds a multi-mode interface over USB named OpenSDA (see this document from GregC for more information)
Before using your FRDM-KL05Z, you need to load the right mbed OpenSDA application to get the board properly recognized by the tool.

 

a. To ensure a correct detection, download and INSTALL FIRST the mbed Windows serial port driver at: https://mbed.org/media/downloads/drivers/mbedWinSerial_16466.exe

Then donwload the mbed OpenSDA firmware/application for your board available at: http://mbed.org/media/uploads/sam_grove/20140530_k20dx128_kl05z_if_opensda.s19

 

b. Connect one end of the USB cable to the computer, then keep RESET button pressed while connecting the other end of the cable to the OpenSDA USB connector

9b5d30.jpg

 

c. From your file explorer drag'n drop or copy-paste the 20140530_k20dx128_kl05z_if_opensda.s19 file corresponding to the mbed interface into the BOOTLOADER drive

 

d. Unplug and replug the USB cable

 

e. Check in Device Manager that the following drivers have been correctly installed:

          Disk drives / MBED Microcontroller USB Device

          Portable Devices / MBED

          Port (COM & LPT) / mbed Serial Port (COMxx)

          Universal Serial Bus controllers / mbed composite device

 

696efa.jpg

 

A new mbed drive should also be available in your file explorer !!

 

186f02.jpg

 

Note: If you are using Linux or Mac computers, please check first that your bootloader is updated following the instructions of this tutorial

If you still experience some problem, you have no choice that to use a Windows machine to load the mbed OpenSDA application (single-time operation).

 

 

 

3. Download a mbed precompiled example

 

a. First download the appropriate "Hello World!" binary: HelloWorld_KL05Z.bin


b. From your file explorer drag'n drop or copy-paste the binary file HelloWorld_KL05Z.bin into the mbed drive.

The status LED of the FRDM-KL05Z will flash as the PC writes the file to the mbed OpenSDA buffer. When it is finished, the mbed drive should disappear and reappear and you should hear a tone.


c. Press the Reset Button.

When the Reset Button in pressed, the program loaded in the mbed drive will be programmed into the KL05Z Flash memory. The Status LED will flash during the operation.

When the program has been loaded onto the microcontroller, it will then start running automatically.

You should see now the RGB LED blinking red indefinitely ...

If you reset the Microcontroller, or disconnect and reconnect the power, the same program will simply restart.

 

To download a different program, simply repeat the previous steps with a new binary file (the latest file loaded in the mbed drive will be programmed after reset).

 

 

  

4. Open an existing mbed project example for the FRDM-KL05Z

 

Return to the page https://mbed.org/platforms/FRDM-KL05Z/

In the right panel, select Open mbed Compiler

 

ef2f83.jpg

 

A new interface window will automatically open and the FRDM-KL05Z will be automatically added to your profile in the section 'your platforms'

 

46c0d5.jpg

 

Select Create New Program from the toolbar

 

d2ba22.jpg

 

A popup window will appear with several Template for the Platform FRDM-KL05Z (my previous board connected have been automatically saved)

 

51e169.jpg

 

Let's try it out with the RGB LED example. Project is now creating ...

 

29a6c9.jpg

 

In the left panel, double click on the main.cpp in the folder My Programs / frdm_rgbled to notice how simple is the project thanks to the mbed functions

 

df714d.jpg

   

Select Compile from the toolbar.

 

9c3892.jpg

  

Project is now compiling ...

 

06f961.jpg

  

At the end of the compilation, the generated binary file *.bin will be automatically downloaded by your web explorer

 

6d3649.jpg

 

Follow the steps of the previous exercice 'Download a mbed precompiled example' to program the frdm_rgbled_KL05Z.bin file into into the flash memory of the KL05Z target.

 

 

 

5. Create from scratch your first mbed project for the FRDM-KL05Z

 

Return to the mbed compiler web interface.

 

Again, select Create New Program from the toolbar

 

d2ba22.jpg

 

The same popup window will appear

Select the Template option Empty Program

We will first create a basic project, which blinks Red Green and Blue LEDs alternately each second, so let's call it: FRDM-KL05Z_BlinkRGB

Press OK

 

5fa0a2.jpg

 

Your new project will now be displayed in the Program Workspace above the project example frdm_rgbled that we opened in lab 4.

  

fc9895.jpg

Expand project frdm_rgbled

Copy the mbed folder and paste it in the FRDM-KL05Z_BlinkRGB project (right click)

 

7545cd.jpg          c9ccd6.jpg

 

Then right click on the FRDM-KL05Z_BlinkRGB project and Select New File

 

c675e2.jpg

 

In the popup window, enter the file name: main.cpp

 

ccd9f1.jpg

 

Open the main.cpp file for the project FRDM-KL05Z_BlinkRGB and copy the text below

 

 

#include "mbed.h"             //mbed libraries

 

DigitalOut rled(LED_RED);     //Function DigitalOut defines if the output connected to LED_RED is high (means LED ON) when equal to 0 or low when equal to 1

DigitalOut gled(LED_GREEN);   //Function DigitalOut defines if the output connected to LED_GREEN is high (means LED ON) when equal to 0 or low when equal to 1

DigitalOut bled(LED_BLUE);    //Function DigitalOut defines if the output connected to LED_BLUE is high (means LED ON) when equal to 0 or low when equal to 1

 

int main()

{

    while(1)

    {

        rled=0;

        gled=1;

        bled=1;

        wait (1);           //Function wait with parameter in second

     

        rled=1;

        gled=0;

        bled=1;

        wait (1);

     

        rled=1;

        gled=1;

        bled=0;

        wait (1);

    }

}

 

 

I have inserted some comments in green for a better comprehension.

 

Double-click on the LEDs and a popup window in the top right corner will enumerate the port allocated (should be LED_RED=PTB8, LED-GREEN=PTB9, LED-BLUE=PTB10 according to schematics)

 

35a8f7.jpg

 

Double-click on the DigitalOut and a popup window will enumerate the function

 

ef4fd4.jpg

 

Click on Save-All to save project modification then select Compile from the toolbar

 

1d0705.jpg

 

If no error are detected your web explorer should automatically download the FRDM-KL05Z_BlinkRGB_KL05Z.bin generated by the compileur

As in lab 4 you need to copy-paste the bin file in the mbed drive, wait 5s the tone and press the reset button ...


CONGRATULATION !!  Your board is now blinking R..G..B  image


For the fun, you can modify the frequency (change the parameter in second in each wait function), the sequence ...

  • Sign in to reply

Top Comments

  • shabaz
    shabaz over 11 years ago in reply to dragonstyne +2
    It's actually easier than Arduino, but sometimes it feels like a secret No one believes it until they see it : ) It's like swallowing the red pill : )
  • DAB
    DAB over 11 years ago +1
    Excellent tutorial. I had been hesitant to try MBED, but I now have more confidence to go try. Thanks DAB
  • dragonstyne
    dragonstyne over 11 years ago +1
    I agree with DAB excellent job! -Steve
  • FreescaleTools_and_Software
    FreescaleTools_and_Software over 11 years ago

    In addition, the FRDM-KL05Z sold now below 9USD by Farnell is probably the cheapest solution to evaluate the mbed tool image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • FreescaleTools_and_Software
    FreescaleTools_and_Software over 11 years ago in reply to shabaz

    I fully agree with you, when ARM demonstrated me the first time the mbed tool, I couldn't believe it, as existing libraries really simplify the programming.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • FreescaleTools_and_Software
    FreescaleTools_and_Software over 11 years ago in reply to dragonstyne

    Thank you too for your nice comment

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • FreescaleTools_and_Software
    FreescaleTools_and_Software over 11 years ago in reply to DAB

    Thank you for your appreciated feedback

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 11 years ago in reply to shabaz

    It's like swallowing the red pill : )

    What was that like, I took the blue pill ... woke up with a headache and a rabbit standing there looking at me. image

     

    I do agree the mbed is a very easy solution .... as long as you have an internet connection.

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube