-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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.
+4,578
−3,951
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
422467a
doc: update stepper documentation to address the split
jilaypandya 5dbbdd7
drivers: stepper: split stepper api
jilaypandya a02f4d9
drivers: stepper: refactor gpio based stepper drivers
jilaypandya 1fa9874
tests: stepper_api: test motion control apis
jilaypandya 59d9a8e
drivers: stepper: shell: refactor to address the split
jilaypandya 961a67b
drivers: stepper: tmc5xxx: use mfd approach
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
48 changes: 48 additions & 0 deletions
48
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,48 @@ | ||
| .. _stepper-individual-controller-driver: | ||
|
|
||
| Individual Stepper Motion Controller and Driver | ||
| ############################################### | ||
|
|
||
| A motion control driver implements ``stepper`` API, for instance, :dtcompatible:`zephyr,gpio-step-dir-controller` | ||
| and a hardware driver implements ``stepper_drv`` API, for instance, :dtcompatible:`adi,tmc2209`. | ||
|
|
||
| Following is an example of a device tree configuration for a stepper driver with a dedicated stepper motion | ||
| controller: | ||
|
|
||
| .. code-block:: dts | ||
|
|
||
| / { | ||
| aliases { | ||
| stepper_drv = &tmc2209 | ||
| stepper = &step_dir_motion_control; | ||
| }; | ||
|
|
||
| /* DEVICE_API: stepper_drv api */ | ||
| tmc2209: tmc2209 { | ||
| compatible = "adi,tmc2209"; | ||
| enable-gpios = <&gpioa 6 GPIO_ACTIVE_HIGH>; | ||
| msx-gpios = <&gpiob 0 GPIO_ACTIVE_HIGH>, <&gpioa 7 GPIO_ACTIVE_HIGH>; | ||
| }; | ||
|
|
||
| /* DEVICE_API: stepper api */ | ||
| step_dir_motion_control: step_dir_motion_control { | ||
| compatible = "zephyr,gpio-step-dir-controller"; | ||
| step-gpios = <&gpioa 9 GPIO_ACTIVE_HIGH>; | ||
| dir-gpios = <&gpioc 7 GPIO_ACTIVE_HIGH>; | ||
| invert-direction; | ||
| dual-edge-step; | ||
| step-width-ns = <1000>; | ||
| }; | ||
| }; | ||
|
|
||
| Following the aforementioned configurations, the stepper driver subsystem can be used in the application code | ||
| as follows: | ||
|
|
||
| .. code-block:: c | ||
|
|
||
| static const struct device *stepper = DEVICE_DT_GET(DT_ALIAS(stepper)); | ||
| static const struct device *stepper_drv = DEVICE_DT_GET(DT_ALIAS(stepper_drv)); | ||
| ... | ||
| stepper_move_to(stepper, 200); | ||
| stepper_stop(stepper); | ||
| stepper_drv_disable(stepper_drv); |
90 changes: 90 additions & 0 deletions
90
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,90 @@ | ||
| .. _stepper-integrated-controller-driver: | ||
|
|
||
| Integrated Stepper Motion Control and Driver | ||
| ############################################ | ||
|
|
||
| Devices which comprise of both motion controller and a stepper driver in a single IC. These devices | ||
| have to be modelled as multi-functional-device in device tree, implementing both ``stepper`` and | ||
| ``stepper_drv`` APIs. An example of such a device is :dtcompatible:`adi,tmc50xx`. ``stepper`` API is | ||
| implemented by :dtcompatible:`adi,tmc50xx-motion-controller` and ``stepper_drv`` API is implemented by | ||
| :dtcompatible:`adi,tmc50xx-stepper-driver`. | ||
|
|
||
| .. code-block:: dts | ||
|
|
||
| / { | ||
| aliases { | ||
| x_axis_stepper_motor = &tmc50xx_0_motion_controller; | ||
| y_axis_stepper_motor = &tmc50xx_1_motion_controller; | ||
| x_axis_stepper_driver = &tmc50xx_0_stepper_driver; | ||
| y_axis_stepper_driver = &tmc50xx_1_stepper_driver; | ||
| }; | ||
| }; | ||
|
|
||
| &spi0 { | ||
| /* SPI bus options here, not shown */ | ||
|
|
||
| /* Dual controller/driver for up to two 2-phase bipolar stepper motors */ | ||
| tmc50xx: tmc50xx@0 { | ||
| compatible = "adi,tmc50xx"; | ||
| reg = <0>; | ||
| spi-max-frequency = <DT_FREQ_M(8)>; /* Maximum SPI bus frequency */ | ||
|
|
||
| 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 */ | ||
| tmc50xx_0_stepper_driver: tmc50xx_0_stepper_driver { | ||
| idx = <0>; | ||
| compatible = "adi,tmc50xx-stepper-driver"; | ||
| micro-step-res = <256>; | ||
| /* ADI TMC stallguard settings specific to TMC50XX */ | ||
| stallguard2-threshold=<30>; | ||
| }; | ||
|
|
||
| /* DEVICE_API: stepper api */ | ||
| tmc50xx_0_motion_controller: tmc50xx_0_motion_controller { | ||
| idx = <0>; | ||
| compatible = "adi,tmc50xx-motion-controller"; | ||
| ... | ||
| vmax = <900000>; | ||
| amax = <50000>; | ||
| ... | ||
| activate-stallguard2; | ||
| ... | ||
| }; | ||
|
|
||
| /* DEVICE_API: stepper_drv api */ | ||
| tmc50xx_1_stepper_driver: tmc50xx_1_stepper_driver { | ||
| idx = <1>; | ||
| compatible = "adi,tmc50xx-stepper-driver"; | ||
| micro-step-res = <256>; | ||
| /* ADI TMC stallguard settings specific to TMC50XX */ | ||
| stallguard2-threshold=<30>; | ||
| }; | ||
|
|
||
| /* DEVICE_API: stepper api */ | ||
| tmc50xx_1_motion_controller: tmc50xx_1_motion_controller { | ||
| idx = <1>; | ||
| compatible = "adi,tmc50xx-motion-controller"; | ||
| ... | ||
| vstart = <1000>; | ||
| ... | ||
| stallguard-threshold-velocity=<200000>; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| Following the aforementioned configurations, the stepper driver subsystem can be used in the application code | ||
| as follows: | ||
|
|
||
| .. code-block:: c | ||
|
|
||
| static const struct device *x_stepper = DEVICE_DT_GET(DT_ALIAS(x_axis_stepper_motor)); | ||
| static const struct device *x_stepper_drv = DEVICE_DT_GET(DT_ALIAS(x_axis_stepper_driver)); | ||
| static const struct device *y_stepper = DEVICE_DT_GET(DT_ALIAS(y_axis_stepper_motor)); | ||
| static const struct device *y_stepper_drv = DEVICE_DT_GET(DT_ALIAS(y_axis_stepper_driver)); | ||
| ... | ||
| stepper_move_to(x_stepper, 200); | ||
| stepper_stop(x_stepper); | ||
| stepper_drv_disable(x_stepper_drv); | ||
| stepper_drv_disable(y_stepper_drv); |
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 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
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,4 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025 Jilay Sandeep Pandya | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| zephyr_library_include_directories(include) |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
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.