USB-Controlled Relays

At Summit Embedded, a core part of working efficiently is to enable our employees to work from anywhere. Embedded devices aren’t very portable. Unsealed development boards with DuPont wires are hard to set up on an airplane tray table. We typically connect our devices to a PC that can be accessed remotely. VSCode, STM32CubeIDE, and others can be configured for remote debugging. A future blog post will explain setting that up.

We’ve found that remote embedded devices need to be physically power cycled from time to time. Especially early on in development when the software is not stable. For this, we connect USB-Controlled Relays in-line with the power supply to each device. We leverage an open-source HID driver called usbrelay. Search any online electronics marketplace for “usb relay” and you’ll see options for less than $10 each.

We ran into two notable issues when initially testing the usbrelay driver:

1) usbrelay is in Ubuntu’s apt repository, but it’s an older v1.0.2 that doesn’t support USB device ID 5131:2007. The devices we ordered just so happened to use device ID 5131:2007. Time to compile the latest from source! This was a straightforward build with make. But only straightforward if you install on the build machine, which brings us to our next tweak:

2) We install this usbrelay tool on different machines connected to different embedded devices. The usbrelay code leverages a libusbrelay.so library file, so that library must also be installed for the usbrelay command to work. It’s pretty simple to install two files on a remote server. But installing one file would be even easier! We tweaked this line in the Makefile as follows:

usbrelay: usbrelay.c libusbrelay.h libusbrelay.so

$(CC) $(CPPFLAGS) $(CFLAGS) $< -l:libusbrelay.so.$(USBLIBVER) -L./ $(LDFLAGS) -o $@ $(LDLIBS)

to

usbrelay: usbrelay.c libusbrelay.h libusbrelay.c

$(CC) $(CPPFLAGS) $(CFLAGS) usbrelay.c libusbrelay.c $(LDFLAGS) -o $@ $(LDLIBS)

This creates a statically-linked executable. Now just a single usbrelay file can be transferred to other x86 servers to install the application. It does make the file a bit larger, but it’s only 27kB. Pretty lightweight for an x86 server.

Previous
Previous

Demystifying Trusted Platform Modules, Part 1