Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,17 @@ benchpod status --json # the pod's raw status reply

# Hardware (network):
benchpod la voltage 3.3V # the DUT's I/O voltage for now (it normally comes from the wiring profile)
benchpod la voltage 5V # digital board v3r4: 5 V I/O (see the 5 V page linked under la voltage)
benchpod generate --waveform sine --freq 1kHz --duration 2s # DAC waveform
benchpod measure --waveform sine --samples 1024 # DAC + ADC loopback
benchpod capture --samples 1024 --output csv # ADC snapshot
benchpod stream ...
benchpod test ...
benchpod la pull 3 up # LA pin pull resistor: up, down or off
benchpod la pull 3 up # LA pin pull resistor: up, down or off (digital v3r4: every pin, strength picked by the pod)
benchpod la status
benchpod la step --la 6 --steps 200 --delay 500us --dir-la 7 --direction 1
benchpod la pins # every LA pin: function, level, pull-up, direction, warnings
benchpod la pins 1-4 # only LA1-LA4
benchpod la dir 9,10 dut_output # the pod refuses push-pull drivers on these pins
benchpod i2c start --sda 1 --scl 2 --hz 400000 # the pod as an I2C master (gateware v55+)
benchpod i2c xfer 0x48 --write 0d --read 2 # hex in, hex out
Expand Down Expand Up @@ -1476,7 +1478,9 @@ embeddedci.com; `la voltage` also works over USB.
### `benchpod la voltage [VOLTAGE]`

Show or set the LA bank's I/O voltage, which must match the DUT's: `1.8V` or `3.3V`
(also `1800mV`, `3.3` or `3300`). Leave it out to show the setting. The pod refuses
(also `1800mV`, `3.3` or `3300`), or `5V` on a pod with the digital board v3r4
([5 V I/O](https://embeddedci.com/docs/benchpod-targets/5v-rs485#5v-io): pin 21 goes to 5 V,
and the output then shows pin 21). Leave it out to show the setting. The pod refuses
LA capture, UART, SWD flash, pull-ups and sensor emulation until it is set;
1.8 V needs a v3 pod, and the pod refuses a change while an LA pin is in use. Works
over the network, over USB and through embeddedci.com. No flags.
Expand Down Expand Up @@ -1529,15 +1533,18 @@ Pulse an LA pin N times, for step/dir stepper drivers. The FPGA times the train.
| `--dir-la` | (none) | Direction pin, driven before stepping. |
| `--direction` | `0` | Level for `--dir-la`: `0` or `1`. |

### `benchpod la pins`
### `benchpod la pins [PINS]`

List all 14 LA pins: what each one is used for (and by whom), its GPIO mode and
List all 14 LA pins, or only PINS (a pin, a list or a range: `9`, `9,10`, `9-12`,
`la9`, or a name from the pod's wiring profile): what each one is used for (and by whom), its GPIO mode and
level, its live level, its pull resistor, its direction (see `la dir`) and its
warnings. A warning line follows the table for each pin that has one: a pull-up on
under a push-pull output (it only costs current), or a pin driven high or pulled up
while the pod's target power is off (that powers an unpowered DUT through its pins;
ignore it when the DUT has its own supply). Directions and warnings need gateware v55
or later; older pods show every pin as `unknown`.
or later; older pods show every pin as `unknown`. A list too large for one cloud reply
(a long sensor instance name on every pin) is read in two parts by itself (firmware after
3.10.12; older firmware answers "reply too large" then).

| Flag | Default | Purpose |
|----------|---------|----------------------------------|
Expand Down
96 changes: 92 additions & 4 deletions cmd/benchpod-cli/busmaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,19 +562,107 @@ func printLAPins(w io.Writer, rep laPinsReply) {
}
}

// laPinsCommander is the one call laPinsFetch needs (the pod client).
type laPinsCommander interface {
Command(ctx context.Context, req map[string]any) (json.RawMessage, error)
}

// laPinsFetch reads la_pins: every pin (pins nil) or only those pins. Firmware after 3.10.12 sends
// only the pins asked for; older firmware sends all 14 and they are filtered here. A full listing
// the pod answers with "reply too large" (a long sensor instance name on every pin) is read in two
// parts, LA1-7 and LA8-14, and joined.
func laPinsFetch(ctx context.Context, c laPinsCommander, pins []int) (json.RawMessage, error) {
if pins == nil {
raw, err := c.Command(ctx, map[string]any{"cmd": "la_pins"})
if err == nil || !strings.Contains(err.Error(), "reply too large") {
return raw, err
}
first, err1 := laPinsQuery(ctx, c, []int{1, 2, 3, 4, 5, 6, 7})
if err1 != nil {
return nil, laPinsUpdateHint(err)
}
if n, _ := first["pins"].([]any); len(n) > 7 {
return nil, laPinsUpdateHint(err) // firmware without the pin subset: it sent everything again
}
second, err2 := laPinsQuery(ctx, c, []int{8, 9, 10, 11, 12, 13, 14})
if err2 != nil {
return nil, err2
}
a, _ := first["pins"].([]any)
b, _ := second["pins"].([]any)
first["pins"] = append(a, b...)
return json.Marshal(first)
}
m, err := laPinsQuery(ctx, c, pins)
if err != nil {
return nil, err
}
return json.Marshal(m)
}

// laPinsUpdateHint says what to do when older firmware (no pin subset) cannot send the whole list.
func laPinsUpdateHint(err error) error {
return fmt.Errorf("%w; firmware after 3.10.12 reads this list in parts: update the pod "+
"(benchpod flash-self, or the firmware update in the web app), or ask for fewer pins "+
"(benchpod la pins 1-7)", err)
}

// laPinsQuery sends la_pins with "la" and keeps only the entries of those pins.
func laPinsQuery(ctx context.Context, c laPinsCommander, pins []int) (map[string]any, error) {
raw, err := c.Command(ctx, map[string]any{"cmd": "la_pins", "la": pins})
if err != nil {
return nil, err
}
var m map[string]any
if err := json.Unmarshal(raw, &m); err != nil {
return nil, fmt.Errorf("unexpected reply %s", strings.TrimSpace(string(raw)))
}
want := map[int]bool{}
for _, p := range pins {
want[p] = true
}
var keep []any
entries, _ := m["pins"].([]any)
for _, e := range entries {
if em, ok := e.(map[string]any); ok {
if la, ok := em["la"].(float64); ok && want[int(la)] {
keep = append(keep, e)
}
}
}
if keep == nil {
keep = []any{}
}
m["pins"] = keep
return m, nil
}

func newLAPinsCmd(g *globalFlags) *cobra.Command {
var asJSON bool
cmd := &cobra.Command{
Use: "pins",
Use: "pins [PINS]",
Short: "List every LA pin: function, GPIO state, live level, pull-up, direction and warnings",
Args: cobra.NoArgs,
RunE: func(_ *cobra.Command, _ []string) error {
Long: "List every LA pin, or only PINS (a pin, a list or a range: 9, 9,10, 9-12, la9, or a\n" +
"name from the pod's wiring profile). A list too large for one cloud reply is read\n" +
"in two parts by itself (firmware after 3.10.12).",
Example: " benchpod la pins\n benchpod la pins 1-4\n benchpod la pins uart_rx --json",
Args: cobra.MaximumNArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
var pins []int
if len(args) == 1 && !strings.EqualFold(strings.TrimSpace(args[0]), "all") {
r := &pinResolver{g: g}
p, err := r.pins("PINS", args[0])
if err != nil {
return usageErrorf("%v", err)
}
pins = p
}
ctx, cancel, t, err := g.podClient("la pins", i2cTimeout)
if err != nil {
return err
}
defer cancel()
raw, err := t.client.Command(ctx, map[string]any{"cmd": "la_pins"})
raw, err := laPinsFetch(ctx, t.client, pins)
if err != nil {
return fmt.Errorf("la pins: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/benchpod-cli/commands_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,11 @@ func newLAPullCmd(g *globalFlags) *cobra.Command {
"and reports its value (ohms). Which pins have one and which way each can pull depends on the\n" +
"board: today LA1-LA6 pull up, LA7/LA8 pull down and LA9-LA14 have none; the reply's dirs\n" +
"lists them. Another direction is refused (BP0024), and up or down on a pin without a resistor\n" +
"(BP0023); off works on every pin. The resistors go to 3.3 V, so the LA bank must be at 3.3 V.",
"(BP0023); off works on every pin. The resistors go to the LA bank voltage.\n\n" +
"Digital board v3r4: every pin, LA1-LA14, pulls up or down with a 10k, a 2.2k or both (about\n" +
"1.8k). The pod picks the strength from the pin's function (2.2k for I2C, one-wire UART, open\n" +
"drain and outputs in 5 V mode, else 10k); the reply's strength says which. The pull-ups go to\n" +
"J1 pin 21, so they work at 1.8, 3.3 and 5 V; while pin 21 is down they are off (BP0029).",
Example: " benchpod la pull 1 up\n benchpod la pull 7 down\n benchpod la pull 7 off",
Args: cobra.ExactArgs(2),
RunE: func(_ *cobra.Command, args []string) error {
Expand Down
96 changes: 96 additions & 0 deletions cmd/benchpod-cli/lapins_subset_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package main

import (
"context"
"encoding/json"
"errors"
"reflect"
"strings"
"testing"
)

// fakeLAPins answers la_pins like the firmware: "la" selects pins when subset is true (firmware
// after 3.10.12), the full listing fails with "reply too large" when tooLarge is true.
type fakeLAPins struct {
subset, tooLarge bool
sent []map[string]any
}

func (f *fakeLAPins) Command(_ context.Context, req map[string]any) (json.RawMessage, error) {
f.sent = append(f.sent, req)
want, has := req["la"].([]int)
if !f.subset {
has = false
}
if !has && f.tooLarge {
return nil, errors.New("pod error: reply too large")
}
var pins []map[string]any
for la := 1; la <= 14; la++ {
ok := !has
for _, w := range want {
ok = ok || w == la
}
if ok {
pins = append(pins, map[string]any{"la": la, "function": "none"})
}
}
return json.Marshal(map[string]any{"pins": pins, "pull_dirs": []string{"up", "down"}, "levels": nil})
}

func pinNumbers(t *testing.T, raw json.RawMessage) []int {
t.Helper()
var rep laPinsReply
if err := json.Unmarshal(raw, &rep); err != nil {
t.Fatal(err)
}
var out []int
for _, p := range rep.Pins {
out = append(out, p.LA)
}
return out
}

func TestLAPinsSubset(t *testing.T) {
f := &fakeLAPins{subset: true}
raw, err := laPinsFetch(context.Background(), f, []int{9, 3})
if err != nil {
t.Fatal(err)
}
if got := pinNumbers(t, raw); !reflect.DeepEqual(got, []int{3, 9}) {
t.Fatalf("pins %v", got)
}
// Older firmware ignores "la": the CLI keeps the pins asked for.
f = &fakeLAPins{}
raw, _ = laPinsFetch(context.Background(), f, []int{5})
if got := pinNumbers(t, raw); !reflect.DeepEqual(got, []int{5}) {
t.Fatalf("old firmware pins %v", got)
}
// Without PINS the request is as before.
_, _ = laPinsFetch(context.Background(), f, nil)
if last := f.sent[len(f.sent)-1]; !reflect.DeepEqual(last, map[string]any{"cmd": "la_pins"}) {
t.Fatalf("plain request %v", last)
}
}

func TestLAPinsTooLargeReadsInTwoParts(t *testing.T) {
f := &fakeLAPins{subset: true, tooLarge: true}
raw, err := laPinsFetch(context.Background(), f, nil)
if err != nil {
t.Fatal(err)
}
want := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}
if got := pinNumbers(t, raw); !reflect.DeepEqual(got, want) {
t.Fatalf("pins %v", got)
}
if len(f.sent) != 3 {
t.Fatalf("requests %v", f.sent)
}
// Firmware without the subset cannot help: the error stands.
f = &fakeLAPins{tooLarge: true}
_, err = laPinsFetch(context.Background(), f, nil)
if err == nil || !strings.Contains(err.Error(), "reply too large") ||
!strings.Contains(err.Error(), "firmware after 3.10.12 reads this list in parts") {
t.Fatalf("want the too-large error with the update hint, got %v", err)
}
}
50 changes: 46 additions & 4 deletions cmd/benchpod-cli/lavoltage.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ const laVoltageMissing = "this firmware has no LA voltage selection; update the
func newLAVoltageCmd(g *globalFlags) *cobra.Command {
return &cobra.Command{
Use: "voltage [VOLTAGE]",
Short: "Show or set the LA bank I/O voltage (1.8V or 3.3V, the DUT's logic level)",
Short: "Show or set the LA bank I/O voltage (1.8V or 3.3V, 5V on digital v3r4: the DUT's logic level)",
Long: "Show or set the voltage of the pod's LA bank (LA1-LA14), which must match the\n" +
"DUT's I/O voltage. The pod refuses LA capture, UART, SWD flash, pull-ups and\n" +
"sensor emulation until it is set. 1.8V needs a v3 pod, and the pod refuses a\n" +
"change while any LA pin is in use.\n\n" +
"VOLTAGE is 1.8V or 3.3V (also 1800mV, 3.3, or 3300). Omit it to show the\n" +
"current setting. Works over the network, over USB (--connection usb) and through\n" +
"VOLTAGE is 1.8V or 3.3V (also 1800mV, 3.3, or 3300).\n\n" +
"5V (5.0, 5000) works on a pod with the digital board v3r4: pin 21, the pull-up rail,\n" +
"goes to 5V and outputs reach 5V through their pull-ups (benchpod la pull PIN up). The\n" +
"output then shows pin 21. BP0028: 5V did not come up. Other pods refuse 5000. Details:\n" +
"https://embeddedci.com/docs/benchpod-targets/5v-rs485#5v-io\n\n" +
"Omit VOLTAGE to show the current setting. Works over the network, over USB (--connection usb) and through\n" +
"embeddedci.com (--connection embeddedci:<name>).\n\n" +
"The pod forgets the voltage on a restart. Firmware 3.10.8 and later keeps wiring\n" +
"profiles on the pod: the profile's I/O voltage is applied when the DUT powers on and\n" +
Expand Down Expand Up @@ -80,6 +84,36 @@ var openLAVoltageConsole = func(g *globalFlags, device string, timeout time.Dura
type laVoltageReply struct {
MV int `json:"mv"`
ReadbackMV int `json:"readback_mv"`
// VrefOut is J1 pin 21 on the digital board v3r4 (nil on other boards).
VrefOut *vrefOut `json:"vref_out,omitempty"`
}

// vrefOut is pin 21 in the la_voltage reply (digital board v3r4).
type vrefOut struct {
Source string `json:"source"` // "bank" or "5v"
SetMV int `json:"set_mv"`
MV int `json:"mv"` // -1 without a reading
State string `json:"state"`
Up bool `json:"up"`
}

// pin21Text is pin 21's line and, when it is not ok, a warning ("" when there is none).
func pin21Text(v *vrefOut) (line, warning string) {
measured := "no reading"
if v.MV >= 0 {
measured = formatMV(v.MV)
}
line = fmt.Sprintf("J1 pin 21 (pull-up rail): %s, set to %s (%s)", measured, formatMV(v.SetMV), v.State)
switch v.State {
case "high":
warning = "pin 21 is above its setting: a DUT signal above the I/O voltage lifts it through the pull " +
"resistors. Select 5V (benchpod la voltage 5.0) or remove the signal."
case "low":
warning = "pin 21 is below its setting: something on it draws too much current."
case "short":
warning = "pin 21 is shorted or held down: the pull resistors are off until it is back."
}
return line, warning
}

func runLAVoltage(g *globalFlags, mv int, out, warn io.Writer) error {
Expand All @@ -96,9 +130,17 @@ func runLAVoltage(g *globalFlags, mv int, out, warn io.Writer) error {
return nil
}
fmt.Fprintf(out, "LA voltage of %s%s %s\n", label, verb, formatMV(rep.MV))
if rep.ReadbackMV != 0 && rep.ReadbackMV != rep.MV {
// In 5 V mode the bank stays at 3.3 V while the I/O voltage is 5 V.
if rep.ReadbackMV != 0 && rep.ReadbackMV != rep.MV && !(rep.MV == 5000 && rep.ReadbackMV == 3300) {
fmt.Fprintf(warn, "Warning: the bank's power mux reports %s, not %s\n", formatMV(rep.ReadbackMV), formatMV(rep.MV))
}
if rep.VrefOut != nil {
line, w := pin21Text(rep.VrefOut)
fmt.Fprintln(out, line)
if w != "" {
fmt.Fprintln(warn, "Warning: "+w)
}
}
if mv != 0 && podStoresWiring(g) {
fmt.Fprintln(out, "Not saved: the pod uses the I/O voltage in its wiring profile after a restart (change it there with `benchpod wiring save`, or in the Pins pane).")
return nil
Expand Down
Loading