Skip to content

Stepper: Callbacks not called when not using a dedicated timer #88821

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
jbr7rr opened this issue Apr 19, 2025 · 2 comments · May be fixed by #88835
Open

Stepper: Callbacks not called when not using a dedicated timer #88821

jbr7rr opened this issue Apr 19, 2025 · 2 comments · May be fixed by #88835
Assignees
Labels
area: Stepper bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@jbr7rr
Copy link

jbr7rr commented Apr 19, 2025

Describe the bug

When using the stepper API for DRV84xx (and possible others) without the use of a dedicated timer, the callback is not called when the stepper motor has finished turning

To Reproduce

In file tests/drivers/stepper/drv84xx/api/boards/native_sim.overlay
Remove or comment out the following line:

		// counter = <&counter0>;

Run the test:

west twister -T tests/drivers/stepper/drv84xx/api/ 

The test will fail on the callbacks

Expected behavior

Callbacks called in the same manner as when using a dedicated timer.

Impact

ESP32 does not have a suitable timer for the stepper API, so on that platform there is no way to make the stepper motor work with the current API

Logs and console output

handler.log

Environment (please complete the following information):

  • OS: (e.g. Linux, MacOS, Windows)
  • Toolchain (e.g Zephyr SDK, ...)
  • Commit SHA or Version used

OS: Manjaro
Toolchain: Zephyr SDK
Main branch @ 0648e49

Additional context

@jbr7rr jbr7rr added the bug The issue is a bug, or the PR is fixing a bug label Apr 19, 2025
@jilaypandya
Copy link
Member

jilaypandya commented Apr 19, 2025

ESP32 does not have a suitable timer for the stepper API, so on that platform there is no way to make the stepper motor work with the current API

there is an alternative work_q based approach which is already part of the driver subsystem, it should be used per default if counter is not used.
We will look further into it.

Ping @faxe1008

@jilaypandya jilaypandya added the priority: low Low impact/importance bug label Apr 19, 2025
@jbr7rr
Copy link
Author

jbr7rr commented Apr 20, 2025

there is an alternative work_q based approach which is already part of the driver subsystem, it should be used per default if counter is not used. We will look further into it.

Yeah, but when using the work_q based approach the callback doesn't get called, I had a look and there is a problem that the work does not get rescheduled.

This fixes the issue:

diff --git a/drivers/stepper/step_dir/step_dir_stepper_common.c b/drivers/stepper/step_dir/step_dir_stepper_common.c
index bd4eac4b996..b6b7566f07f 100644
--- a/drivers/stepper/step_dir/step_dir_stepper_common.c
+++ b/drivers/stepper/step_dir/step_dir_stepper_common.c
@@ -145,11 +145,11 @@ static void position_mode_task(const struct device *dev)
 		(void)step_dir_stepper_perform_step(dev);
 	}
 
-	update_remaining_steps(dev->data);
-
 	if (config->timing_source->needs_reschedule(dev) && data->step_count != 0) {
 		(void)config->timing_source->start(dev);
 	}
+
+	update_remaining_steps(dev->data);
 }
 
 static void velocity_mode_task(const struct device *dev)

I'll try to write a proper PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Stepper bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants