Skip to content

Add sanity check for MAXIMUM_STEPPER_RATE #27764

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

Merged

Conversation

AndreySamokhin
Copy link
Contributor

Description

It was observed that when the actual stepper motor rate (calculated from DEFAULT_AXIS_STEPS_PER_UNIT and DEFAULT_MAX_FEEDRATE) exceeds hardware limitations (i.e., MAXIMUM_STEPPER_RATE), unpredictable behavior occurs (#27496).

Several lines of code were added to SanityCheck.h to trigger a compile-time error in such cases.

Example

Use extreme values for DEFAULT_MAX_FEEDRATE to trigger a compile-time error.

  #define DEFAULT_MAX_FEEDRATE          { 300, 30000, 5, 25 }
error: static assertion failed: For the Y axis, the maximum stepper rate calculated from DEFAULT_AXIS_STEPS_PER_UNIT and DEFAULT_MAX_FEEDRATE exceeds 500000 (i.e., MAXIMUM_STEPPER_RATE).

Requirements

No specific hardware components are required.

Benefits

This change ensures a compile-time error occurs instead of the unpredictable behavior that might occur otherwise.

Configurations

This applies to all configurations where MAXIMUM_STEPPER_RATE is defined.

Related Issues

#27496

@thisiskeithb thisiskeithb linked an issue Mar 31, 2025 that may be closed by this pull request
1 task
@thinkyhead thinkyhead force-pushed the pr/tb6560-driver-issue branch from e14293d to 29cee68 Compare April 1, 2025 03:35
@thinkyhead thinkyhead force-pushed the pr/tb6560-driver-issue branch from 282e286 to 35a455a Compare April 1, 2025 04:38
@AndreySamokhin
Copy link
Contributor Author

Build Test (LPC1769) (.../examples/Azteeg/X5GT) failed with error: static assertion failed: Slow down! DEFAULT_MAX_FEEDRATE[X] * DEFAULT_AXIS_STEPS_PER_UNIT[X] > MAXIMUM_STEPPER_RATE (15000). I do not understand why MAXIMUM_STEPPER_RATE is set to 15000, it should be 50000. I compiled it locally without errors.

@ellensp
Copy link
Contributor

ellensp commented Apr 3, 2025

Build Test (LPC1769) (.../examples/Azteeg/X5GT) failed with error: static assertion failed: Slow down! DEFAULT_MAX_FEEDRATE[X] * DEFAULT_AXIS_STEPS_PER_UNIT[X] > MAXIMUM_STEPPER_RATE (15000). I do not understand why MAXIMUM_STEPPER_RATE is set to 15000, it should be 50000. I compiled it locally without errors.

The currently failing test is ["Test LPC1769] Cohesion3D Remix DELTA | ABL Bilinear | EEPROM | Sensorless Homing/Probing | I Axis..."

example has "#define I_DRIVER_TYPE TB6560" so it gets set to the slowest driver

  #if HAS_DRIVER(TB6560)
    #define MAXIMUM_STEPPER_RATE 15000

This is set as part of the test https://github.com/MarlinFirmware/Marlin/blob/bugfix-2.1.x/buildroot/tests/LPC1769#L47

as is

        DEFAULT_AXIS_STEPS_PER_UNIT '{ 80, 80, 400, 500, 80 }' \
        DEFAULT_MAX_FEEDRATE '{ 300, 300, 5, 25, 300 }' \
X:  80*300 = 24000 Fail   
Y:  80*300 = 24000 Fail
Z:  400*5  = 2000  Pass
I:  500*25 = 12500 Pass
E:  80*300 = 24000 Fail

If you update the test file buildroot/tests/LPC1769 lines 48-49 with valid values, this test will pass

@AndreySamokhin
Copy link
Contributor Author

@ellensp, thank you for the clarification! Initially I mistakenly thought that considering all configurations from Configurations/config/examples/ would be enough. Now I see that all scripts from Marlin/buildroot/tests/ should also be taken into account.

@thinkyhead thinkyhead merged commit 6984c7f into MarlinFirmware:bugfix-2.1.x Apr 7, 2025
65 checks passed
EvilGremlin pushed a commit to EvilGremlin/Marlin that referenced this pull request May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Rebooting while homing
3 participants