[{"element_type":"markdown","content":"\u003cp\u003eI've been working on hardware-in-the-loop testing for use in continuous integration testing, coding agent loops and validating coding agent output. There are a number of pieces to this puzzle.\u003c/p\u003e\n\n\u003ch2\u003e\u003ca href=\"https://github.com/adafruit/esp-usbip-bridge\"\u003eesp-usbip-bridge\u003c/a\u003e\u003c/h2\u003e\n\n\u003cp\u003eThis ESP-IDF firmware runs on an ESP chip and bridges the usb host port to a TCP usbip server. This allows the USB devices connected to the ESP to be controlled remotely. They can be attached to the Linux kernel with the \u003ccode class=\"inline\"\u003eusbip\u003c/code\u003e command OR they can be used directly (see below).\u003c/p\u003e\n\n\u003cp\u003eThis firmware also starts an MDNS server so they can be discovered on the network.  The firmware advertises a \u003ccode class=\"inline\"\u003e_usbip._tcp\u003c/code\u003e mDNS/DNS-SD service on port \u003ccode class=\"inline\"\u003e3240\u003c/code\u003e with hostname \u003ccode class=\"inline\"\u003eusbip-XXYYZZ.local\u003c/code\u003e.\u003c/p\u003e\n\n\u003cp\u003eLastly, this firmware can integrate other ESP-IDF components via a virtual CDC link. Virtual devices appear as a subsequent USB bus with a single virtual device. Currently only CDC is supported and translates to internal input and output FIFOs the component can use. The first example use is with the logic analyzer firmware.\u003c/p\u003e\n\n\u003ch2\u003e\u003ca href=\"https://github.com/adafruit/esp-perfetto-logic\"\u003eesp-perfetto-logic\u003c/a\u003e\u003c/h2\u003e\n\n\u003cp\u003eThis is an ESP component with standalone examples that uses the PARLIO peripheral on the ESP32-P4 (and others untested) to capture signals up to 16 bits at 80 mhz. It uses an extended SUMP protocol for configuration. It also returns perfetto encoded trace data for visualization and analysis. It doesn't currently stream data. It simply writes it into PSRAM.\u003c/p\u003e\n\n\u003cp\u003eThis code can be run standalone on a P4 with the USB example or as a virtual device from within the USBIP bridge.\u003c/p\u003e\n\n\u003ch3\u003e\u003ca href=\"https://github.com/tannewt/viewtrace.dev\"\u003eviewtrace.dev\u003c/a\u003e\u003c/h3\u003e\n\n\u003cp\u003eThis is the UI for the logic analyzer. It is based on the \u003ca href=\"https://ui.perfetto.dev/\"\u003ePerfetto UI\u003c/a\u003e originally designed for debugging Chrome and Android runtimes.\u003c/p\u003e\n\n\u003cp\u003eIt has been modified to support capturing from a serial connecting logic analyzer using the above firmware. It also has basic protocol decoding.\u003c/p\u003e\n","metadata":{"markdown":"I've been working on hardware-in-the-loop testing for use in continuous integration testing, coding agent loops and validating coding agent output. There are a number of pieces to this puzzle.\n\n## [esp-usbip-bridge](https://github.com/adafruit/esp-usbip-bridge)\n\nThis ESP-IDF firmware runs on an ESP chip and bridges the usb host port to a TCP usbip server. This allows the USB devices connected to the ESP to be controlled remotely. They can be attached to the Linux kernel with the `usbip` command OR they can be used directly (see below).\n\nThis firmware also starts an MDNS server so they can be discovered on the network.  The firmware advertises a `_usbip._tcp` mDNS/DNS-SD service on port `3240` with hostname `usbip-XXYYZZ.local`.\n\nLastly, this firmware can integrate other ESP-IDF components via a virtual CDC link. Virtual devices appear as a subsequent USB bus with a single virtual device. Currently only CDC is supported and translates to internal input and output FIFOs the component can use. The first example use is with the logic analyzer firmware.\n\n## [esp-perfetto-logic](https://github.com/adafruit/esp-perfetto-logic)\nThis is an ESP component with standalone examples that uses the PARLIO peripheral on the ESP32-P4 (and others untested) to capture signals up to 16 bits at 80 mhz. It uses an extended SUMP protocol for configuration. It also returns perfetto encoded trace data for visualization and analysis. It doesn't currently stream data. It simply writes it into PSRAM.\n\nThis code can be run standalone on a P4 with the USB example or as a virtual device from within the USBIP bridge.\n\n### [viewtrace.dev](https://github.com/tannewt/viewtrace.dev)\nThis is the UI for the logic analyzer. It is based on the [Perfetto UI](https://ui.perfetto.dev/) originally designed for debugging Chrome and Android runtimes.\n\nIt has been modified to support capturing from a serial connecting logic analyzer using the above firmware. It also has basic protocol decoding."}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/002/309/original/image_%281%29.png?1776289684","metadata":{}},{"element_type":"markdown","content":"\u003ch1\u003eDirect communication\u003c/h1\u003e\n\n\u003cp\u003eThere are two layers to communicating from Python to the USB devices hosted by the bridge.\u003c/p\u003e\n\n\u003ch2\u003e\u003ca href=\"https://github.com/adafruit/pyusb-usbip-backend\"\u003epyusb-usbip-backend\u003c/a\u003e\u003c/h2\u003e\n\n\u003cp\u003eThis Python library provides a backend to PyUSB that translates backend calls into the USB over IP protocol. Higher level libraries can then be written targeting the PyUSB API, which is what CircuitPython's USB host API is too.\u003c/p\u003e\n\n\u003ch2\u003e\u003ca href=\"https://github.com/adafruit/pyserial-pyusb\"\u003epyserial-pyusb\u003c/a\u003e\u003c/h2\u003e\n\n\u003cp\u003eThis library implements the serial protocol portion of USB on top of PyUSB and connects it into PySerial. It is essentially drivers for standard CDC and CP210x. PySerial has a backend system but it requires the backend to be registered in the same python instance. Not quite like pluggy for USB where installation is enough.\u003c/p\u003e\n\n\u003cp\u003eThis works with idf.py by modifying it to \u003ccode class=\"inline\"\u003eimport serial_pyusb\u003c/code\u003e which does the registration.\u003c/p\u003e\n","metadata":{"markdown":"# Direct communication\n\nThere are two layers to communicating from Python to the USB devices hosted by the bridge.\n\n## [pyusb-usbip-backend](https://github.com/adafruit/pyusb-usbip-backend)\n\nThis Python library provides a backend to PyUSB that translates backend calls into the USB over IP protocol. Higher level libraries can then be written targeting the PyUSB API, which is what CircuitPython's USB host API is too.\n\n## [pyserial-pyusb](https://github.com/adafruit/pyserial-pyusb)\nThis library implements the serial protocol portion of USB on top of PyUSB and connects it into PySerial. It is essentially drivers for standard CDC and CP210x. PySerial has a backend system but it requires the backend to be registered in the same python instance. Not quite like pluggy for USB where installation is enough.\n\nThis works with idf.py by modifying it to `import serial_pyusb` which does the registration."}}]