-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
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
[BUG] SysTick_Callback
interferes with timing critical code - causes speed jitter - LPC176x
#27115
Comments
I believe @p3p was on vacation so we likely wont hear something until next week. |
Greetings from the Marlin AutoBot! Disclaimer: This is an open community project with lots of activity and limited |
This needs looking into |
We're waiting on #27131 to get merged. |
Did you test the latest
bugfix-2.1.x
code?Yes, and the problem still exists.
Bug Description
SysTick_Callback()
should not be used as doing so causes timing jitter for all interrupts.SysTick_Callback()
is an api from thepio-framework-arduino-lpc176x
.Here's the relevant section from
pio-framework-arduino-lpc176x/cores/arduino/main.cpp
:0
is the highest priority level which meansSysTick_Handler
is going to run regardless of anyone. This would be absolutely fine if it was just incrementing_millis
. But it's not.SysTick_Callback()
running as part of SysTick_IRQn and at the highest possible priority puts it ahead of every other interrupt: stepper isr, uart, serial, pwm, watchdog, you name it. And it runs every millisecond.The main problematic
SysTick_Callback()
is fromMarlin/src/HAL/LPC1768/HAL.cpp
:Where
disk_timerproc()
is actually fromframework-arduino-lpc176x/system/CMSIS/lib/chanfs/mmc_ssp.c
.Issue
A logic analyzer capture of step/dir pins best shows the issue:
![jitter](https://private-user-images.githubusercontent.com/299015/332455226-7ff7fdea-1451-43f4-a5ca-3e7e13fccb70.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU1NjU0MzMsIm5iZiI6MTcyNTU2NTEzMywicGF0aCI6Ii8yOTkwMTUvMzMyNDU1MjI2LTdmZjdmZGVhLTE0NTEtNDNmNC1hNWNhLTNlN2UxM2ZjY2I3MC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTA1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkwNVQxOTM4NTNaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0yNDhmZmZlMmFmMTlmZGMyYjgyZmFlMDE0YjMxZWJkYmU1OWZmODRkZDZmZmY1MzA1MjY5ZGE4YWViZDRkZWM4JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.ztO-Pri8RxwPhGP8hicc8MBDTLbIU9x-conMS-cQjgc)
(Note in this capture the stepper isr was at the priority
0
)You can see speed jitter equivalent to 6000mm/s^2 or more throughout, even at a somewhat leisurely 100mm/s movement speed. In my testing, I've disabled all features I could think of incl. lcd and watchdog and increased the stepper isr priority to highest (
0
), but still jitter.Root cause
To confirm that it's
![jitter_no](https://private-user-images.githubusercontent.com/299015/332457673-07620e2f-8391-42ee-a270-e2bd8461e998.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU1NjU0MzMsIm5iZiI6MTcyNTU2NTEzMywicGF0aCI6Ii8yOTkwMTUvMzMyNDU3NjczLTA3NjIwZTJmLTgzOTEtNDJlZS1hMjcwLWUyYmQ4NDYxZTk5OC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTA1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkwNVQxOTM4NTNaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT00NTY3ZjRmMjZiMDg1NTgzMDBkOGE5NjFlMzczOTUwMjFiZmMxNGU4Yjc5MzllZDM4Mzg4OGM3ZmE2YmQxOTY5JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.3fFXhaU1e8avAlKabcwu7ChpRjBJ977ciF_KPZ8kx9s)
SysTick_Callback()
I've commented it out completely, including definition and use. This is the result:(Note in this capture the stepper isr was at the priority
0
)The slightly strange part is that without the
disk_timerproc();
call, reading from/writing to SD card still seems to work. So It's definitely not crucial. Is it even needed? Every ms? / When is it needed?One more
Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp
(unused in my build) also defines aSysTick_Callback()
.pio-framework-arduino-lpc176x
I've also opened pio-framework-arduino-lpc176x/issues/49.
Impact
It makes ADAPTIVE_STEP_SMOOTHING seem lees effective. ADAPTIVE_STEP_SMOOTHING reduces a larger source of speed jitter, namely bresenham aliasing for the minor axes.
It may interfere with communication like serial and spi, depending on timing sensitivity or implementation.
Bug Timeline
Old issue, maybe 2019. Git blame points to
SysTick_Callback
added in 60cb36b "(grafted)"Expected behavior
No significant isr jitter.
Actual behavior
Interrupt jitter.
Steps to Reproduce
Run this simple/X-axis only gcode and look at the step/dir pins with a logic analyzer (at >=12Mhz sample rate).
Version of Marlin Firmware
Last sync: 06762db [cron] Bump distribution date (2024-05-18)
Printer model
Customized Ender-3
Electronics
SKR v1.4 Turbo but all LPC176x are affected
LCD/Controller
No response
Other add-ons
No response
Bed Leveling
None
Your Slicer
None
Host Software
SD Card (headless)
Don't forget to include
Configuration.h
andConfiguration_adv.h
.Additional information & file uploads
(In lieu of configuration zip file I've root caused to specific lines of code.)
The text was updated successfully, but these errors were encountered: