Skip to content

StallGuard telemetry (not real sg yet), firmware improvements, TMC2209 UART init fix (2x uart still not working)#150

Merged
spencerhhubert merged 9 commits into
mainfrom
spencer/stallguard-telemetry-wip
May 30, 2026
Merged

StallGuard telemetry (not real sg yet), firmware improvements, TMC2209 UART init fix (2x uart still not working)#150
spencerhhubert merged 9 commits into
mainfrom
spencer/stallguard-telemetry-wip

Conversation

@spencerhhubert

Copy link
Copy Markdown
Contributor

Summary

  • StallGuard telemetry subsystem — new stepper_telemetry.py SQLite store, backend routes (/api/stepper/telemetry/*), and a SvelteKit page at /settings/stepper-stallguard with a StallGuardChart component for recording and visualizing SG_RESULT sweeps
  • Firmware: no-enable-on-boot — steppers are not energized on Pico startup, only when the backend explicitly enables them
  • Firmware: fix TMC_UART_BUS_COUNT preprocessor visibility — was a const uint8_t (invisible to #if guards), now a #define
  • Firmware: GET_VERSION reports build version/variant — makes it easier to confirm which firmware is running on which board
  • Backend: write GCONF on stepper init — TMC2209 chips can reset independently of the Pico (motor power rail cycling), returning to hardware defaults where I_SCALE_ANALOG=1 (current from VREF, ignoring IRUN) and MSTEP_REG_SELECT=0 (microsteps from hardware pins, ignoring CHOPCONF). Backend now writes GCONF=0x1C0 at the top of each stepper's init sequence, before applying microsteps/current from machine.toml
  • Frontend: remove continuous DRV_STATUS poll — 500ms interval was reading all 15 TMC registers over USB serial whenever the driver panel was open, causing ~500% CPU on the Pi
  • flash.py: handle RPI-RP2 block device not yet mounted on Linux
  • .gitignore: ignore machine.toml in any directory
  • SorterOS: full git clone in firstboot + v3.4.5 bump

Test plan

  • Trigger POST /api/system/initialize after deploy, verify GCONF reads back as 0x1C0 (not 0x101) in the TMC panel
  • Verify IRUN=0 reduces/stops motor torque (I_SCALE_ANALOG=0 now active)
  • Verify microstep setting sticks after save (MSTEP_REG_SELECT=1 now active)
  • Open StepperSidebar driver panel — confirm CPU stays low (no continuous TMC register polling)
  • Run a StallGuard sweep from /settings/stepper-stallguard and verify samples are recorded

🤖 Generated with Claude Code

spencerhhubert and others added 7 commits May 29, 2026 16:35
When a Pico is already in bootloader mode, the block device appears
(/dev/sda1, label RPI-RP2) but may not be auto-mounted. The previous
code only checked mounted paths, so it fell through to serial scanning
and bailed with "No Pico boards found over USB". Now checks the block
device before scanning serial ports.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Telemetry DB (stepper_telemetry.py): runs + samples tables in local_state.sqlite,
  self-creating, with downsampling-on-read and a retention prune.
- StallGuard sweep endpoint now records each run + full per-sample context and
  returns run_id; added loaded/label params (loaded -> stall_test).
- Query router (server/routers/telemetry.py): list/summary/run/samples/delete.
- Frontend page (settings/stepper-stallguard) + StallGuardChart.svelte: per-motor
  summary, run list, canvas SG load-curve chart, sweep controls, save-SGTHRS-to-TOML.
- Firmware (sorter_interface_firmware.cpp): leave stepper nEN HIGH at boot, enable
  per-channel on first move / explicit enable so motors don't hold at boot.
  NOTE: this file also carries pre-existing GET_VERSION work, entangled in the
  same working-tree edit; included here since it can't be split non-interactively.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Prevents machine-specific config from being swept into commits.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
TMC_UART_BUS_COUNT was a `const uint8_t`, but it gates `#if
TMC_UART_BUS_COUNT > 1` blocks that construct and route the second TMC
UART bus. The preprocessor cannot see a C++ const (it evaluates as 0),
so `#if 0 > 1` was false and the entire second bus was compiled out on
v1-2 — every channel silently fell back to bus 0. Make it a #define so
the conditional sees the real count. v1-1 and skr stay at 1.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Bake git describe, short commit, UTC build time, and the hw/role
variant into the firmware at configure time and expose them through the
already-present GET_VERSION command handler. Add the matching host-side
MCUDevice.get_version() so the backend can read what is actually
flashed on each board.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…fix DRV_STATUS CPU spike

TMC2209 chips can reset (motor power rail cycling after Pico boot) and
return to hardware defaults: I_SCALE_ANALOG=1 (current from VREF, not
IRUN) and MSTEP_REG_SELECT=0 (microsteps from MS pins, not CHOPCONF).
Backend now writes GCONF=0x1C0 (PD_DISABLE | MSTEP_REG_SELECT |
MULTISTEP_FILT) at the top of each stepper's init sequence, before
applying microsteps/current from machine.toml.

Also remove continuous DRV_STATUS refresh from the 500ms StepperSidebar
poll — it was reading all 15 TMC registers over USB serial every 500ms
whenever the driver panel was open, causing ~500% CPU on the Pi. The
panel still refreshes on open and after saving settings.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vercel

vercel Bot commented May 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sorter-v2-docs Ready Ready Preview, Comment May 30, 2026 10:10am
sorteros-setup Ready Ready Preview, Comment May 30, 2026 10:10am

UART bus1 (uart1, ch4) is not currently working, so the chute stepper
was unreachable over UART. Move it to bus0 where UART is confirmed
functional. c_channel_2_rotor takes the lone bus1 slot (ch4) since it
is less dependent on UART control right now.

New channel order on bus0: chute(ch0), c1_rotor(ch1), c3_rotor(ch2),
carousel(ch3). c2_rotor on bus1 ch4.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@spencerhhubert spencerhhubert changed the title WIP: StallGuard telemetry, firmware improvements, TMC2209 UART init fix StallGuard telemetry (not real sg yet), firmware improvements, TMC2209 UART init fix May 30, 2026
@spencerhhubert spencerhhubert changed the title StallGuard telemetry (not real sg yet), firmware improvements, TMC2209 UART init fix StallGuard telemetry (not real sg yet), firmware improvements, TMC2209 UART init fix (2x uart still not working) May 30, 2026
@spencerhhubert spencerhhubert marked this pull request as ready for review May 30, 2026 10:09
Resolve api.py conflict by keeping both telemetry and tailscale routers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant