Poll for BOOTSEL readiness instead of fixed sleep, load with -x
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user