Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: stepper: Add stepper driver for allegro a4988 #79120

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Hallootto1100
Copy link

This PR adds a stepper driver for allegro a4988 DMOS microstepping driver.

It has manly be copied from the gpio_stepper_controller and adapted where needed.
I've tested it using the stepper_shell.

One can enable this driver in an overlay like follow:

stepper: a4988 {
        compatible = "allegro,a4988";
        dir-gpios = <&gpio0 22 0>;
        step-gpios = <&gpio0 23 0>;
        en-gpios = <&gpio0 5 0>;
        msx-gpios = <&gpio0 15 0>, 
                    <&gpio0 2 0>, 
                    <&gpio0 4 0>;
    };

en-gpios and msx-gpios (used for selecting micro stepping mode) are optional and can be left away.

Copy link

Hello @Hallootto1100, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

drivers/stepper/CMakeLists.txt Outdated Show resolved Hide resolved
drivers/stepper/Kconfig Outdated Show resolved Hide resolved
drivers/stepper/Kconfig.a4988 Outdated Show resolved Hide resolved
drivers/stepper/Kconfig.a4988 Outdated Show resolved Hide resolved
drivers/stepper/stepper_a4988.c Outdated Show resolved Hide resolved
drivers/stepper/stepper_a4988.c Outdated Show resolved Hide resolved
@jilaypandya
Copy link
Contributor

jilaypandya commented Sep 27, 2024

Thanks for the contribution,

  • Could you write a generic driver with step_dir interface? For instance, a4988, drv8825 and quite a few other drivers have this same interface.
  • Also i can see right now its a bitbang driver, however, as far as i understand you could also use pwm for stepper control, use the step pin.

Adding stepper driver for allegro a4988 DMOS microstepping driver.

Signed-off-by: Armin Kessler <armin.kessler@me.com>
@Hallootto1100
Copy link
Author

Could you write a generic driver with step_dir interface? For instance, a4988, drv8825 and quite a few other drivers have this same interface.

In theory I think yes.
I was not sure about the micro stepping resolution gpios and if they are handled on all stepper drivers the same way.
(e.g. the a4988 has a strange value for setting 16th steps.)
And then many driver have some additional functionalities. E.g. sleep mode and fault detection.

Also i can see right now its a bitbang driver, however, as far as i understand you could also use pwm for stepper control, use the step pin.

That came also to my mind during development. However, I haven't used the pwm api as much and wanted to finish this for now.

Also i see that a lot of code has been carried over from gpio_stepper_controller. These two drivers could be unified in the future. Using Kconfig one can select between GPIO_STEPPER STEP_DIR_PWM_STEPPER or STEP_DIR_GPIO_STEPPER

Yes, that would make sense since a lot of the code is shared.

@pdgendt
Copy link
Collaborator

pdgendt commented Sep 27, 2024

Add an entry to tests/drivers/build_all/stepper/

@Hallootto1100
Copy link
Author

Hi @Hallootto1100,

Can you update the existing gpio_stepper_controller to accomodate this interface. I see a lot of code is carried over from that controller. We can update the existing dts bindings and use kconfig variables to select between various interfaces.

This idea was floated in the community in the past and now i clearly see merit in doing so.

@jilaypandya I might find some time next Friday.

@jilaypandya
Copy link
Contributor

jilaypandya commented Sep 27, 2024

Yes, that would make sense since a lot of the code is shared.

A minor correction on my side, this selection would have to be in device tree. Because in theory you could have two different types of gpio driver and selection of interface would have to be device driver specific.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants