auto flash teensy

This commit is contained in:
Chris Frankland-Wright 2025-07-07 19:26:59 +01:00 committed by GitHub
parent 28e7d1e644
commit 2819f111cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,14 +21,12 @@ sudo apt update && sudo apt upgrade -y
# --------------------------------------------------------- # ---------------------------------------------------------
echo "Step 2: Installing required tools..." echo "Step 2: Installing required tools..."
sudo apt install -y git curl python3 python3-pip build-essential cmake \ sudo apt install -y git curl python3 python3-pip build-essential cmake \
python3-serial python3-serial libusb-dev
# --------------------------------------------------------- # ---------------------------------------------------------
# Step 2.5: Install teensy-loader-cli from source # Step 2.5: Install teensy-loader-cli from source
# --------------------------------------------------------- # ---------------------------------------------------------
echo "Installing teensy-loader-cli manually from source..." echo "Installing teensy-loader-cli manually from source..."
sudo apt install -y libusb-dev
cd "$HOME" cd "$HOME"
if [ ! -d teensy_loader_cli ]; then if [ ! -d teensy_loader_cli ]; then
git clone https://github.com/PaulStoffregen/teensy_loader_cli.git git clone https://github.com/PaulStoffregen/teensy_loader_cli.git
@ -40,6 +38,17 @@ sudo cp teensy_loader_cli /usr/local/bin/teensy-loader-cli
echo "Verifying teensy-loader-cli..." echo "Verifying teensy-loader-cli..."
teensy-loader-cli --version || echo "⚠️ teensy-loader-cli failed to install properly" teensy-loader-cli --version || echo "⚠️ teensy-loader-cli failed to install properly"
# ---------------------------------------------------------
# Step 2.6: Install udev rules for Teensy
# ---------------------------------------------------------
echo "Installing udev rules for Teensy access..."
cd "$HOME"
wget -O 49-teensy.rules https://www.pjrc.com/teensy/49-teensy.rules
sudo cp 49-teensy.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules
sudo udevadm trigger
echo "✅ Teensy udev rules installed. Reboot required to take effect."
# --------------------------------------------------------- # ---------------------------------------------------------
# Step 3: Install Arduino CLI manually (latest version) # Step 3: Install Arduino CLI manually (latest version)
# --------------------------------------------------------- # ---------------------------------------------------------
@ -69,28 +78,64 @@ else
fi fi
# --------------------------------------------------------- # ---------------------------------------------------------
# Step 5: Download Teensy firmware and flash if available # Step 5: Download Teensy firmware
# --------------------------------------------------------- # ---------------------------------------------------------
echo "Step 5: Downloading Teensy firmware..." echo "Step 5: Downloading Teensy firmware..."
cd "$HOME" cd "$HOME"
wget -O ltc_audiohat_lock.ino.hex https://raw.githubusercontent.com/cjfranko/NTP-Timeturner/master/firmware/ltc_audiohat_lock.ino.hex wget -O ltc_audiohat_lock.ino.hex https://raw.githubusercontent.com/cjfranko/NTP-Timeturner/master/firmware/ltc_audiohat_lock.ino.hex
echo "Checking for connected Teensy 4.0..." # ---------------------------------------------------------
# Step 6: Create flash script and one-time service
# ---------------------------------------------------------
echo "Step 6: Creating one-time flash script and service..."
cat << 'EOF' > "$HOME/flash_teensy_once.sh"
#!/bin/bash
echo "🔧 Running one-time Teensy flash..."
if ls /dev/ttyACM* 1> /dev/null 2>&1; then if ls /dev/ttyACM* 1> /dev/null 2>&1; then
echo "✅ Teensy detected. Flashing firmware..." echo "✅ Teensy detected. Flashing firmware..."
teensy-loader-cli --mcu=TEENSY40 -w -v ltc_audiohat_lock.ino.hex /usr/local/bin/teensy-loader-cli --mcu=TEENSY40 -w -v "$HOME/ltc_audiohat_lock.ino.hex"
echo "✅ Firmware uploaded successfully." echo "✅ Firmware upload complete."
else else
echo "⚠️ No Teensy detected on /dev/ttyACM* — firmware not flashed." echo "⚠️ No Teensy detected on /dev/ttyACM* — skipping flash."
fi fi
# Clean up: remove script and disable this service
rm -- "$HOME/flash_teensy_once.sh"
systemctl --user disable flash-teensy.service
rm -- "$HOME/.config/systemd/user/flash-teensy.service"
EOF
chmod +x "$HOME/flash_teensy_once.sh"
mkdir -p "$HOME/.config/systemd/user"
cat << EOF > "$HOME/.config/systemd/user/flash-teensy.service"
[Unit]
Description=One-time Teensy Flash
After=default.target
[Service]
Type=oneshot
ExecStart=$HOME/flash_teensy_once.sh
RemainAfterExit=true
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reexec
systemctl --user daemon-reload
systemctl --user enable flash-teensy.service
echo "✅ One-time flash service scheduled to run after reboot."
# --------------------------------------------------------- # ---------------------------------------------------------
# Final Message # Final Message & Auto-Reboot
# --------------------------------------------------------- # ---------------------------------------------------------
echo "" echo ""
echo "─────────────────────────────────────────────" echo "─────────────────────────────────────────────"
echo " Setup Complete — Time magic is in place." echo " Setup Complete — Rebooting in 15 seconds..."
echo "─────────────────────────────────────────────" echo "─────────────────────────────────────────────"
echo "Teensy tools are installed, firmware is ready." echo "Teensy will be flashed automatically on next boot (once)."
echo "Your Raspberry Pi is now ready for testing."
echo "" echo ""
sleep 15
sudo reboot