This tutorial was extracted from Erich Styger blog http://mcuoneclipse.wordpress.com with his agreement.
I knew about mbed already for some time: watching students using it for an NXP enabled board. Pretty cool stuff: mbed is an online IDE and compiler with tons of software libraries for the supported platform.
So I was dreaming to have something like this for my own boards like the Freedom board. But because mbed only supported two dedicated NXP boards, that was a road block.
But then mbed announced recently that the mbed SDK is open source. Wow, that is interesting! And finally the announcement last week: mbed supports the KL25Z Freedom Board. Now they have my attention .
In a few words: mbed is a ‘cloud’ implementation of development tools and software libraries. As with any ‘cloud’ application, there are pros and cons:
- This is a online IDE with compiler: so no long download and installation needed
- Everything is online, as well the provided libraries/SDK: so if there is a bug fix or update, it is there already there, no need to download and update software tools .
- The IDE runs in a web browser (so I need access to the internet, ok, that’s something to consider as I’m travelling a lot)
- It comes for free
- It has a version control system integrated
So this sounds really exciting. Well, as with anything, there are pros and cons. I come to the cons at the end. The good thing is: it is really, really easy to use. I wish all other tool chains I use would be so easy. I explain this with the steps to create and download a program to the FRDM-KL25Z board with mbed.
Getting Started
Getting started only takes a few minutes, and registration is free of charge.
- Signup for an account at mbed.org.
- Read the KL25Z Getting Started guide here.
Programming the mbed Firmware
In order to download (not debug!) a program to the KL25Z board, the mbed S19 application needs to be programmed to the board using the OpenSDA bootloader. The detailed steps are explained in the Getting Started Guide here. Freedom Board users are familiar with the bootloader steps:
- Enter Bootloader mode
- Copy the mbed firmware file to the board
- Re-Power the board. Now it should enumerate as ‘MBED’ device
If using a file manager/extension under Windows, or if there are troubles to get the firmware file copied to the Freedom board: use the DOS shell/cmd to copy the file to the device.
Downloading an mbed Program
On http://mbed.org/handbook/mbed-FRDM-KL25Z-Downloading there is already a .bin file available to download with the steps how to do this. Basically it works the same as programming S19 files with the normal OpenSDA bootloader:
- Download the file
- copy it to the MBED device
- Reset/repower the board
Creating a Program
The page at http://mbed.org/handbook/Creating-a-program explains how to create a program. First I click on the ‘Compiler’ button (top right corner of the web page):
With ‘compiler’ mbed means the IDE+compiler+linker. Everything I need to build my application.
With ‘New Program’ I create a new one:
Next, I provide a name:
This creates my project files:
Double clicking on main.cpp opens the main() routine which toggles the RGB LED on the Freedom board:
With the ‘Compile’ button I build my application:
Similar to Eclipse, an output pane at the bottom of the window shows errors or if I was able to successfully build it:
On the right side the Program Details inform about the code/data size:
After building, opens a dialog from my web browser to download the program:
After downloading it, I can copy the file the MBED Freedom device.
Importing
The cool thing with a web based IDE like mbed is that you can share and use code and libraries. To import an existing program, I use the Import button:
Then I can filter and search for programs I’m interested in:
The easiest way to import it then is to drag&drop it the program workspace on the left hand side.
The really cool feature of mbed is that it comes with libraries and class description:
Exporting
It is possible to Export a program. This functionality is somewhat hidden behind a context menu:
This opens an Export Dialog:
I clicked the drop down:
And here the first disappointment: no CodeWarrior support .
But what about the ARM Embedded one, as CodeWarrior supports this? But this does not work neither:
I tried Code_Red, as this is Eclipse based and I have it on my machine installed. But it gave me:
Ok, but I do have IAR for Kinetis-L, so hopefully I’m lucky here. But again:
What worked was to export to Keil (but here my Keil IDE expired ).
What worked was exporting as zip file:
That’s at least something. But it had only my source file in it, and not all the other libraries.
Freedom Board Examples
The mbed Freedom support and community is growing, and there are already multiple Freedom board examples available with this link.
Summary
With mbed, it is possible to build and download a program to my Freedom board in a few minutes. Installing a typically IDE takes longer than this . The great part with mbed is that it has a big community (at least for the other platforms), with a rich software library behind it.
But it is not possible to debug the application on the board, at least I have not found a way to do it. This makes mbed limited a not very well suited for a typical embedded programming process in my view. Great for exploring things, but not for doing a real project? I have seen that there is a beta CMSIS-DAP mbed debug connection available for the NXP board, so hopefully this will exist for the Freedom board too?
That would be mitigated if it would be possible to export the projects to other IDE’s. I think CodeWarrior support or at least IAR would be needed. Otherwise I feel mbed is like a ‘golden jail’. And it is unclear to me how I could use mbed for a different Kinetis than the KL25Z board or for my custom board (as it requires a special bootloader).
But it is a great thing to start with a new board and to explore things, without investing into a tool chain. As for everything, there is a learning curve, and I just started exploring things. So if you know how to debug with mbed, or how to export things to Eclipse/CodeWarrior, post a comment!