Repository navigation
examples: USB/IP server for the USB device model - #608
Open
teknoman117 wants to merge 5 commits into
Open
teknoman117 wants to merge 5 commits into
teknoman117 wants to merge 5 commits into
Conversation
The usb-vhci kernel module and libusb_vhci are unmaintained and the module does not build on current kernels. The mainline vhci-hcd USB/IP client replaces them. The examples Makefile now uses filter-out for the board list.
- A control write data stage NAKs until the firmware reads the SETUP. - A bulk IN read with no data NAKs instead of returning zero bytes. The zero byte reply was a workaround for the removed vhci bridge. - avr_reset() zeroes the cycle count before the peripheral reset callbacks. Timers they start were due late otherwise.
usbip_usb.c exports the simulated USB device over USB/IP 1.1.1 on TCP port 3240. Linux vhci-hcd and usbip-win2 can attach it. - Runs from a 100us cycle timer in the simulation thread. - Enumerates the device on attach to list it and learn its endpoint sizes. - Several clients can list the device. One can import it. - EP0 gets one transaction per tick. Bulk pipes get up to 16 packets. - Waits 10ms after a bus reset. - Restarts its timer after an AVR reset. avr_terminate() frees it. - Builds with POSIX sockets and Winsock. Uses SO_NOSIGPIPE on macOS. - Sockets are non-blocking. A full send buffer waits in select(). - Protocol messages are structs converted with htonl() and ntohl(). - Listens on 127.0.0.1 by default.
An Arduino Leonardo over USB/IP: an ATmega32U4 at 16MHz running Caterina with the Leonardo BOOTRST and BOOTSZ bits. - The flash and EEPROM persist between runs in an Intel HEX file. - -r starts as after the reset button. Ctrl-\ presses it. - A sketch can be given as .hex or .elf. Caterina-Leonardo-bootloader.hex is the ArduinoCore-avr image with the demonstration sketch below 0x7000 removed. LICENSE has its origin and the LUFA notice. The .hex is force-added past the *.hex ignore rule.
The Arduino Uno R3 USB to serial adapter over USB/IP: an ATmega16U2 running Arduino-usbserial. - USART1 is looped back or connected to a pty with -t. - Changes of the 328P RESET line are printed. - Other firmware can be given as .hex or .elf. usbip_check.py drives the server like vhci-hcd and cdc-acm without a kernel. Arduino-usbserial-atmega16u2-Uno-Rev3.hex is the unchanged ArduinoCore-avr image. LICENSE has its origin and the LUFA notice. The .hex is force-added past the *.hex ignore rule.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This supersedes #247. Closes #286: the out of tree usb-vhci kernel modules that issue is about are removed. vhci-hcd is in the mainline kernel (drivers/usb/usbip) and replaces them.
It exports the simulated USB device over USB/IP so that a real USB stack can use it. The host's own tools then talk to the firmware as to a board plugged in. Avrdude can upload through Caterina (The bootloader for Arduino Leonardo and Micro) and CDC sketches show up as /dev/ttyACMn.
USB/IP carries USB requests over TCP. A client lists the devices a server exports and imports one. The client's virtual host controller then sends each transfer as a request and gets the reply on the same connection. On Linux the client is the mainline vhci-hcd driver with the usbip tool. On Windows it is usbip-win2. The protocol and how the part maps it onto
avr_usb.care described at the top ofusbip_usb.c.Commits:
avr_reset()zeroes the cycle count before the peripheral reset callbacks so the timers they start are due on time.usbip_usb.c. It runs from a 100us cycle timer in the simulation thread so nothing calls into the model from another thread. It enumerates the device when the firmware attaches. Several clients can list the device and one can import it. Packets the firmware NAKs are tried again on the next tick. It builds with POSIX sockets and Winsock.usbip_check.pydrives the server the way vhci-hcd and cdc-acm do without needing a kernel.The two .hex images are the ArduinoCore-avr ones. The Caterina image has its demonstration sketch removed. Each board's LICENSE gives the origin and the LUFA notice.
Testing:
usbip_check.pyagainst board_usbserial: it checks the listing while the device is imported and that a second import is refused. It also checks loopback data and unlinks.Limitations: