Introduction: Freescale FRDM-K64F: USB Communication

Picture of Freescale FRDM-K64F: USB Communication

The Freescale K64F has features that make it ideal for controlling robot movement. For semi-autonomous operation, the accelerometers would allow one to do some dead reckoning and the magnetometer would allow for some absolute reference to improve the accuracy. It is not an ideal solution, but would be great for a fun robot.

But my first thought was to make a two wheeled robot (like a mini Segway). The accelerometers would be part of a closed loop system to allow the robot to balance. This robot would not be autonomous, but would be steered by a human. This project would not be simple, I am sure Dean Kamen spent many hours perfecting the Segway.

A first step in this project would be establishing a communication channel for controlling the robot. There are several options; Ethernet, several serial channels and USB. I even considered infrared. It is not native to to the FRDM-K64F, but I believe one could use the CMT (Carrier Modulation Timer) and some simple circuits to implement IR. But that is another project. I decided that USB would be a simple solution and investigated what was available. I found that Freescale has a USB stack that appears as a COM port. This Instructable shows how to use it in Windows, I believe it works in a similar way on other operating systems.

Step 1: What You Need

Picture of What You Need

Freescale FRDM-K64F

USB with mini-USB end

The USB cable is not included in the FRDM-K64F package. It is necessary for development. This is the minimal amount of equipment one needs to experiment with the FRDM-K64F.

Step 2: Setting Up Your FRDM-K64F

Picture of Setting Up Your FRDM-K64F

Freescale has created a cloud based solution for development on the FRDM-K64F. And they have a clever technique for communicating with the device. Browsers can't directly access the hardware without a plugin. Each type of browser would need a plugin written for it. When one connects the FRDM-K64F development port to the PC, a virtual drive is created. Freescale has used the virtual drive to load code to the FRDM-K64F. I have seen that technique before (i.e. the Smoothieboard), but this is the first time I have seen it married it to a browser based development environment. When one builds code in the development environment, one can save it to the virtual drive.

I mention this because they have done another clever thing. That virtual drive has a link to the development web site. There are two mini-USB connectors on the board. The one to the left of the Ethernet connector looking toward the end of the board is the development port. Plug into that connector and into your computer. As stated, the USB device on the development port is set to appear as a mass storage device. It should pop up a window, if it doesn't pop up, track down the device. On Windows, it will be the next available drive letter. If one has a DVD and a CD drive, it would be "F://".

In that drive will be an "mbed.htm" file. It has a link to the MBED web site. My device had the link below

http://mbed.org/device/?code=0240020154974E74A969B3CC

I don't know if that code is unique to my device or if it encodes for all K64F devices. I think the latter is likely and the above link should work for everyone.

Step 3: Register on the MBED Web Site

Picture of Register on the MBED Web Site

When you click on the link, it will take you to the mbed.org login page.

Click on "Signup".

Then click on "No, I haven't created an account before".

Fill in the form with your information and click on "Signup".

Step 4: Open the Development Page

Picture of Open the Development Page

I have mixed feelings about the cloud paradigm, but uses like this seem pretty cool. Once you are logged in, click on the "Compiler" link in the upper right corner. That will open the page where one can do Mbed development.

Step 5: Import USBSerial Program

Picture of Import USBSerial Program

I found more than one implementation of a USB stack. It seems to me that for Windows, the one I am using had the lowest barrier for success. There is a default "Hello World" app that supposedly runs on the USB. But it doesn't work on Windows unless you run an executable file. This implementation requires no executable, it uses the normal "inf" file that defines most USB devices. Here is the link to the USB stack I found useful.

https://developer.mbed.org/handbook/USBSerial

Go to the page at the above link.

Go down to and click the button that says "Import Program".

Go back to the Development window.

Select "Update all libraries to latest revision" and click on "Import"

Step 6: Compile USBSerial Program

Picture of Compile USBSerial Program

Select the newly imported program.

Click on the "Compile" button.

When the compile completes a Open/Save box pops up.

Choose "Save".

In the following window choose the MBED drive. That will load the program into the K64F program memory. The unit will reset and the program will run.

Step 7: Getting the USB COM Port

Picture of Getting the USB COM Port

As stated before there are two USB ports on the K64F. The program will be using the port to the right of the Ethernet port. If you plug into that port chances are you will get an unknown device in the Device Manager. The USBSerial page describes a way to solve the unknown device. I have attached the "serial.inf" file they have offered. But in Windows 8 (and others I am sure) Microsoft has decided that we can't be trusted to use unsigned drivers. More likely they have decided that signed drivers make them money. In any case, the "serial.inf" will not work in Windows 8 (and others). The Smoothie Board Project uses an Arm processor and I have found that their signed driver works. Unzip the attached file and follow the same procedure of browsing for the software, only this time go to the unzipped Smoothieware files.

Take note of the Com Port number that is created in the Device Manager. We will use it in the next step.

Step 8: Talking to the Com Port

Picture of Talking to the Com Port

We need a terminal program to talk on the serial port. I use Putty for SSH, it is a good terminal program for this case as well.

http://the.earth.li/~sgtatham/putty/latest/x86/putty-0.64-installer.exe

After it is installed, open it up.

At the top type in the Com Port number from the previous step.

Set the speed to 115200.

Click on "Open"

In the terminal window, one should see "I am a virtual serial port" show up every second.

Step 9: Establishing Two Way Communications

Picture of Establishing Two Way Communications

The K64F is talking to the PC. Now we want to talk to the K64F. I have written a program to control the tri-color LEDs from the terminal.

Replace the main.cpp with the attached file.

Switch back to the Development port

Compile and save the file to MBED.

Switch to the other port.

The commands are of the form COLOR:value where COLOR is RED, GRN, or BLUE the value is 0-255.

The separating character is a colon (:).

We now have a USB communications channel for controlling our robot. Note that this package includes several other USB packages. The USBHID package is the one we would likely use if we were to write our own PC controller.

Comments

About This Instructable

3,792views

45favorites

License:

More by steve.m.graves:Deodorant FrugalityFreescale FRDM-K64F: USB communicationRaspberry Pi Configured for a Maker Fair
Add instructable to: