Add dispatch loop, copy_to_ram, retry picotool load without sleep

This commit is contained in:
Ian Gulliver
2026-04-06 17:36:41 +09:00
parent b197f0bfa7
commit 00b960d81d
7 changed files with 87 additions and 116 deletions

View File

@@ -6,25 +6,20 @@ import (
"time"
)
func WaitForBootsel(serial string, timeout time.Duration) error {
func Load(uf2Path string, 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 {
var out []byte
var err error
for {
cmd := exec.Command("picotool", "load", uf2Path, "-x", "--ser", serial)
out, err = cmd.CombinedOutput()
if err == nil {
return nil
}
time.Sleep(100 * time.Millisecond)
if time.Now().After(deadline) {
return fmt.Errorf("picotool load: %w\n%s", err, out)
}
}
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, "-x", "--ser", serial)
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("picotool load: %w\n%s", err, out)
}
return nil
}
func Reboot(serial string) error {