Skip to content

Instantly share code, notes, and snippets.

@nmk456
Last active February 3, 2022 20:04
Show Gist options
  • Save nmk456/5a231aa5d55a15623409e29ca02ab618 to your computer and use it in GitHub Desktop.
Save nmk456/5a231aa5d55a15623409e29ca02ab618 to your computer and use it in GitHub Desktop.
Bash script for WSL to put Raspberry Pi Pico into BOOTSEL mode and copy .uf2 file over automatically
#!/usr/bin/bash
if [[ $1 == "-h" ]] || [[ $# -eq 0 ]]; then
echo "Usage: flash_pico file.uf2 port drive";
exit;
fi
# Serial command to trigger BOOTSEL mode
serialcmd="\$port= new-Object System.IO.Ports.SerialPort $2,1200,None,8,one
try {\$port.open()} catch {}"
# Only get first char
letter=${3:0:1}
upper=${letter^^}
lower=${letter,,}
powershell.exe -Command "$serialcmd"
sleep 1
sudo mount -t drvfs $upper: /mnt/$lower
cp $1 /mnt/$lower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment