-
Notifications
You must be signed in to change notification settings - Fork 7.4k
drivers: stepper: Stepper driver architectural refactoring #90748
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
base: main
Are you sure you want to change the base?
drivers: stepper: Stepper driver architectural refactoring #90748
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool :)
LOG_ERR("Failed to start timing source: %d", ret); | ||
} | ||
} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reduce the nesting with early return :)
return (uint32_t)x; | ||
} | ||
|
||
static uint64_t avr446_start_interval(const uint32_t acceleration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for these functions to have the avr446
prefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an internal function which is implementing part of the AVR446 algorithm.
|
||
# zephyr-keep-sorted-start | ||
add_subdirectory(motion_controller) | ||
add_subdirectory(interface) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_subdirectory(interface) | |
add_subdirectory(step_dir_interface) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually i thought this folder could later include multiple different stepper interfaces (like e.g. h-bridge etc). Do we want to have each one in its own folder?
*/ | ||
typedef int (*stepper_set_microstep_interval_t)(const struct device *dev, | ||
const uint64_t microstep_interval_ns); | ||
typedef int (*stepper_set_ramp_t)(const struct device *dev, struct stepper_ramp_base *ramp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this scale up for setting ramp for tmc drivers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it could yes but i am not sure if we really want to handle hardware ramp of trinamic under stepper.h API or deal with it like with any other vendor specific API over e.g. stepper_trinamic.h
. this is definitely something to be discussed
drivers/stepper/stepper_common.h
Outdated
*/ | ||
stepper_enable_t enable; | ||
/** | ||
* @brief Represents a point in a 2D Cartesian coordinate system. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation is off
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will rewrite it. thx
drivers/stepper/adi_tmc/tmc22xx.c
Outdated
STEPPER_MOTION_CONTROLLER_DT_INST_DEFINE(inst, &motion_controller_callbacks) \ | ||
STEPPER_INTERFACE_STEP_DIR_DT_INST_DEFINE(inst) \ | ||
static const struct stepper_common_config common_cfg_##inst = { \ | ||
.motion_controller = STEPPER_MOTION_CONTROLLER_DT_INST_GET(inst), \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you have a look at the compliance checks over here, Lot of noise is being created from the GitHub actions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah compliance checks are my next goal
cd2e18e
to
fba3e91
Compare
drivers/stepper/adi_tmc/tmc22xx.c
Outdated
static const struct gpio_dt_spec tmc22xx_stepper_msx_pins_##inst[] = { \ | ||
DT_INST_FOREACH_PROP_ELEM_SEP( \ | ||
inst, msx_gpios, GPIO_DT_SPEC_GET_BY_IDX, (,) \ | ||
), \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to reduce some noise in this File, could we revert the changes related to msx_gpios, so that it's directly visible that motion_controller and interface are getting added. I see the IF_ENABLED and BUILD_ASSERT macros in relation to msx_gpios have been shifted around, but keeping them where they where would make the git diff a bit more pleasant :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ramp_constant is a bit ambiguous i think. Alternative name might be stepper_constant_speed.c .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like personally like how the various phases of a ramp are based on the steps in a particular ramp phase.
*/ | ||
int stepper_motion_controller_is_moving(const struct device *dev, bool *is_moving); | ||
|
||
int stepper_motion_controller_set_ramp(const struct device *dev, struct stepper_ramp_base *ramp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing documentation
@@ -0,0 +1,129 @@ | |||
/* | |||
* SPDX-FileCopyrightText: Copyright (c) 2024 Fabian Blatz <fabianblatz@gmail.com> | |||
* Copyright (c) 2025 Andre Stefanov <mail@andrestefanov.de> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Copyright (c) 2025 Andre Stefanov <mail@andrestefanov.de> | |
* SPDX-FileCopyrightText: Copyright (c) 2025 Andre Stefanov <mail@andrestefanov.de> |
@@ -0,0 +1,104 @@ | |||
/* | |||
* SPDX-FileCopyrightText: Copyright (c) 2024 Fabian Blatz <fabianblatz@gmail.com> | |||
* 2025 Andre Stefanov <mail@andrestefanov.de> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 2025 Andre Stefanov <mail@andrestefanov.de> | |
* SPDX-FileCopyrightText: 2025 Andre Stefanov <mail@andrestefanov.de> |
23dbd4a
to
9b4aebc
Compare
Introduced modular architecture to the stepper driver to allow usage of different software and hardware components during stepper motion. Signed-off-by: Andre Stefanov <mail@andrestefanov.de>
9b4aebc
to
b1e1959
Compare
|
Introduction
Problem description
The current stepper motor driver implementation lacks a standardized and flexible API architecture that can accommodate different stepper motor types, control methods, and motion profiles. This makes it difficult to implement advanced features like ramping (acceleration/deceleration profiles) and to cleanly separate the hardware abstraction from the motion control logic.
Proposed change
Refactor the stepper driver API to create a modular, extensible architecture that separates core functionality from implementation details. This includes creating a clear hierarchy of components: generic stepper interface, timing source, motion controller, and ramp profile abstractions. The architecture will allow for plug-and-play ramp profiles and consistent interfaces across different stepper driver implementations.
Detailed RFC
Proposed change (Detailed)
The refactored stepper API architecture introduces a layered design with three key architectural elements:
Timing Source Layer
Motion Controller Layer
Ramp Profile Layer
Hardware access Layer
stepper_common
or other internal componentsThis architecture separates concerns clearly:
Dependencies
This change affects:
The core Zephyr kernel and other subsystems are not affected as this is contained within the driver layer.
Concerns and Unresolved Questions
The chosen layered approach provides a good balance of flexibility, code reuse, and standardization. By separating the timing source, motion control, and ramp profile concerns, we enable future extensions without major API changes, while providing a consistent experience for application developers across different stepper motor implementations.
Currentl PoC was tested with
samples/drivers/stepper/generic
by usingTMC2209
and anucleo_f446re
.