Skip to content

RP: add pio program to drive bipolar steppers through driver board#5808

Open
1-rafael-1 wants to merge 4 commits intoembassy-rs:mainfrom
1-rafael-1:bipolar-4-wire-stepper
Open

RP: add pio program to drive bipolar steppers through driver board#5808
1-rafael-1 wants to merge 4 commits intoembassy-rs:mainfrom
1-rafael-1:bipolar-4-wire-stepper

Conversation

@1-rafael-1
Copy link
Copy Markdown
Contributor

This PR adds a pio program step_dirthat can be used to drive a 4-wire bipolar stepper motor using a driver board. It includes one example (duplicated for rp and rp23).

The pio program has three modes, depending on how low a frequency one needs for driving the motor. It uses two gpio, one is just the direction control and uses normal gpio toggling and the other is driven by a pio program to generate the pulses.

This PR has been coded with AI assistance. I have undertaken these following steps to verify the viability of this contribution:

  • I have reviewed the code
  • I have used a logic analyzer to confirm expected outputs
  • I have tested on a rp2350 board, tmc2209 stepper driver board and nema17 bipolar 4wire motor.
  • I have no rp2040 on hand so for this I assume parity.

Here is the LA output for 10 dedicated steps at 2Khz frequency using default setup. See pulses and measurements: this should work as expected.
image

Here is the test setup with hardware, working as expected:
image

I am happy to change/adapt code if concerns arise :-). I am equally happy to run/demonstrate other tests if requested.

Copilot AI review requested due to automatic review settings April 6, 2026 08:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new step_dir PIO program/driver in embassy-rp for generating STEP pulses via PIO plus a software-controlled DIR GPIO, along with duplicated usage examples for RP2040 (rp) and RP235x (rp235x) boards.

Changes:

  • Added embassy_rp::pio_programs::step_dir with configurable STEP pulse timing and frequency control.
  • Added pio_step_dir.rs examples for both rp and rp235x.
  • Exported the new module from embassy-rp/src/pio_programs/mod.rs.

Reviewed changes

Copilot reviewed 2 out of 4 changed files in this pull request and generated 2 comments.

File Description
examples/rp235x/src/bin/pio_step_dir.rs Adds an rp235x example demonstrating the new step/dir driver usage.
examples/rp/src/bin/pio_step_dir.rs Adds an rp2040 example demonstrating the new step/dir driver usage.
embassy-rp/src/pio_programs/step_dir.rs Implements the step/dir PIO program wrapper and API (timing, frequency, move, stop).
embassy-rp/src/pio_programs/mod.rs Exposes the new step_dir module.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread embassy-rp/src/pio_programs/step_dir.rs
Comment thread embassy-rp/src/pio_programs/step_dir.rs
@xoviat xoviat added the e-rp Issues for the RP family of chips label Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e-rp Issues for the RP family of chips

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants