13 Commits
Author SHA1 Message Date
WillandCursor 8150c2af77 BWM: add ability to flash over wifi
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-26 12:23:47 -04:00
MsprgandClaude Fable 5.1 465cb47b5a pm5: BWM link flow control counts bytes in flight, sized to the ESP ring
A forward frame on the BWM link is anywhere from ~30 bytes to ~2.1 KB (an
NG reply at PM3_FPC_MAX_DATA), so a 16-frame ack window allowed ~33 KB
in flight while the module held un-acked frames in a 4 KB UART ring:
any radio stall of ~45 ms at 921600 baud overflowed it and the module
dropped PM3 bytes. A frame cap tight enough for big frames stalled
uploads, where the module defers small acks behind large incoming
chunks (the old comment on BWM_FC_WINDOW).

Count bytes instead: a FIFO of un-acked frame lengths (the module acks
in order) with budget BWM_FC_BYTES = BWM_ESP_UART_RX_BUF (12288, the
module's ring in the companion Proxmark5_BWM_esp32 PR) minus 1 KB slack,
and a 64-frame FIFO cap for tiny frames. Change the ring size in both
places; the armsrc -pedantic C99 build rejects a static assert tying
them.

The ack timeout no longer forgets the whole window. That made the gate
open loop for the rest of the command: the acks of forgotten frames
released younger ones early, so after the first eaten ack (bwm_cmd()
drains the ring, #3648) the budget protected nothing. Now it forgets
just enough of the oldest frames to send this one: a lost ack costs one
wait and heals, and a stalled radio gets one frame per timeout on top of
a full ring instead of a window. The wait is 200 ms instead of 50: a
full window that stays full is the module stuck on the radio (a phone
scanning stalls BLE for a few hundred ms), and every timeout leaks a
frame into its ring. A CMD_ERROR broadcast naming SEND_FORWARD_DATA
releases the slot like the ack (older module firmware answers that way
when a WiFi forwarding type is configured and no channel takes the
frame). hw status at debug level prints the window counters.

Measured over BLE with the companion module firmware, which acks a
frame as it leaves its ring: 86 KB/s honest against 88 KB/s open loop,
and a 20 s run with the phone scanning meanwhile finishes clean.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-24 10:33:47 +02:00
MsprgandClaude Fable 5.1 0cd1fada0e pm5: auto power-off: idle timeout, unplug switch, stored on the BWM
The USB-unplug power-off left two ways to drain the battery: a PM5
woken by the button and forgotten, and one left idle after the phone
disconnected.

Idle trigger (opt-in, PM5_AUTOOFF_IDLE_MS 0 by default so out of the box
only the unplug trigger exists, as before): on battery the board powers
off after the idle timeout with no interaction and no wireless client.
Interaction is a received command over any transport, any button press,
or a client connecting or leaving; a standalone mode or a long-running
command holds the main loop, so neither can be cut short. The BWM
reports its clients with the LINK_STATE broadcast (8092, companion
Proxmark5_BWM_esp32 PR) which bwm_forward.c tracks; at boot the BLE
half is seeded with a status query since the module only reports
changes. When the timer is due but a client is still tracked, the module
is asked for its BLE state (at most every 10 s), so a lost "client left"
broadcast cannot pin the board on. And right before going off the module
is asked once more: older module firmware never sends the broadcast and
a "connected" one can get lost, and neither may power the board off
under a silent BLE client. No answer means off.

--unplug off: the unplug trigger always won, so "survive the unplug, go
off after N idle seconds" was not reachable. It is its own setting
(default on = unchanged). With it off an unplug only restarts the idle
clock - from the unplug, not from the last command, or a board that sat
idle on USB for an hour would still die with the cable. Unplug detection
is edge-based (VUSB present at the previous poll, absent at this one)
instead of "absent and seen since boot", which would fire on every poll
after a tolerated unplug. VUSB is followed while the feature is switched
off too, so switching it on again on battery is not taken for an unplug.

Stored on the BWM: runtime-only settings reset at every boot, which is
exactly when the idle trigger matters. The PM5 has no settings store, so
the switch, the idle timeout and the unplug switch live in the module's
host value slots (APP_CMD_SET/GET_SYS_HOST_VALUE 1021/1022, companion
PR; slot 0 switch, 1 idle seconds, 2 unplug), loaded at the first
auto-off poll and saved by CMD_PM5_BWM_AUTOOFF with 1 s per write, so a
silent or older module still leaves the reply inside the client's 5 s
wait. Without a module, or with an older one, the defaults apply and the
status says "not stored".

hw bwm autooff [on|off] [--idle <sec>] [--unplug <on|off>]; no argument
shows the state, one fact per line: switch, idle timeout, unplug
power-off, stored on module, USB power, USB seen since boot, unplug
trigger armed, tracked client, the module's BLE state, idle time.
Payload [action][enabled][idle_s u32][unplug, optional] with keep
sentinels; both actions are non-zero so an old firmware, which reads
byte 0 as the enable flag, can only be left enabled. hw status prints
the module's live BLE state and the auto power-off setting; at debug
level also the tracked client, which should agree with the live state.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-24 10:33:46 +02:00
Msprg 22e9b37b9f armsrc: resync BWM link baud after an AT32-only reset
The ESP keeps its negotiated UART baud (921600) across a bootloader round
trip, hw reset or flash, while the AT32 restarts at the boot baud (460800)
and its baud-set request is then garbage to the ESP. The link stayed at
460800 and every BWM command failed until the module lost power.

Probe GET_UART_BAUD at both rates on boot and adopt the one the ESP answers
at; only run the set-baud handshake when it really is at the boot baud.
2026-09-03 01:02:38 +02:00
Niel Nielsen a3b4767ff6 Enhance UART baud negotiation and acknowledgment
Added acknowledgment handling for GET_UART_BAUD command and improved baud negotiation logic.

Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-09-02 14:24:03 +02:00
Niel Nielsen b8d0fbc347 Implement baud acknowledgment in negotiation process
Add baud acknowledgment handling in UART negotiation.

Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-31 08:40:25 +02:00
iceman1001 35c098d489 make style 2026-08-29 17:42:29 +02:00
Niel Nielsen 72c99f1345 Fix formatting and comments in bwm_forward.c
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-27 19:40:20 +02:00
Niel Nielsen a1d256e16a Refactor flow control and update CRC handling
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-27 12:39:04 +02:00
Niel Nielsen d2bd743542 Refactor bwm_forward.c for improved clarity and structure
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-26 20:22:05 +02:00
Philippe Teuwen 0c8005b9c1 Remove inline keyword to fix compiler warning about it not being fulfilled anyway 2026-08-26 16:26:48 +02:00
Niel Nielsen a82c6e4fe9 Add files via upload
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-26 16:07:37 +02:00
Niel Nielsen 3553836b7c Add files via upload
Signed-off-by: Niel Nielsen <nieldk@gmail.com>
2026-08-26 16:07:37 +02:00