Return to Tutorials

mbed – FRDM-K64F

What is mbed

We discused on the last post what are the Tiva C that are ARM Cortex-M platform based.  Well mbed gets the ARM Cortex-M microcontrollers and helps with very useful circuitry.  In this case we will use the Freescale Freedom K64F.


Of course there is also a set of platforms that you could use.  Some brands that use to do platforms for mbed are:

  • NXP Semiconductors
  • Nordic Semiconductors
  • STMicroelectronics
  • Freescale Semiconductors

They also use the online compiler (you can also export the project to Keil or IAR IDEs for debug capabilities), programming libraries and handbook plus cookbooks for fast prototyping your own project as fast as possible and test your new product as fast as you can.


The programmig of the mbed is done via USB. When you connect your mbed device you view it as a mass storage device and when compiled the program the browser (online compiler) asks you where to download.  Finally a reset button is needed to reboot the SoC (System on a Chip) to test your application.

Note:  Unfortunately, the Tiva C Series, right now doesn’t supports mbed platform.

mbed Architecture

Depending of the rand every board has different capabilities (in input/output MEM and communications).  In the board that we are analyzing has a plenty of interface and a “Arduino like” connector.


If you want to view the block diagram of the microcontroller, there is no clear block diagram of it in the datasheet, its sectioned in small modules so don’t expect view a full and complete overview of this MCU (does it matter?).  But basically, remember, its an ARM Cortex-M4 with floating point unit architecture and surrounded of hardware (on chip) modules to complete the full microcontroller.

Getting started with our mbed bard

For our first try i was viewing the capability of putting all together.  First you need:

  • The mbed (ANYONE) board, i use the FRDM-K64F
  • A computer with Windows, Linux or MacOS
  • A web browser installed

You could use this guide or follow me.

Then, the next step is to connect your mbed board to your computer.  Then you will se the mbed.htm link opened with the mbed K64F platform loaded as an USB.

Next go to the link of your platform and if you haven’t installed go to the webpage and follow the instructions to install the leatest serial port driver for communicate with your board.

Download the sample .bin file of the hello world application to your board, the download port is the most rightest USB port if you put your board with the ethernet connector on top.

Press the reset button and then view your led blink.

When you are done and bored about view some other code to succedd, then go to the next section to create your own program.

Review the platform page very well, there are the:

  • Schematics
  • Datasheets
  • Firmware
  • Example of libraries

Of the current K64F board

Writing a different mbed LED blink program.

Finally i want to understand how to address the ports, manage delay, the basics when you are in embedded systems for understand how to get interface for the real world.  Then i decided to do the same led application using I/O ports.

You could find the program in my mbed repository.

The program is C/C++ like in some ways, here it is:

*                              HTTP://WWW.CERESCONTROLS.COM
*                              PANAMÁ, REPÚBLICA DE PANAMÁ
*  File          : main.cpp
*  Programer(s)  : Rangel Alvarado
*  Language      : C/C++
*  Description   : RGB Led Blinking using GPIO
*  Notas         : Using standard mbed classes to start in mbed and blink a RGB
*                  led detailed on the manual below.
#include "mbed.h"                     // mbed supported libraries
DigitalOut R(PTB22);                  // PTB22 = Red   pin
DigitalOut G(PTE26);                  // PTE26 = Green pin
DigitalOut B(PTB21);                  // PTB21 = Blue  pin
typedef unsigned char INT8U;          // typedef of unsigned char
typedef union {                       // union for easy access of RGBLed
    INT8U RGB;
    struct {
        INT8U r :1;
        INT8U g :1;
        INT8U b :1;
        INT8U   :1;
        INT8U   :1;
        INT8U   :1;
        INT8U   :1;
        INT8U   :1;
    } Bits;
    struct {
        INT8U RGB :3;
        INT8U     :5;
    } MergedBits;
                                       // Main application
int main(void)
    char   colors;                     // variable for color
    RGBLED RGBled;                     // structure for led
    RGBled.RGB = 0x00;                 // clean outputs
    while(1) {
        for(colors = 0x00; colors < 0x08; RGBled.RGB = colors++) {
            R = RGBled.Bits.r;         // set red
            G = RGBled.Bits.g;         // set green
            B = RGBled.Bits.b;         // set blue
            wait(0.5);                 // software delay 0.5s
    return 0;                          // never pass here!!!

Explaining the above solution:

I assigned on the first lines the outputs, view the user guide on section 10, page 15, here are the assigned LEDs, red, green and blue, they are on:

  • RED = PTB22
  • BLUE = PTB21
  • GREEN = PTE25

So i first assigned the outputs to those pins.  Later i made an union and structs for easy understanding of what i will do later; basically i create a easy representation of the leds to follow. I will discuss it later.

On the main routine i created the variables colors and the union/struct RGBled for control in the program.

Next i do a 8-cycle forever of the set of leds, because we have 8 combination in 3 leds (2^3) we can show the combination of red, green and blue spectrum.  The key here is in the for loop.  RGBled.RGB = colors++ means that FIRST i pass the number first to the union AND THEN increment colors.

Finally i assign each bit of the RGBled structure to each output, making it easy to understand.

In example, when the colors count is five (5), the binary will be 00000101, so when i access the structure of bits in the union using RGBled.Bits.r, RGBled.Bits.g or RGBled.Bits.b:

  • red     = 1
  • green = 0
  • blue    = 1

And that’s all.  Finally i show you the very short video showing it works well.


Permanent link to this article:

1 comment

1 ping

  1. very good !!

  1. […] mbed – FRDM-K64F […]

Leave a Reply

Your email address will not be published.