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.
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.
Go to www.mbed.org/teams/Freescale/ and select the FRDM-KL05Z in the right panel below 'Platforms'
You will find precious information about the board including the pinout of the embedded components (RGB LED, accelerometer, touch slider) and the Arduino headers.
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
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
A new mbed drive should also be available in your file explorer !!
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
A new interface window will automatically open and the FRDM-KL05Z will be automatically added to your profile in the section 'your platforms'
Select Create New Program from the toolbar
A popup window will appear with several Template for the Platform FRDM-KL05Z (my previous board connected have been automatically saved)
Let's try it out with the RGB LED example. Project is now creating ...
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
Select Compile from the toolbar.
Project is now compiling ...
At the end of the compilation, the generated binary file *.bin will be automatically downloaded by your web explorer
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
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
Your new project will now be displayed in the Program Workspace above the project example frdm_rgbled that we opened in lab 4.
Expand project frdm_rgbled
Copy the mbed folder and paste it in the FRDM-KL05Z_BlinkRGB project (right click)
Then right click on the FRDM-KL05Z_BlinkRGB project and Select New File
In the popup window, enter the file name: main.cpp
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)
Double-click on the DigitalOut and a popup window will enumerate the function
Click on Save-All to save project modification then select Compile from the toolbar
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
For the fun, you can modify the frequency (change the parameter in second in each wait function), the sequence ...
Top Comments