Skip to content

Conversation

@ArthurHeymans
Copy link
Contributor

This change refactors the SPI handling to ensure pins are only configured as outputs during active SPI operations. Between operations, pins are reset to high-impedance (analog/disconnected) state to prevent interference with the target flash chip.

Key changes:

  • Implemented SpiDeviceProvider and SpiCsGuard traits for on-demand SPI configuration
  • Added platform-specific pin reset implementations for STM32 and RP2040
  • Refactored serprog library to use generic patterns with configurable buffer sizes
  • SPI pins are now automatically released after each operation via guard's Drop implementation
  • Separated USB and SPI tasks into focused async functions with proper resource management

This ensures the programmer doesn't hold the SPI pins in output state when not actively communicating with the flash chip.

@ArthurHeymans ArthurHeymans force-pushed the LazySpiDevice branch 2 times, most recently from a2db6a6 to 0e620ab Compare December 22, 2025 16:11
…board

Replace the static `Serprog` struct with a trait-based approach where
SPI pins are only configured as outputs during actual SPI operations:

- Add `SpiDeviceProvider` trait for on-demand SPI device creation
- Add `SpiCsGuard` trait for guards that provide SPI+CS access
- Add `LedProvider` trait with blanket impl for any `OutputPin`
- Replace `Serprog::run_loop()` with free function `run_loop()`
- Store SPI frequency and pass to provider on each acquire

Pin cleanup on drop:
- Embassy SPI/Output do NOT auto-reset pins to input mode
- Each platform implements custom guard with explicit pin reset
- RP2040: Set funcsel to NULL and reset pad control
- STM32: Use Flex drop to set pins to analog mode

This prevents the serprog microcontroller from driving the SPI pins
when idle, allowing the target mainboard to boot normally with the
programmer attached.

🤖 Generated with [eca](https://eca.dev)

Co-Authored-By: eca <[email protected]>
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.

2 participants