-
-
Notifications
You must be signed in to change notification settings - Fork 100
Open
Labels
topic: codeRelated to content of the project itselfRelated to content of the project itselftype: imperfectionPerceived defect in any part of projectPerceived defect in any part of project
Description
Reading the source code for the renesas core, I find in time.cpp:
__attribute__((weak)) void delay(uint32_t ms)
{
auto const start = millis();
auto const stop = start + ms;
while(millis() < stop) yield();
}
That's exactly the way we're taught NOT to implement delay, and it doesn't handle the wrap of millis() corrected (ie when start+ms is larger than 32bits, and thus stop will be truncated and millis() will immediately be greater than stop.)
(Also, this code has the "delay might be up to just less than 1ms shorter than expected, because of the quantization of millis(). This was fixed for AVR quite some time ago by having the loop check micros...)
Additional context
Related discussion:
https://forum.arduino.cc/t/r4-delay-does-not-properly-handle-millis-wrap-around/1416399
Metadata
Metadata
Assignees
Labels
topic: codeRelated to content of the project itselfRelated to content of the project itselftype: imperfectionPerceived defect in any part of projectPerceived defect in any part of project