Introduction to Mbed Environment

Mbed is a complete environment for developing ARM controllers. One of the main attractions of MBed is you can get started very quickly and you can put together working prototypes extremely quickly. The Mbed Hardware platform has grown significantly in resent years, with around 50 development boards supported. There is A HDK available so you can build your own hardware but using cheap readily available development board like the K64F is the simplest and most common way to sue the environment.

So why would you use Mbed over a vendor specific flow ? There are a number of reasons but the biggest reason is you can get something working fast, very fast.   You don't have to worry about setting up toolchain, downloading and configuring support libraries, you can quite literally  be up and running in minutes. The Mbed environment comes with an online IDE with build in version management, so there is no setup to be done, just login and go! (the sign up is free). When starting a project you are faced with many different processors and variants, using Mbed your code is pretty much portable, so if you have to switch to a different board your code should work with almost no changes, so again you can get started before you make your final decisions

Of course there are some drawbacks, the online IDE works really well, my Hard-disk died and I simply moved to a different machine and I could continue to work, no backup restore, no tools to download. However once your  projects get bigger you start to miss some of the editing feature you find in desktop editors, like code completion. Probably the biggest limitation of the online IDE is the lack of a built in debugger. However there is the ability to export your project to an external tool and this seems to work well, so if you need advanced editing or better debug you can simply export your IDE project and work from your desktop. There is a a very big list libraries which means you can nearly always find a library for what you want, which is partly the reason why you can put applications together so quickly. The libraries fall into two categories official libraries and community contributed libraries. The community contributed libraries can be very good however often they are tested against a single platform so you need to take care.  

The K64F is a very good board to use with MBed it has Ethernet connectivity built in which gives you many more options without having to add on external boards and it has plenty of RAM and FLASH, which is very helpful if you are putting things together quickly as the libraries you are using may not be optimized for size. It can be surprising how quickly you can use the memory!

 

Getting Started.

The online IDE environment will work with Linux, MAC and PC. I'm going to go through the process with Windows.

Go to https://mbed.org/ and click on the Developer Site . Register and login.  Its probably a good idea to look through the site The Handbook is a good place to start

You'll want to communicate with your K64F, e.g. send debug and status information for this you'll need a terminal program, if you don't have one installed there are several free versions I've used terra term and RealTerm  but CoolTerm is also popular.

On windows you need to install the serial driver you can get the driver from here Windows serial configuration - Handbook | mbed

Update the Firmware on your board,  this is a simple procedure the step by step instructions can be found here http://developer.mbed.org/handbook/Firmware-FRDM-K64F

(note when copying files onto your K64F via the USB drive, they are not stored there, so don't worry when they disappear after a reset. Also ensure you use the correct usb connector it's the one closet to the reset switch)


The above steps should not have taken long and you should now be ready to start creating some programs.  Before we start on our application we can run a quick test to ensure everything is working and we can communicate with your chosen terminal program;

Go to the Mbed Compilier, It's normally the link on the top right of the mbed developer page

This will take you to your program workspace

On the top right of the workspace there is an icon showing your currently selected platform, you can use this to change or add more platforms (e.g. if you want to add a new board)

Select new>program

This will bring up the Create Dialog

The Platform should be set at K64F

You can use an existing program as your template, select the frdm serial example, then press OK

you will now have a new program which contains the core mbed library and main.cpp. Note all your mbed programs will need the mbed library, if you import a program it's always a good idea to update the mbed library as the program may be using an old version.

Open main.cpp

You'll see it doesn't do much , it makes a serial connection over the USB port using

Serial pc(USBTX, USBRX);

it sends "Hello World" to the pc

it then loops toggling the LED and sending  the loop counter to the pc.


Compile the program it should compile fine and will download a .bin image file


Connect your board to the PC using the USB cable , use the USB connector nearest the reset button. At this stage there is no need to supply any external power the USB port is able to power the board. Open a file Explorer and you will see that your board shows up as a drive


 

Drag and drop the compiled .bin onto the MBED drive, this will automatically program the device. Open your terminal program and select the Mbed serial port. The Mbed serial port may show up differently on differnt terminal programs On some it shows up as expected on others you simply get the a com port number. If you want to find out the COM port number it should be show in printers and devices

 

 

Configure the terminal port for 9600 Baud , 8 bit , i stop and no parity, These are common defaults.

Press the reset button on the K64F board and the LED on the board should flash and the terminal should show Hello World followed by the loop count

 

So we now have a working flow, hopefully that was pretty straight forward.

 

Next we'll start on a simple application that has a few more features and uses the the boards Ethernet connectivity.

Part two K64F MBED Part 2 Weather Station