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 a4979 #86620

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

verenascst
Copy link

This PR adds a stepper driver for allegro a4979 microstepping driver.

It has manly been developed analogous to drv8429 with adaptions where they are needed. It was tested with the generic stepper sample.

Adding a stepper driver for allegro a4979 microstepping programmable stepper motor driver.

Signed-off-by: Verena Schweinstetter <verena.schweinstetter@zeiss.com>
…legro a4979

Add entry in gpio.dtsi for allegro a4979 stepper in tests/drivers/build_all/stepper

Signed-off-by: Verena Schweinstetter <verena.schweinstetter@zeiss.com>
Copy link

github-actions bot commented Mar 4, 2025

Hello @verenascst, 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. 😊

Copy link
Collaborator

@faxe1008 faxe1008 left a comment

Choose a reason for hiding this comment

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

Nice work, some things around formatting and minor nits 👍

zephyr_library()
zephyr_library_property(ALLOW_EMPTY TRUE)

zephyr_library_sources_ifdef(CONFIG_A4979_STEPPER a4979.c)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check you editor settings, there should be a new line at the end of file.


comment "Allegro Stepper Drivers"

rsource "Kconfig.a4979"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add a zephyr-keep-sorted directive?

*
* This structure contains all of the devicetree specifications for the pins
* needed by a given A4979 stepper driver.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Usually we only add doxygen comments for public facing headers. Internal implementation files should not have them.

data->enabled = enable;
if (!enable) {
config->common.timing_source->stop(dev);
ret = gpio_pin_set_dt(&config->common.step_pin, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a benefit to setting the step pin explicitly?

enum stepper_micro_step_resolution *micro_step_res)
{
struct a4979_data *data = dev->data;
*micro_step_res = data->micro_step_res;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Compliance check probably wants some new lines here.

}

/* Configure microstep pin 0 */
ret = gpio_pin_configure_dt(&config->m0_pin, GPIO_OUTPUT_INACTIVE);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess you should check the gpio_is_ready_dt there also before trying to configure.

\
DEVICE_DT_INST_DEFINE(inst, a4979_init, NULL, &a4979_data_##inst, \
&a4979_config_##inst, POST_KERNEL, \
CONFIG_STEPPER_INIT_PRIORITY, &a4979_stepper_api);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check the formatting of the macro, some lines are too long. clang-format usually gets you 90% of the way there but I guess in some cases it fails for our macrobatics :^)

- counter

properties:

Copy link
Collaborator

Choose a reason for hiding this comment

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

Drop the empty line.

compatible: "allegro,a4979"

include:
#- name: spi-device.yaml
Copy link
Collaborator

Choose a reason for hiding this comment

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

Leftover :^) ?

Copy link
Member

@jilaypandya jilaypandya left a comment

Choose a reason for hiding this comment

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

Thanks @verenascst for the contribution :-) Try running
python scripts/ci/check_compliance.py after you have committed your changes locally and it should report all the whitespacing & other compliance errors :-)

# SPDX-FileCopyrightText: Copyright (c) 2025 Carl Zeiss Meditec AG
# SPDX-License-Identifier: Apache-2.0

config STEPPER_ALLEGRO
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
config STEPPER_ALLEGRO
menuconfig STEPPER_ALLEGRO

# SPDX-License-Identifier: Apache-2.0

config A4979_STEPPER
bool "Activate driver for A4979 stepper motor driver"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bool "Activate driver for A4979 stepper motor driver"
bool "Activate allegro A4979 stepper driver"

default y
depends on DT_HAS_ALLEGRO_A4979_ENABLED
select STEP_DIR_STEPPER
select STEPPER_STEP_DIR_GENERATE_ISR_SAFE_EVENTS
Copy link
Member

Choose a reason for hiding this comment

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

User should be able to select this :)

Suggested change
select STEPPER_STEP_DIR_GENERATE_ISR_SAFE_EVENTS

#include "../step_dir/step_dir_stepper_common.h"

#include <zephyr/logging/log.h>

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

*
* This structure contains mutable data used by a A4979 stepper driver.
*/
struct a4979_data {
Copy link
Member

Choose a reason for hiding this comment

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

Same as what @faxe1008 mentioned above :)

@@ -0,0 +1,46 @@
description: |
Copy link
Member

Choose a reason for hiding this comment

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

The spacing needs to be adjusted over here a bit :)

tmc2209 is a good example.
https://docs.zephyrproject.org/latest/build/dts/api/bindings/stepper/adi/adi%2Ctmc2209.html

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