This article will take a first time user of the NXP FRDM-K64F microprocessor development board though the steps necessary to get up and running within the online mbed development environment. This is intended to quickly get the user to the point where one can download a simple embedded program to the K64F development board.
The mbed development environment is a free online environment which runs with a browser window. Thus there is no need to install any proprietary development tools on your local computer. The only requirement of your local computer is that it must have a terminal emulation program available and certain operating systems "may" need special USB driver programs installed.
A few of the mbed development environment features include:
- USB drag and drop programming
- USB Virtual COM port for serial terminal
- CMSIS-DAP interface for programming and debugging from offline tools
- Free access to the mbed online compiler, mbed C/C++ SDK, and developer community
The mbed environment contains a wealth of development libraries, sample programs and user developed projects that can be imported into your own private environment for inspection as well as reuse depending upon licence restrictions within the code. In this regard the mbed environment is not unlike Hackster.io in the code sharing philosophy.
The Kinetis Design Studio is separate, offline development environment that is provided by NXP, the company that produces the FRDM line of processors. Due to its much different nature the Kinetis Design Studio IDE is out of scope for this discussion thus will not be mentioned within the remainder of this article.
OverviewThe following is a series of steps required to take a FRDM-K64F development board from out of the box to running a simple "Hello World" type of embedded application.
This discussion is broken up into several sections bases on the efforts required.
- Section 1 Identifies the important components built into the K64F development board.
- Section 2 Details a couple of items required of your local computer in order to communicate to and from the K64F board.
- Section 3 is about getting the the K64F firmware up to date for use with the mbed environment.
- Section 4 walks through the steps needed to get registered with the mbed development environment.
- Section 5 contains a bit about getting to know the Compiler. As this is intended to be a quick start we will touch upon very little of the compiler capabilities.
- Section 6 has us downloading the compiled binary to your local computer.
- Section 7 starts the program execution.
So, lets dive in.
Section 1. The FRDM-K64F development boardThis is a picture of the K64F development board labeled with the few components that we will be using for this exercise.
A few of the board features include:
- FXOS8700CQ - 6-axis combo Sensor Accelerometer and Magnetometer
- 2 user push-buttons
- RGB LED
- micro-USB connector used for programming and printf style debugging
- Ethernet connectivity
- up to 5x UARTs, 2x SPIs, 2x I2Cs and 1x CAN connected to Headers (multiplexed peripherals)
- Micro SD-Card Socket
- Headers compatible with Arduino R3 shields (32-pins / outter row)
- Drag-n-drop MSD Flash-programming
A full listing of the development board features can be found on the mbed platform page for the K64F at: https://developer.mbed.org/platforms/FRDM-K64F/
Section 2. Support for K64F communication to your PCProviding support for the USB Virtual Serial Port.
The binary file created and downloaded by the compiler must still be uploaded to the K64F development board. This is done via a virtual USB serial port connection between the PC and the K64F.
Mac and Linux machines will by default support this mbed serial port.
Windows platforms may need special drivers installed in order to communicate properly.
NOTE: A couple of things to note on the Windows platform when installing the driver:
- make sure the K64F dev board is plugged into a USB port
- When you do plug in your K64F board an Explorer drive window should open corresponding to the drive assigned to the development board. Be sure to dismiss the Explorer drive window before attempting to install the driver. If you do not the driver install will most likely fail.
Refer to the following mbed documentation link for specific instructions for installing the the driver on a Windows platform : https://developer.mbed.org/handbook/Windows-serial-configuration
To ensure proper driver installation on your local computer plug in the K64F development board into an available USB port then verify:
- Windows - Within the "Ports" section in "Device Manager" (''Start -> Control Panel -> System -> Hardware -> Device Manager''). The added serial port should be labeled ''mbed Serial Port (COMx)'', where ''x'' is the number of the COM port allocated.
- Mac OS X - The port name will have a prefix of tty.usbmodem. To verify use the command "ls /dev/tty.usbmodem*".
- Linux -The port name will have a prefix of ttyACM. To verify use the command "ls /dev/ttyACM* ".
The embedded program running on the K64F board can communicate with your computer for the purposes of outputting debug messages or obtaining user input. This communications is accomplished via a terminal emulation program. The following mbed documentation link provides details for installing and configuring a typical terminal emulation program
.https://developer.mbed.org/handbook/Terminals
Note: The standard default serial communications settings for the port is 9600 baud, 8 bits, 1 stop bit, no parity. (9600-8-N-1).
Section 3. Preparing the K64F for using within the mbed environmentDepending on the manufacture date of your FRDM-K64F board it may need to have the firmware updated in order to be compatible with the mbed environment.
Note: To connect the K64F development board to your computer locate the USB adapter cable ( USB Type A to USB Micro B 5 pin). Plug the type A end into your computer, the Micro B end into the K64F connector that is labeled SDA USB. This connector is also highlighted in the image above, next to the Ethernet port connector.
The following link provides the details for determining the current board revision level, manufacturer's available revision level as well as details for updating the board firmware if needed.
FRDM-K64F firmware: https://developer.mbed.org/handbook/Firmware-FRDM-K64F
Section 4. Getting registered with mbed.orgThis first step in using mbed is to get registered with the mbed developer site. On this site you will find a wealth of information describing the development tools, supported hardware platforms, sample programs, developer forums, etc.
The mbed online environment contains a great deal of getting started information. The intent of this guide is to get you up and running with minimal reading, however if you have difficulty you may need to refer back to the full documentation. Here are just a few links to get you started if you need more details than this article provides.
Getting started with mbed: https://developer.mbed.org/getting-started/
Getting started with the FRDM-K64F platform: https://developer.mbed.org/platforms/FRDM-K64F/
Top level of the mBed Handbook: https://developer.mbed.org/handbook/Homepage
For the purpose of this discussion we will jump right into the developer site. Note: the mbed community strongly suggests only one login per user. As I had already registered a couple of years ago and to remain a good community citizen I will not be reproducing the registration screens here. Also the initial view of the online compiler may differ slightly from my current view.
Navigate to the mbed registration page: https://developer.mbed.org/account/signup
Here you have two options, choose the second, "No, I haven't created an account before". Follow the registration screens and instructions. Once the registration is complete and you have successfully logged in as an mbed user you can continue the steps below.
Section 5. Getting to know the CompilerOnce registered on the mbed site you will have access to the 'compiler" page that you may have noticed in the menu bar. Click on the "Compiler" menu option and you should see a view of the mbed IDE similar though not exactly like what is shown below. This is the view when the "Help" menu item has been selected.
For further details about the mbed compiler see the following link: https://developer.mbed.org/handbook/mbed-Compiler-Getting-Started
1. Add the target platform/s to the compiler settings.The mbed platform supports many different hardware vendors as well as many different processor boards that these vendors have developed. When compiling an app you must choose what platform you are targeting. This can be done when importing a program or prior to importing via the selected platform button in the far upper right corner of the compiler window.
To add a new platform click on selected platform button which should currently be labeled "No device selected". When the following dialog opens, click on the "Add Platform" button.
When the "Add Platform" button is clicked a new browser window should open up to the developer.mbed.org/platforms page. From there you can find all of the platforms supported by the mbed environment. For our purposes we need to locate the NXP FRDM-K64F platform. So in the filter area on the left side of the page locate, within the "Target vendor" section, "NXP Semiconductors and select it's check box.
When the window refreshes you should be shown only NXP platforms. Scroll down until you find the FRDM-K64F platform and click on the image. This will take you to the information page for the K64F platform. Here you can find all of the details needed to develop on this particular platform.
Notice on the right side of the page you see the "Board Partner" frame with the NXP logo as seen below.
Scroll down a bit until you see the "Add to your mbed Compiler" button, then click it. When the platform has been added to your compiler configuration you will see the platform page refresh and there will now be a couple of new buttons in this same area.
The first button displays "Open mbed Compiler". Clicking this will open a new tab with a refreshed update of your compiler environment. If you wish you can go back to your previous compiler tab but you will need to refresh the page before the newly added platform is reflected in that tab.
The platform just selected, FRDM-K64F should now be displayed on the selected platform button in the far upper right corner of the compiler page.
The second button added is "Remove". Should you wish to remove this platform from your compiler configuration you would return back to this page and click on "Remove". If the platform just removed is named as the selected platform on your compiler page you need to refresh that page in order to see the change reflected on the selected platform button.
After having added the platform, when you open the new compiler tab or refresh an existing tab you should see the platform name displayed on the selected platform button, as shown below, rather than "No device selected" as seen earlier.
Alternatively a platform can be added by going directly to any target platform description page and choosing the same "Add to your mbed Compiler" button as we had seen in the previous steps. You are not required to go through the compiler page when adding a platform configuration.
With the platform set you can now search for a sample program to run.
2. Search for a sample program or libraryMuch like with Hackster.io within the mbed environment you have access to many, many applications and libraries. These are freely available for testing purposes however be sure to check on licensing requirements if you plan to build a production application.
The "compiler" window contains a "Help" menu item. This will open up a tab within the compiler window that will step through the details for getting started as well as importing a program or library. We will not duplicate all of that here but will take a quick start approach.
To search for an example mbed application or library open up another browser tab and browse to https://developer.mbed.org/. From within the developer landing page, locate the search box at the top right of the page. Enter a search term for the name of the program or library of interest, for our purpose enter "frdm_helloworld".
There may be one or more projects of the same name choose the one with the latest date, as of this writing it was Mar 30, 2016.
3. Importing the program into your project environmentOn the right hand side of the project page, locate the "Repository toolbox" group box then select "Import into Compiler". This will open up the following dialog box:
Here you can see the import is a program vs. library with a default name of frdm_helloworld. You can keep the default name or change it as needed. Select the "Import" button to complete the import process. As you notice the import process will open a new "Compiler" tab within your browser windows.
Note: Because the import process opens the new compiler tab any existing compiler tab that is open is now out of date. When you revisit that preexisting tab you will be notified of the need to refresh that preexisting tab.
When the program has been imported the dialog will be dismissed and the new program will be opened as the current working program. At this point one can double click on one of the source files to open it for inspection. The code for this project has been duplicated in the code section of this article.
More code importing details and methodologies can be found at: https://developer.mbed.org/handbook/Importing-code
4. Compile your first programWhen ready to compile the program locate and click on the 'Compile" menu item. This should result in a Compiling status dialog being opened . The dialog is dismissed when the compilation is complete.
If the compilation fails be sure to verify there is a platform defined for the program. The platform name should be reflected on the button at the far top right corner of the compiler window.
The "Compile output for program ..." view will show the status of the compilation step. It may display warnings but should show a success with a green arrow as the final result.
If successful the .bin binary file should have been downloaded to your local file downloads directory and may be listed at the bottom of your browser window.
Further compiler details can be found at: https://developer.mbed.org/handbook/mbed-Compiler
Section 6. Uploading and executing your first application.Now that you have successfully compiled a program it's time to upload it to the K64F development board.
Note: To connect the K64F development board to your computer locate the USB adapter cable ( USB Type A to USB Micro B 5 pin). Plug the type A end into your computer, the Micro B end into the K64F connector that is labeled SDA USB. This connector is also highlighted in the image above, next to the Ethernet port connector.
When the K64F is plugged into the PC's USB port a new drive window labeled "mbed" will open. In that drive window should be displayed 2 files. The file Details.txt lists the current firmware installed on the board while mbed.htm is an html file that when loaded into a browser will take you to the platform page for the FRDM-K64F.
Locate the compiled .bin file created in the previous compile step. It may be at the bottom of the compiler browser window and/or within the users Download directory. Drag that file into the "mbed" drive window and drop it along side the two existing files. I have found on occasion that if I am in a hurry I might accidentally drop the file onto the desktop rather than within the "mbed" drive window.
Immediately after you drop the binary you should see it being copied into the "mbed" drive window. The act of dropping the file also results in the .bin file being uploaded to the K64F board. The green led on the K64F board will flash confirming the program is being loaded.
After the upload has completed the "mbed" drive window will close and reopen. When it reopens the binary file will no longer be seen, only the Details.txt and mbed.htm files.
Section 7. Program ExecutionWhen the program executes it will attempt to display debug messages to the terminal emulator. Thus, activate the terminal emulation program and connect to the virtual USB port configured above in section 2.
Make sure the port is configured for the default settings of 9600 baud, 8 data bits, 1 stop bit, no parity. In addition one may need to configure the emulator to implicitly add a carriage return for each line feed sent from the board.
Once the "mbed" drive window has refreshed from the drag and drop upload, press the "reset" button on the K64F to start program execution. This example program exercises the two software buttons and the multicolored led. It also sends data to and reads data from the terminal emulator.
To exercise the sample:
- 1. Upon program startup the following message should be dsplayed on the termial emulator: "Hello World from FRDM-K64F board.
- 2. Next press the "sw2" button once. This should result in the multicolored led turning on red.
- 3. Next press the "sw3" button once. This should result in a green led. You should also see the message "5 characters will be echoed. Start typing" displayed on the terminal emulator.
- 4. Enter any 5 characters via the keyboard. They should be echoed back to the terminal screen.
- 5. Pressing the "sw2" button again will repeat the exercise.
Refer to the code section for program details.
At this point the program has been loaded into the K64F board's nonvolatile memory. Thus, if power is removed and then restored this same program will continue to run until a new program is uploaded.
SummaryCongratulations by following this article you should have been able to:
- Install the prerequisite USB drivers, if required and a terminal emulator program
- Verify your development board has the required firmware level installed
- Register with the mbed development community
- Use the mbed compiler to import. compile and download a simple program
- Upload and execute your first mbed embedded program
Enjoy working within the embed environment and feel free to comment to add suggestions/updates for this article.
Comments
Please log in or sign up to comment.