Virtual Machine, Emulate a USB through networked USB hub - virtual-machine

I am trying to automate the below process:
Operator executes operation on field device and generates local data that is stored on the field device. (NOT a PC)
Operator inserts USB into field device and executes a local export function.
Operator takes USB to network machine and transfer files to secure file location.
The USB connection is the ONLY method of data transfer.
I would like to have a direct USB to USB connection, which I believe can be done if you can trick the field device into thinking a USB connection to the network machine (over VLAN/IP USB Hub/some sort of networked hardware) is a flash drive. The field device is commercial off the shelf so it cannot be modified, which drives the need for an emulated flash drive. The new process would look like:
Operator executes operation on field device and generates local data that is stored on the field device.
Operator executes a local export function.
File is transferred over USB connection to emulated flash drive on virtual network machine.
So in summary, the question is how do I configure a virtual machine to have an emulated flash drive that can be hooked into a physical USB port?

Related

Simulating USB port

I have a software that reads serial data (in coming bytes for sensor reading) from USB port. For simulation purpose I need to write a python script that continuous writes bytes to the USB port simulating a USB device. I require that the /dev/serial/by_id to be created as the software reads the data from that file itself. I cannot edit the software. How can I make this work. I read through the pyserial documentation but I could not figure it out
Requirements:
the serial port is accessible at /dev/serial/file
it is listed by serial.tools.list_ports.

Transferring data from STM32F407 to libusb through USB CDC class

I'm working on the project in which I should transfer data from a microcontroller to a PC with the USB protocol. I am working with the STM32F407 microcontroller for transferring data to a PC with the USB Protocol.
I am using libsub for transferring data in Windows 7.
I have written a program with STM32cubeMX and configured the USB device class library. I can transfer data with the CDC virtual COM port, but I want to transfer data with libusb. I install the libusb driver for my device, but when I send data from the microcontroller to PC nothing is send!!!!
What is my problem? How can I send data from a USB device to a PC with USB and high speed?
Enter image description here
In USB protocol the host device initiates any transfer, for example a bulk transfer. i assume that the ST32f407 is the device and the pc ist the host so the ST32 can not initiate any USB transfer. The communication over virtual COM works because it the virtual COM is like a tunnel, but this tunnel was also initated and is (logically) kept alive by the host (pc)
Bulk transactions
Like all other USB transfers, the host always initiates a bulk
transfer. The communication takes place between the host and the
target endpoint. The USB protocol does not enforce any format on the
data sent in a bulk transaction.
source: https://msdn.microsoft.com/de-de/library/windows/hardware/ff539199%28v=vs.85%29.aspx
All data transfers are initiated and controlled by the host and USB
peripherals are slaves responding to host commands
source: https://www.midi.org/articles/basic-of-usb
in usb even interrupts have to wait until the host polls:
Any one who has had experience of interrupt requests on
microcontrollers will know that interrupts are device generated.
However under USB if a device requires the attention of the host, it must wait until the host polls it before it can report that it needs
urgent attention!
source: http://www.beyondlogic.org/usbnutshell/usb4.shtml#Interrupt
See http://www.beyondlogic.org/usbnutshell/usb4.shtml#Bulk for bulk transfers
So you can send data from the device to the host but the host has to establish the communication meaning has 'ask' for the data. This is done via the bulk IN endpoint that is used to read data from the device to the host

How can I program ST MCUs from USB disk without PC?

I want to program (such as STM32F407 cortex M4 MCU) without PC, by using only MCU board, USB disk and USB cable. Binary(.HEX) file should be stored in USB disk. then bootloader which preloaded in MCU, should load binary file from usb to the program memory.
Is it possible to do it, as I describe above?
Yes it is entirely possible given a suitable boot loader. I have implemented a boot loader on STM32 that accepts updates over serial, SD card or USB VCP; adding USB mass storage support would be a relatively simple extension.
Your boot loader will require USB mass storage device support, for which the USB controller must support operation as a USB host, and you will require a file system (could be read-only to reduce size). You will also need to support flash programming.

UART over USB for STM32 Micro-controller

I'm trying to implement UART over a USB interface on the STM324x9I-EVAL development board. The purpose is to send commands to a servo controller (or other hardware, for that matter) serially. I've successfully implemented the USB_Device_CDC example on the development board but am unsure exactly how this works without a PC with drivers on the other end. As far as other hardware is concerned, will the USB port now simply look like a serial port? Or is there still a need for a driver or some sort of interface on the other end?
I do want to point out that I'm aware of the following post:
Emulating UART over USB
but I don't believe my question is fully answered within the context of that answer.
A USB connection is not a peer-to-peer connection like a UART. It requires a host and a device in a master/slave relationship. The device cannot initiate data transfer; it must be continuously polled by the by the host.
A CDC/ACM class device presents a virtual COM port on a PC host, but that does not allow the device to communicate with a UART interface. It looks like a serial port at the software level, but does not implement a UART physical layer. There is an awful lot going on under the hood to make it look like a PC serial port, but none of it resembles UART communications at the physical level.
There are devices that act as UART/USB bridges (from FTDI and Prolific for example), and you could (somewhat expensively) build your own from a microcontroller that has a USB device controller and a UART, but the bridge is a USB device and must still connect to a USB host; these are normally used to connect a PC to a microcontroller that lacks a USB controller or where the software/CPU overhead of using a USB controller is too great.
In theory you could connect a microcontroller that has a USB host controller to one that has a USB device controller, but you need host and device software stacks on each respectively, and once you have the USB connection, implementing CDC/ACM is a somewhat inefficient use of the available bandwidth. The purpose of the CDC/ACM class is primarily to allow "legacy" software to work on a PC.
If you need to connect to a "real" serial port, you should use a real UART - which are far more ubiquitous than USB controllers on microcontrollers in any case.
You should learn a little bit about USB device classes. CDC is a USB device class, and ACM is a subclass that I assume you are using. The device you made could be called a "CDC ACM device" because it uses the CDC class and the ACM subclass.
These classes and subclasses are defined by the USB Implementers Forum in documents that you can find here:
http://www.usb.org/developers/docs/devclass_docs/
These documents specify things like what USB descriptors a CDC ACM device should have in order to describe itself to the host, and what kinds of interfaces and endpoints it should have, and how serial data will be represented in terms of USB transactions and transfers.
Note that CDC ACM only specifies some USB commands for transferring data between the host and the device. It does not specify what the device will actually do with that data. You can use CDC ACM to implement a USB-to-serial adapter, or you can just use it as a general purpose communication interface for whatever data you want to send.
Yes, you do need a driver on the PC side. The driver needs to be designed to run on your specific operating system. It needs to create some kind of virtual serial port device in your operating system that other software (which only knows about serial ports) can find and connect to. It needs to translate serial port operations performed by other software on the serial port (e.g. writing some bytes to the serial port) into low-level USB commands according to the CDC ACM specifications (e.g. sending some bytes out to the device on a particular endpoint in the form of USB packets). It needs to somehow know which USB devices it should operate on, since not every USB device is a CDC ACM device.
For Windows, you will probably use the usbser.sys driver which comes with Windows. For versions of Windows older than Windows 10, you will need to write an INF file to associate your device to usbser.sys and sign it. For Windows 10 and later, there is a new INF file called usbser.inf already included with Windows which will automatically match any valid CDC ACM device. This means you don't have to write or distribute a driver for CDC ACM devices if you only intend to support using the device on Windows 10 or later. The partnership between Microsoft and Arduino which began in 2015 gives me hope that Microsoft will continue supporting and improving usbser.sys in the future. In fact, they claim that in Windows 10 "the driver has been rewritten by using the Kernel-Mode Driver Framework that improves the overall stability of the driver", so that is good news.
For Linux, there is the cdc_acm kernel module, which has been a standard part of the kernel for a long time and should work automatically with any CDC ACM device you plug in.
For Mac OS X, there is the AppleUSBCDCACM driver, which should work automatically with any CDC ACM device you plug in.
Note that for any of these drivers to recognize your device and work with it, your device has to have certain values in its USB descriptors, and the requirements can vary depending on what exact driver version you are talking about.
Will the USB port now simply look like a serial port?
No, that's the wrong way to think about it. The USB port will still look like a USB port, but the various USB drivers provided by your operating system will recognize that a CDC ACM device is plugged into that port and create a new entry in your operating system's list of serial ports. Then if you run some software that only knows about serial ports, it can connect to that port.
In fact, if you make a composite device, you can have a single USB device plugged into a single USB port that actually has two or more virtual serial ports.

Can I duplicate the behavior of one tty on another tty device

I am currently developing an application that connects to a device via USB but due to project modifications I have to move it to a target device whose only serial communication is via RS-232 DE-9 port.
To communicate with the device I use a proprietary API. Using strace I know that it scans all devices in /dev/bus/usb and after finding the right one the API connects to it.
I wanted to know if I could some how emulate my device in /dev/ttyS0 to an unused usb device in /dev/bus/usb/ to connect to it