MarlinFirmware / Marlin

Marlin is an optimized firmware for RepRap 3D printers based on the Arduino platform. Many commercial 3D printers come with Marlin installed. Check with your vendor if you need source code for your specific machine.
https://marlinfw.org
GNU General Public License v3.0
16.03k stars 19.12k forks source link

[BUG] millis usage is not overflow proof. May cause issues when run continously more than 50days. #26545

Closed TBAMax closed 6 months ago

TBAMax commented 6 months ago

Did you test the latest bugfix-2.1.x code?

Yes, and the problem still exists.

Bug Description

I did a little code analysis, trying to familiarize myself with Marlin code. Noticed that the default time comparison style has not been compensated for the known best practices for using millis() and micros () timing. This will cause issues when the timer counter overflows (for millis after 40days, for micros after 70minutes() ). This is a known trap for young players. For detailed information see the very well written detailed explanation here:https://www.norwegiancreations.com/2018/10/arduino-tutorial-avoiding-the-overflow-issue-when-using-millis-and-micros/

As the issue is somewhat hidden behind the "macro magic" in the Marlins case so it took some more time to analyse. This is also some of the reason why I decided to share this info here, to spare some work for somebody else.

The easy initial solution to solve this would be to just edit the coding standards regarding the issue(https://marlinfw.org/docs/development/coding_standards.html#time-comparison). How to alter the "macro magic" I do not have any suggestions. I would suggest to keep it easy and just use the plain Arduino style without the macro magic.

All best Regards

Bug Timeline

native

Expected behavior

No response

Actual behavior

No response

Steps to Reproduce

No response

Version of Marlin Firmware

bugfix 2.1.x

Printer model

No response

Electronics

No response

LCD/Controller

No response

Other add-ons

No response

Bed Leveling

None

Your Slicer

None

Host Software

None

Don't forget to include

Additional information & file uploads

No response

thinkyhead commented 6 months ago

Discussion at PR.

github-actions[bot] commented 4 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.