Last active
February 3, 2022 20:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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