1.5M ratings
277k ratings

See, that’s what the app is perfect for.

Sounds perfect Wahhhh, I don’t wanna

Remote AVR ISP

Background

In my home office I have electronics work bench on one side of the room at my desk (and workstation) on the other. Once projects have progressed far enough I want to be able to keep my projects on my workbench to use power supply or scope.

Also on my workbench I have my tiny Asus EEEPC. While not great for development it does make a great remote environment. I tend to work primarily from comand line with the standard unix automation tools (vim, make etc).

So how to go about doing development on my workstation and deploying changes onto my remote machine.

A quick summary of my setup:

  • Ubuntu GNU/Linux 16.04 on my primary workstation
  • Ubuntu GNU/Linux 15.04 on the EEE PC
  • USBTiny ISP
  • Bus Pirate
All connected to my local LAN.

Previously I had used ser2net to remotely access an Arduino, however the USBTiny does not expose a TTY interface so another solution was required.

Enter usbip

USBip is a linux kernel module that allows USB devices to be exported over an IP network and bound to another machine.

Setup

Note: All the samples are for Ubuntu GNU/Linux (or Debian).

Server/Host

Install the USBIP kernel module and tools (ensure you do not have the usbip package installed, this is out of date)

# Optional but needs to be removed
$ sudo apt remove usbip
$ sudo apt install linux-tools-generic

# Ensure the kernel module is inserted
$ sudo modprobe usbip_host

# Ensure module is installed automatically post reboot
$ sudo -i
$ echo 'usbip_host' >> /etc/modules

Next step is to identify and export the USB devices, plug in the USBTiny:

# List local devices
$ usbip list -l

# Take not of the busid of the device to export.
# If usbip doesn't provide enough info try lsusb.
# Bind the device (in this case the busid is 2-2)
$ usbip bind -b 2-2

# Start export daemon $ usbipd -d

Client

Similar to the server install the USBIP kernel module and tools.

# Optional but needs to be removed
$ sudo apt remove usbip
$ sudo apt install linux-tools-generic

# Ensure the kernel module is inserted
$ sudo modprobe vhci-hcd

# Ensure module is installed automatically post reboot
$ sudo -i
$ echo 'vhci-hcd' >> /etc/modules

First a quick test to ensure that the exported USB device is visible:

# List remote devices
$ sudo usbip list -r $REMOTE_HOST

# And finally attach to the exported device (again 2-2)
$ usbip attach -r $REMOTE_HOST -b 2-2

Finally confirm everything is working:

# Check for the new device with lsusb
$ sudo lsusb

# And finally check that avrdude can find the device
$ avrdude -c usbtiny -p $MCU_NAME

Done!

/update

UDEV Rules

It sounds complex but it’s really quite a simple system, so straight up here are the two rules I’ve added to handle both my Bus Pirate and USBTiny ISP. In the file /etc/udev/rules.d/91-export-usbip.rules:

# Auto bind the Bus Pirate (well any product that includes an FTDI interface).
SUBSYSTEM=="usb" ATTRS{idVendor}=="0403" ATTRS{idProduct}=="6001" RUN+="/usr/bin/usbip bind -b $kernel"

# Auto bind a USBTiny ISP
SUBSYSTEM=="usb" ATTRS{idVendor}=="1781" ATTRS{idProduct}=="0c9f" RUN+="/usr/bin/usbip bind -b $kernel"

Basically this matches on the USB vender and product IDs and automatically executes the usbip bind operation. The variable $kernel provides the reference needed by usbip bind.

To obtain the idVender and idProduct codes use lsusb. In the default listing the two colon seperated values after ID are idVender and idProduct eg:

Bus 009 Device 013: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC

And thats it devices show up on my other machine and that’s one less task I need to perform :)

Happy hacking!

atmel avr avrdude usbtiny linux ubuntu

Ubuntu 14.04 with AVRDude and a USBTiny

Works well straight out of the box but requires the use of sudo. Thankfully this is easy to fix as root (usesudo -i) execute the following:

echo "SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"1781\", ATTRS{idProduct}==\"0c9f\", GROUP=\"adm\", MODE=\"0664\"" >> /etc/udev/rules.d/72-embedded-dev.rules
service udev restart

This gives all users read access and users in the adm (eg anybody who can use sudo) r/w access. If you don’t care about using a group just set the mode to 0666 to give all users r/w access.

avr embedded avrdude