-
Notifications
You must be signed in to change notification settings - Fork 7.7k
drivers: stepper: introduce stepper_drv api to facilitate implementing motion controllers as device drivers #91979
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
Open
jilaypandya
wants to merge
6
commits into
zephyrproject-rtos:main
Choose a base branch
from
jilaypandya:feature/introduce-step-dir-functions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,599
−1,767
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
022f16d
drivers: stepper: introduce stepper_drv api
jilaypandya e5a04e9
drivers: stepper: deprecate stepper_drv functions from stepper_api
jilaypandya 7fb6aa2
drivers: stepper: shell: add stepper index selection functionality
jilaypandya 848fa13
drivers: stepper: introduce event cb mechanism for stepper_drv
jilaypandya 91ab71c
drivers: stepper: change namespacing for stepper_micro_step_resolution
jilaypandya 5e20474
doc: add class diagram for stepper driver subsystem
jilaypandya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
doc/hardware/peripherals/stepper/individual_controller_driver.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
.. _stepper-individual-controller-driver: | ||
|
||
Individual Stepper Motion Controller and Driver | ||
############################################### | ||
|
||
A motion control driver implements ``stepper`` API, for instance, :dtcompatible:`zephyr,stepper-motion-control` | ||
and a hardware driver implements ``stepper_drv`` API, for instance, :dtcompatible:`ti,drv84xx` or | ||
:dtcompatible:`zephyr,h-bridge-stepper`. | ||
|
||
Following is an example of a device tree configuration for a stepper driver with a dedicated stepper motion | ||
controller: | ||
|
||
.. code-block:: dts | ||
|
||
/ { | ||
aliases { | ||
x_axis_stepper_motion_controller = &stepper_motion_control; | ||
x_axis_stepper_driver = &drv8424; | ||
}; | ||
}; | ||
|
||
/* DEVICE_API: stepper_drv api */ | ||
drv8424: drv8424 { | ||
status = "okay"; | ||
compatible = "ti,drv84xx"; | ||
|
||
dir-gpios = <&gpio1 0 GPIO_ACTIVE_LOW>; | ||
step-gpios = <&gpio2 1 GPIO_ACTIVE_LOW>; | ||
sleep-gpios = <&gpio3 0 GPIO_ACTIVE_LOW>; | ||
en-gpios = <&gpio4 1 GPIO_ACTIVE_LOW>; | ||
m0-gpios = <&gpio5 0 GPIO_ACTIVE_LOW>; | ||
m1-gpios = <&gpio6 1 GPIO_ACTIVE_LOW>; | ||
}; | ||
|
||
/* DEVICE_API: stepper api */ | ||
stepper_motion_control: stepper_motion_control { | ||
compatible = "zephyr,stepper-motion-control"; | ||
status = "okay"; | ||
counter = <&counter0>; | ||
stepper = <&drv8424>; | ||
}; | ||
|
||
All the stepper api functions need a stepper motor index, since a stepper motion controller can control | ||
multiple motors. However, this can be configured via application specific Kconfig to use a specific index, | ||
for instance, :kconfig:option-regex:`CONFIG_STEPPER_AXIS_*`. | ||
|
||
Following the aforementioned configurations, the stepper driver subsystem can be used in the application code | ||
as follows: | ||
|
||
.. code-block:: c | ||
|
||
/* Configure the index of motor and respective axis via Kconfig */ | ||
stepper_move_to(x_axis_stepper_motion_controller, CONFIG_STEPPER_AXIS_X_*, 200); | ||
stepper_stop(x_axis_stepper_motion_controller, CONFIG_STEPPER_AXIS_X_*); | ||
stepper_drv_disable(x_axis_stepper_driver); |
86 changes: 86 additions & 0 deletions
86
doc/hardware/peripherals/stepper/integrated_controller_driver.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
.. _stepper-integrated-controller-driver: | ||
|
||
Integrated Stepper Motion Control and Driver | ||
############################################ | ||
|
||
Implements both ``stepper`` and ``stepper_drv`` APIs in a single driver. For instance, :dtcompatible:`adi,tmc50xx`. | ||
|
||
Following is an example of a device tree configuration for a stepper driver with integrated motion control: | ||
|
||
.. code-block:: dts | ||
|
||
/ { | ||
aliases { | ||
x_y_stepper_motion_controller = &tmc50xx; | ||
x_axis_stepper_driver = &motor_x; | ||
y_axis_stepper_driver = &motor_y; | ||
}; | ||
}; | ||
|
||
&spi0 { | ||
/* SPI bus options here, not shown */ | ||
|
||
/* Dual controller/driver for up to two 2-phase bipolar stepper motors */ | ||
/* DEVICE_API: stepper api */ | ||
tmc50xx: tmc50xx@0 { | ||
compatible = "adi,tmc50xx"; | ||
reg = <0>; | ||
spi-max-frequency = <DT_FREQ_M(8)>; /* Maximum SPI bus frequency */ | ||
|
||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
|
||
poscmp-enable; test-mode; lock-gconf; /* ADI TMC Global configuration flags */ | ||
clock-frequency = <DT_FREQ_M(16)>; /* Internal/External Clock frequency */ | ||
|
||
/* DEVICE_API: stepper_drv api */ | ||
motor_x: motor@0 { | ||
status = "okay"; | ||
reg = <0>; | ||
|
||
/* common stepper controller settings */ | ||
invert-direction; | ||
micro-step-res = <256>; | ||
|
||
/* ADI TMC stallguard settings specific to TMC50XX */ | ||
activate-stallguard2; | ||
..................... | ||
|
||
/* ADI TMC ramp generator as well as current settings */ | ||
vstart = <10>; | ||
.............. | ||
}; | ||
|
||
/* DEVICE_API: stepper_drv api */ | ||
motor_y: motor@1 { | ||
status = "okay"; | ||
reg = <1>; | ||
|
||
/* common stepper controller settings */ | ||
micro-step-res = <256>; | ||
|
||
/* ADI TMC stallguard settings specific to TMC50XX */ | ||
activate-stallguard2; | ||
..................... | ||
|
||
/* ADI TMC ramp generator as well as current settings */ | ||
vstart = <10>; | ||
.............. | ||
}; | ||
}; | ||
}; | ||
|
||
All the stepper api functions need a stepper motor index, since a stepper motion controller can control | ||
multiple motors. However, this can be configured via application specific Kconfig to use a specific index, | ||
for instance, :kconfig:option-regex:`CONFIG_STEPPER_AXIS_*`. | ||
|
||
Following the aforementioned configurations, the stepper driver subsystem can be used in the application code | ||
as follows: | ||
|
||
.. code-block:: c | ||
|
||
/* Configure the index of motor and respective axis via Kconfig */ | ||
stepper_move_to(x_y_stepper_motion_controller, CONFIG_STEPPER_AXIS_X_*, 200); | ||
stepper_stop(x_y_stepper_motion_controller, CONFIG_STEPPER_AXIS_Y_*); | ||
stepper_drv_disable(x_axis_stepper_driver); | ||
stepper_drv_disable(y_axis_stepper_driver); |
Binary file added
BIN
+242 KB
doc/hardware/peripherals/stepper/stepper_driver_subsystem_class_diagram.webp
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2025 Jilay Sandeep Pandya | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config ZEPHYR_STEPPER_MOTION_CONTROL | ||
bool "Zephyr CPU based Stepper motion control" | ||
depends on DT_HAS_ZEPHYR_STEPPER_MOTION_CONTROL_ENABLED | ||
select STEPPER_TIMING_SOURCES | ||
default y | ||
|
||
config ZEPHYR_STEPPER_MOTION_CONTROL_GENERATE_ISR_SAFE_EVENTS | ||
bool "Guarantee non ISR callbacks upon stepper events" | ||
help | ||
Enable the dispatch of stepper generated events via | ||
a message queue to guarantee that the event handler | ||
code is not run inside of an ISR. Can be disabled, but | ||
then registered stepper event callback must be ISR safe. | ||
|
||
config ZEPHYR_STEPPER_MOTION_CONTROL_EVENT_QUEUE_LEN | ||
int "Maximum number of pending stepper events" | ||
default 4 | ||
depends on ZEPHYR_STEPPER_MOTION_CONTROL_GENERATE_ISR_SAFE_EVENTS | ||
help | ||
The maximum number of stepper events that can be pending before new events | ||
are dropped. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.