-
Notifications
You must be signed in to change notification settings - Fork 7.6k
delay() with small values (e.g. delay(5)) does not delay if system HZ (CONFIG_FREERTOS_HZ) <1000 #6946
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
Comments
Arduino comes configured with 1000HZ. Why is this an issue? You can switch your project to 1000HZ as well and delay properly. |
When using Arduino as an ESP32 component, it becomes an issue, because CONFIG_FREERTOS_HZ is not necessarily 1000. In fact, it defaults to 100. This caveat is mentioned in the doc, but it seemed preferable for the API to generally work? It might be better to fail at compile time by default if HZ<1000? Or somehow emit a warning somewhere? It certainly can be worked around (assuming you don't mind the higher tick rate), so I don't expect this would be particularly high priority, but it did seem to arguably be a defect worth reporting. |
delayMicroseconds() is a blocking delay. This is not a defect, if you ask for a delay(0), you get it... |
If there's a semantic difference between (I'd been hoping for a BTW I'd be happy to submit a PR if there's an agreement on what it might look like. For example |
"Regular" Arduino does not run on top of FreeRTOS, so blocking is not an issue. Here you have watchdogs and whatnot to ensure that the operating system is running correctly. I am really not sure why any of this is an issue, if it's documented that you need to set it to 1KHz. Supporting other frequencies (could be any other than 100Hz as well) will unnecessarily complicate the code. Given that you are using Arduino as component, we would assume that you are not a noob and know how to adjust the frequency and understand the consequences. 1KHz is there because it makes most sense in Arduino, where users expect somewhat "blocking" behavior, but we still need to allow the OS to run. The only "solution" here might be to give an error of frequency is not 1KHz. |
Erroring out (ideally at compile time!) if HZ != 1000 would certainly seem reasonable to me. That would have forced the bug I filed against platformio (example arduino-in-ESPIDF projects should set HZ to 1000) to get fixed. Would you take that PR? |
Definitely! |
Thanks for the PR @egnor! |
Of course! It seems a bit stuck now, I have an open question in the PR on how to address the test failure? (I can sit patiently if needed, not sure how the review workflow works!) |
Hello, Due to the overwhelming volume of issues currently being addressed, we have decided to close the previously received tickets. If you still require assistance or if the issue persists, please don't hesitate to reopen the ticket. Thanks. |
Board
OLIMEX ESP32-POE (but will happen anywhere I think)
Device Description
Stock OLIMEX ESP32-POE, but I believe this will happen on any board
Hardware Configuration
Nothing attached
Version
latest development Release Candidate (RC-X)
IDE Name
PlatformIO
Operating System
Ubuntu 22.04
Flash frequency
40MHz
PSRAM enabled
yes
Upload speed
115200
Description
The Arduino delay() function is implemented as follows:
arduino-esp32/cores/esp32/esp32-hal-misc.c
Line 178 in fcd4799
If portTICK_PERIOD_MS > 1 (i.e. CONFIG_FREERTOS_HZ < 1000), then small values will round down to 0, and no delay will happen. I'm not super familiar with the delay facilities in FreeRTOS / ESP-IDF but there has to be some way to do a shorter delay (busy-wait, if nothing else)?
See also: platformio/platform-espressif32#846
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: