Poll for BOOTSEL readiness instead of fixed sleep, load with -x

This commit is contained in:
Ian Gulliver
2026-04-06 09:19:26 +09:00
parent ee8563ab69
commit 1fa1b2076c
2 changed files with 27 additions and 17 deletions

View File

@@ -3,10 +3,23 @@ package picotool
import (
"fmt"
"os/exec"
"time"
)
func WaitForBootsel(serial string, timeout time.Duration) error {
deadline := time.Now().Add(timeout)
for time.Now().Before(deadline) {
cmd := exec.Command("picotool", "info", "--ser", serial)
if err := cmd.Run(); err == nil {
return nil
}
time.Sleep(100 * time.Millisecond)
}
return fmt.Errorf("device %s not found in BOOTSEL after %v", serial, timeout)
}
func Load(uf2Path string, serial string) error {
cmd := exec.Command("picotool", "load", uf2Path, "--ser", serial)
cmd := exec.Command("picotool", "load", uf2Path, "-x", "--ser", serial)
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("picotool load: %w\n%s", err, out)