Using FEX Cobra as a USB Device

Is it possible to use the FEZ Cobra as a USB Device (not a host)? If so could someone please direct me to documentation describing how to accomplish this? At the moment I am particularly interested in setting up the Cobra as a HID device.

Also, if this is possile, can the USB device port be used to debug the USB device application and run the HID device at the same time?

Thanks for any assistance you can provide.

Regards,
Synapsys

Yes absolutely, see USBclient class in docs http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation/Index.html

Thanks for your quick reply Gus :slight_smile:

I’ll study the classes you suggested…

Regards,
Synapsys

Do not forget that the free ebook has plenty of examples

Hi Gus,

[quote]Do not forget that the free ebook has plenty of examples
[/quote]

I looked at the ebook example in section “USB Debugging with Virtual COM Channel” and am confused. The code there appears to be the same as the code in section “CDC - Virtual Serial”. The first thing the code does is check if USB is the current debugger and throws an exception if it is.

So I commented out that line and changed the code as follows:


// I commented out this line
//USBC_CDC cdc = USBClientController.StandardDevices.StartCDC();

//and replace it with this line:
USBC_CDC cdc = USBClientController.StandardDevices.StartCDC_WithDebugging();

I deployed the code in the Visual C# 2010 Express debugger and it ran (i.e. TeraTerm printed “Hello World” once every second. So far so good :wink:

I stopped the debugger using the “Debug|Stop Debugging” menu item in Visual C# but the code appeared to continue to run (i.e. TeraTerm continued to print “Hello World” every second). So I closed Visual C# and unplugged the Cobra board USB. When I plugged the board back in it ran the code again without starting Visual C#. So I pressed the Reset button on the board and it stopped running the code.

I restarted Visual C#, rebuilt the project and tried to run it again. Visual C# attempted to deploy the assemblies but after a few seconds it displayed an error dialog that indicated that “There were deployment errors. Continue?”. If I continue I get a second error dialog that indicates “An exception occurred while trying to launch the debugger: Object reference not set to an instance of an object.”.

So now I cannot deploy anything more to the Cobra board :’(

Do you have any suggestions on how I can recover from this situation?

Regards,
Synapsys

Make sure you have the correct NEMTMF SDK 4.1 QFE 1 from our downloads.
Maybe disconnecting/connecting…etc made problems with the USB driver. Restart PC. Make a new project and select USB for deployment, it should work fine. These problems should not normally occur.

Hi Mike,

I did as you suggested, restarted the PC and made a new project. I selected USB for deployment and there were no USB devices listed. So I pressed reset on the Cobra and EMX_EMX appeared.

I built the new project and ran it but it still failed durng deployment with the same errors.

I’m thinking that I need to erase everything and reload all the firmware. The readme file in the EMX firmware folder in the SDK folder indicates the following:

“The firmware is more than one file (CLR, CLR2, Config). All of them MUST be selected at same time and deployed using MFDeploy.”

I ran MFDeploy and held down the three Cobra buttons UP, DOWN and SELECT and then plugged in the USB cable. Serial port COM5 appeared in the list of serial ports in MFDeploy. I assumed this is the virtual com port for the Cobra since my computer only has COM1.

I browsed to the EMX firmware directory and selected the three hex files for the image files and clicked on the Deploy button. After a few seconds an error was displayed as follows:

“Error: No response from the device”

I don’t know what to do next???

Regards,
Synapsys

[quote]I ran MFDeploy and held down the three Cobra buttons UP, DOWN and SELECT and then plugged in the USB cable. Serial port COM5 appeared in the list of serial ports in MFDeploy. I assumed this is the virtual com port for the Cobra since my computer only has COM1.

I browsed to the EMX firmware directory and selected the three hex files for the image files and clicked on the Deploy button. After a few seconds an error was displayed as follows:[/quote]

You are mixing steps… see this - YouTube

Hi Gus,

Thanks for the link, that video is exactly what I needed :slight_smile:

However, there was still a problem that prevented me from following the steps in the video. When I was trying to get the CDC working with the debugger I had to install the driver CDC with Debugging to support that. In order to properly reinstall that firmware I had to manually uninstall those drivers first.

Once the drivers were uninstalled I was able to follow the video and reload the firmware. Now everything is back to normal except of course I still don’t have CDC with debugging working.

Thanks for your superb support today ;D

Regards,
Synapsys

You can always recover FEZ so go ahead and keep trying…you will get it to work I am sure :slight_smile:

;DHi Gus,

I was finally able to get the CDC with Debugging to work ;D

The problem I was having was related to the USB drivers. When the example code deployed for the first time the USB driver for the EMX was, of course, the original USB driver for debugging without CDC. Once the application was deployed it was necessary to manually update the USB driver for EMX using Device Manager to use the CDC with Debugging driver.

Now I can debug the CDC application just fine :slight_smile:

You may want to update the ebook to indicate that this step may be necessary.

Regards,
Synapsys

It is not actually needed to be done manually. I am not sure why it was manual in your case but I am glad it worked finally.