WARNING
I have migrated to the Raspi 5 series, and thus no longer use a DeskPi
Pro enclosure. The code is likely to continue to work, but this project
should be considered "maintenance-only".
Description
As part of the on-going futile search for an ARM development target that
doesn't suck, I ended up using a Raspi 4 (8 GiB) in a DeskPi Pro
enclosure. While the way the SATA support is connected is kind of
jank (a loopback USB connector on the back), at least it is a sort-of
ok AArch64 development target that has an actual m.2 SATA SSD, that
even supports TRIM.
Naturally I would love something better, but that would cost
money.
The DeskPi creators did release the source code to the scripts that
allow you to control the fan and to "safely" power the unit off, but
I feel compelled to rewrite the tooling.
The actual control scheme is dead trivial. There is a "QinHeng
Electronics CH340 serial converter" (1a86:7523), that comes up as
/dev/ttyUSB0, that appears to be connected to the fan and power
control. Writing various plain text commands (eg: even just with
echo), does useful things.
pwm_000 ... pwm_100: Set fan speed by percent, needs to be 3 digits.
power_off: Turn off the unit "safely".
Installation
This requires the Go toolchain. Either grab it from the official
site or from your distribution's package manager.
The installation SHOULD be done after /boot/config.txt (this may be
/boot/firmware/config.txt on some systems) has been manually edited
to apply the changes in config/boot/config.txt.
git clone https://github.com/Yawning/deskpi-ctl.git
cd deskpi-ctl
go build
sudo cp deskpi-ctl /usr/local/bin/
sudo cp config/udev/20-usb-serial.rules /etc/udev/rules.d/20-deskpi-usb-serial.rules
sudo cp config/systemd/deskpi-cut-off-power.service /usr/lib/systemd/system/deskpi-cutoff-power.service
sudo cp config/systemd/deskpi-fan-daemon.service /usr/lib/systemd/system/deskpi-fan-daemon.service
# Optional: Enable TRIM support on the SSD. This requires the firmware
# on the USB->SATA bridge to be sufficiently recent.
#
# See: https://github.com/DeskPi-Team/deskpi/blob/master/DeskPi_v3_firmware_upgrade_manual.md
sudo cp config/udev/50-usb-ssd-trim.rules /etc/udev/rules.d/50-deskpi-usb-ssd-trim.rules
sudo udevadm control --reload
sudo systemctl start deskpi-fan-daemon.service
sudo systemctl enable deskpi-fan-daemon.service
sudo systemctl enable deskpi-cutoff-power.service
Annoyances
- The fan probably just uses low-frequency PWM, and the only duty
cycles that don't make a lot of really annoying noises are 0% and
100%. I also did not bother checking the extension board to see
if there is a flyback diode present.
- The vendor provided C code's serial port initialization is "odd".
Thankfully, 9600 8-N-1 "just works".
- Recent Ubuntu (that I don't use, because Debian/Ubuntu is banned on
my hardware), has a Braille tty package that claims ownership of
the USB serial device that controls the fan and power. Remove
brltty to get things to work.
Acknowledgements
Thanks to @ahrbe1 for improvements and the installation instructions
that I was too lazy to write.