Add test target, parallelize load and info across two devices
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
---
|
---
|
||||||
name: load
|
name: load
|
||||||
description: Build firmware, load it onto the Pico, and reboot. Use when the user says "load", "flash", "deploy", "push to pico", or after making changes to picomap.cpp or include/ headers that need testing on hardware.
|
description: Build firmware, load it onto the Pico, and reboot. Use when the user says "load", "flash", "deploy", "push to pico", or after making changes to firmware/ files that need testing on hardware.
|
||||||
user-invocable: true
|
user-invocable: true
|
||||||
---
|
---
|
||||||
|
|
||||||
Run `go run ./cmd/load/` from the project root. This builds the firmware, loads it onto the Pico, and reboots.
|
Run `go run ./cmd/load/` from the project root. This builds both firmware targets, loads picomap onto the first device and picomap_test onto the second, and reboots both.
|
||||||
|
|
||||||
If cmake needs reconfiguring (e.g. after CMakeLists.txt changes), run `cmake -B build` first.
|
After loading, run `go run ./cmd/info/` to verify both devices are responding.
|
||||||
|
|
||||||
After modifying the load command itself (cmd/load/, lib/wire/, lib/picoserial/), run it twice: once to load the firmware, once to verify the load process still works end-to-end.
|
After modifying the load command itself (cmd/load/, lib/wire/, lib/picoserial/), run it twice: once to load the firmware, once to verify the load process still works end-to-end.
|
||||||
|
|||||||
@@ -3,11 +3,18 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/theater/picomap/lib/client"
|
"github.com/theater/picomap/lib/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type deviceResult struct {
|
||||||
|
dev string
|
||||||
|
info *client.ResponseInfo
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := run(); err != nil {
|
if err := run(); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||||
@@ -21,27 +28,42 @@ func run() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(devs) == 0 {
|
if len(devs) == 0 {
|
||||||
return fmt.Errorf("no device found")
|
return fmt.Errorf("no devices found")
|
||||||
}
|
|
||||||
dev := devs[0]
|
|
||||||
|
|
||||||
fmt.Printf("Device: %s\n", dev)
|
|
||||||
c, err := client.NewSerial(dev, 2*time.Second)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
info, err := c.Info()
|
|
||||||
c.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Board ID: %02X%02X%02X%02X%02X%02X%02X%02X\n",
|
results := make([]deviceResult, len(devs))
|
||||||
info.BoardID[0], info.BoardID[1], info.BoardID[2], info.BoardID[3],
|
var wg sync.WaitGroup
|
||||||
info.BoardID[4], info.BoardID[5], info.BoardID[6], info.BoardID[7])
|
for i, dev := range devs {
|
||||||
fmt.Printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
|
wg.Add(1)
|
||||||
info.MAC[0], info.MAC[1], info.MAC[2],
|
go func() {
|
||||||
info.MAC[3], info.MAC[4], info.MAC[5])
|
defer wg.Done()
|
||||||
|
results[i].dev = dev
|
||||||
|
c, err := client.NewSerial(dev, 2*time.Second)
|
||||||
|
if err != nil {
|
||||||
|
results[i].err = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
info, err := c.Info()
|
||||||
|
c.Close()
|
||||||
|
results[i].info = info
|
||||||
|
results[i].err = err
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
for _, r := range results {
|
||||||
|
fmt.Printf("Device: %s\n", r.dev)
|
||||||
|
if r.err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, " error: %v\n", r.err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Printf(" Board ID: %02X%02X%02X%02X%02X%02X%02X%02X\n",
|
||||||
|
r.info.BoardID[0], r.info.BoardID[1], r.info.BoardID[2], r.info.BoardID[3],
|
||||||
|
r.info.BoardID[4], r.info.BoardID[5], r.info.BoardID[6], r.info.BoardID[7])
|
||||||
|
fmt.Printf(" MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
|
||||||
|
r.info.MAC[0], r.info.MAC[1], r.info.MAC[2],
|
||||||
|
r.info.MAC[3], r.info.MAC[4], r.info.MAC[5])
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
115
cmd/load/main.go
115
cmd/load/main.go
@@ -5,6 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/theater/picomap/lib/client"
|
"github.com/theater/picomap/lib/client"
|
||||||
@@ -25,7 +26,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func run(buildDir string) error {
|
func build(buildDir string) error {
|
||||||
fmt.Println("Configuring...")
|
fmt.Println("Configuring...")
|
||||||
cmake := exec.Command("cmake", "-S", filepath.Join(filepath.Dir(buildDir)), "-B", buildDir)
|
cmake := exec.Command("cmake", "-S", filepath.Join(filepath.Dir(buildDir)), "-B", buildDir)
|
||||||
cmake.Stdout = os.Stdout
|
cmake.Stdout = os.Stdout
|
||||||
@@ -41,36 +42,116 @@ func run(buildDir string) error {
|
|||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
return fmt.Errorf("build failed: %w", err)
|
return fmt.Errorf("build failed: %w", err)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func boardSerial(id [8]byte) string {
|
||||||
|
return fmt.Sprintf("%02X%02X%02X%02X%02X%02X%02X%02X",
|
||||||
|
id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7])
|
||||||
|
}
|
||||||
|
|
||||||
|
func run(buildDir string) error {
|
||||||
|
if err := build(buildDir); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
devs, err := client.ListSerial()
|
devs, err := client.ListSerial()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(devs) > 0 {
|
if len(devs) < 2 {
|
||||||
dev := devs[0]
|
return fmt.Errorf("expected 2 devices, found %d", len(devs))
|
||||||
fmt.Printf("Sending PICOBOOT request to %s...\n", dev)
|
}
|
||||||
c, err := client.NewSerial(dev, 2*time.Second)
|
|
||||||
|
serials := make([]string, 2)
|
||||||
|
errs := make([]error, 2)
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
for i := range 2 {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
c, err := client.NewSerial(devs[i], 2*time.Second)
|
||||||
|
if err != nil {
|
||||||
|
errs[i] = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
info, err := c.Info()
|
||||||
|
c.Close()
|
||||||
|
if err != nil {
|
||||||
|
errs[i] = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
serials[i] = boardSerial(info.BoardID)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
for i, err := range errs {
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("info %s: %w", devs[i], err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Sending PICOBOOT requests...")
|
||||||
|
for i := range 2 {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
c, err := client.NewSerial(devs[i], 2*time.Second)
|
||||||
|
if err != nil {
|
||||||
|
errs[i] = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = c.PICOBOOT()
|
||||||
|
c.Close()
|
||||||
|
if err != nil {
|
||||||
|
errs[i] = fmt.Errorf("PICOBOOT %s: %w", devs[i], err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
for _, err := range errs {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = c.PICOBOOT()
|
|
||||||
c.Close()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "warning: PICOBOOT request failed: %v\n", err)
|
|
||||||
} else {
|
|
||||||
fmt.Println("Device confirmed reboot into PICOBOOT mode.")
|
|
||||||
}
|
|
||||||
time.Sleep(2 * time.Second)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uf2 := filepath.Join(buildDir, "picomap.uf2")
|
time.Sleep(2 * time.Second)
|
||||||
|
|
||||||
|
uf2s := []string{
|
||||||
|
filepath.Join(buildDir, "picomap.uf2"),
|
||||||
|
filepath.Join(buildDir, "picomap_test.uf2"),
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println("Loading firmware...")
|
fmt.Println("Loading firmware...")
|
||||||
if err := picotool.Load(uf2); err != nil {
|
for i := range 2 {
|
||||||
return err
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
errs[i] = picotool.Load(uf2s[i], serials[i])
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
for i, err := range errs {
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("load %s: %w", serials[i], err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Rebooting...")
|
fmt.Println("Rebooting...")
|
||||||
_ = picotool.Reboot()
|
for i := range 2 {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
errs[i] = picotool.Reboot(serials[i])
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
for i, err := range errs {
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("reboot %s: %w", serials[i], err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println("Done.")
|
fmt.Println("Done.")
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -9,26 +9,29 @@ set(CMAKE_C_STANDARD 11)
|
|||||||
set(CMAKE_CXX_STANDARD 23)
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
pico_sdk_init()
|
pico_sdk_init()
|
||||||
|
|
||||||
add_executable(picomap
|
set(LIB_SOURCES
|
||||||
main.cpp
|
lib/dhcp.cpp
|
||||||
dhcp.cpp
|
lib/net.cpp
|
||||||
net.cpp
|
lib/tusb_config.cpp
|
||||||
tusb_config.cpp
|
|
||||||
w6300/w6300.cpp
|
w6300/w6300.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(picomap PRIVATE
|
set(LIB_DEPS pico_stdlib pico_rand tinyusb_device tinyusb_board hardware_pio hardware_spi hardware_dma hardware_clocks)
|
||||||
include
|
|
||||||
w6300
|
|
||||||
)
|
|
||||||
|
|
||||||
|
add_executable(picomap firmware.cpp ${LIB_SOURCES})
|
||||||
|
target_include_directories(picomap PRIVATE include w6300)
|
||||||
target_compile_options(picomap PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
target_compile_options(picomap PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
||||||
|
|
||||||
pico_generate_pio_header(picomap ${CMAKE_CURRENT_LIST_DIR}/w6300/qspi.pio)
|
pico_generate_pio_header(picomap ${CMAKE_CURRENT_LIST_DIR}/w6300/qspi.pio)
|
||||||
|
|
||||||
pico_enable_stdio_usb(picomap 0)
|
pico_enable_stdio_usb(picomap 0)
|
||||||
pico_enable_stdio_uart(picomap 0)
|
pico_enable_stdio_uart(picomap 0)
|
||||||
|
|
||||||
pico_add_extra_outputs(picomap)
|
pico_add_extra_outputs(picomap)
|
||||||
|
target_link_libraries(picomap ${LIB_DEPS})
|
||||||
|
|
||||||
target_link_libraries(picomap pico_stdlib pico_rand tinyusb_device tinyusb_board hardware_pio hardware_spi hardware_dma hardware_clocks)
|
add_executable(picomap_test test.cpp ${LIB_SOURCES})
|
||||||
|
target_include_directories(picomap_test PRIVATE include w6300)
|
||||||
|
target_compile_options(picomap_test PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
||||||
|
pico_generate_pio_header(picomap_test ${CMAKE_CURRENT_LIST_DIR}/w6300/qspi.pio)
|
||||||
|
pico_enable_stdio_usb(picomap_test 0)
|
||||||
|
pico_enable_stdio_uart(picomap_test 0)
|
||||||
|
pico_add_extra_outputs(picomap_test)
|
||||||
|
target_link_libraries(picomap_test ${LIB_DEPS})
|
||||||
|
|||||||
58
firmware/test.cpp
Normal file
58
firmware/test.cpp
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#include "pico/stdlib.h"
|
||||||
|
#include "pico/bootrom.h"
|
||||||
|
#include "pico/unique_id.h"
|
||||||
|
#include "tusb.h"
|
||||||
|
#include "wire.h"
|
||||||
|
#include "usb_cdc.h"
|
||||||
|
#include "net.h"
|
||||||
|
#include "w6300.h"
|
||||||
|
|
||||||
|
static usb_cdc usb;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
tusb_init();
|
||||||
|
net_init();
|
||||||
|
|
||||||
|
static static_vector<uint8_t, 256> rx_buf;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
tud_task();
|
||||||
|
|
||||||
|
usb.drain();
|
||||||
|
|
||||||
|
while (tud_cdc_available()) {
|
||||||
|
uint8_t byte;
|
||||||
|
if (tud_cdc_read(&byte, 1) != 1) break;
|
||||||
|
|
||||||
|
rx_buf.push_back(byte);
|
||||||
|
|
||||||
|
auto msg = try_decode(rx_buf);
|
||||||
|
if (!msg) {
|
||||||
|
if (rx_buf.full()) rx_buf.clear();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
rx_buf.clear();
|
||||||
|
|
||||||
|
switch (msg->type_id) {
|
||||||
|
case RequestPICOBOOT::ext_id:
|
||||||
|
usb.send(encode_response(msg->message_id, ResponsePICOBOOT{}));
|
||||||
|
sleep_ms(100);
|
||||||
|
reset_usb_boot(0, 1);
|
||||||
|
break;
|
||||||
|
case RequestInfo::ext_id: {
|
||||||
|
ResponseInfo resp;
|
||||||
|
pico_unique_board_id_t uid;
|
||||||
|
pico_get_unique_board_id(&uid);
|
||||||
|
std::copy(uid.id, uid.id + 8, resp.board_id.begin());
|
||||||
|
auto ninfo = w6300::get_net_info();
|
||||||
|
resp.mac = ninfo.mac;
|
||||||
|
usb.send(encode_response(msg->message_id, resp));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__wfi();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,8 +5,8 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Load(uf2Path string) error {
|
func Load(uf2Path string, serial string) error {
|
||||||
cmd := exec.Command("picotool", "load", "-f", uf2Path)
|
cmd := exec.Command("picotool", "load", uf2Path, "--ser", serial)
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("picotool load: %w\n%s", err, out)
|
return fmt.Errorf("picotool load: %w\n%s", err, out)
|
||||||
@@ -14,8 +14,8 @@ func Load(uf2Path string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Reboot() error {
|
func Reboot(serial string) error {
|
||||||
cmd := exec.Command("picotool", "reboot")
|
cmd := exec.Command("picotool", "reboot", "--ser", serial)
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("picotool reboot: %w\n%s", err, out)
|
return fmt.Errorf("picotool reboot: %w\n%s", err, out)
|
||||||
|
|||||||
Reference in New Issue
Block a user