Jul 4, 2014 0 Comments in Learning, USB by
Playing with USB devices

Having a USB device port on an embedded system is quite useful due the fact that a common port can be used for several different connection types. You can use it to simulate a normal serial line or to implement a mass storage device in order to exchange organized data in a file-system structure or just an ethernet connection!

In the industrial environment USB ports are largely used most to emulate serial and/or ethernet ports that’s why Cosino Project’s based boards have at least a USB device port.

warning You need a Cosino based board with a USB device port (type B or microB). If the USB port is not mounted on your board you may use an USB device port adapter.

The serial gadget

In order to use the serial gadget you have to load the g_serial module as follow:

then connect the USB cable to an host port and, on your Cosino board you should get the kernel message:

while on the host (we consider the host is a GNU/Linux machine) you will see the following kernel messages:

Now on your Cosino board you should have a new device called /dev/ttyGS0 while on the host side you’ll have a device called /dev/ttyACM0 (see the above messages). That’s all! By using these new two devices you can now communicate as far as a serial port does. For instance on your Cosino board do the command:

in this manner, on the host side, you can send strings to the Cosino board by using:

Here the result:

The ether gadget

If you need an ethernet connection through your USB cable the g_ether module is for you! Just load it:

warning Note: the dev_addr parameter is needed only if you need a well defined MAC address for your ethernet device.

Now connect the USB cable on an host machine and you should see on the kernel messages:

Now, depending on your host system, you should configure the new usb0 device. On my Ubuntu I managed the network manager in order to get a manual configuration of my usb0 device as follow:

Now on the Cosino board I use the command:

in order to have an IP adress in the same subnet of my host computer. That’s all! I can do a login via SSH on the Cosino board just using:

The mass_storage gadget

This is one of the most nice gadget I have never used, since it simulate perfectly a common mass storage device (aka an USB key).

To use it you can create a fake image file or just using a block device. I’m going to use a file for simplicity:

then load the gadget g_mass_storage by using the command:

Now connect your Cosino board to an USB host and you should get:

Great! We now have a new disk on device /dev/sdb. Let’s start partitioning it:

and then we should format it:

Now the host system should recognize the new USB key and auto-magically mount it!

Facebooktwitterlinkedin
Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

83 − = 75