-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
Watchdog reset dependent on delay
?
#2493
Comments
This is the IDLE task (ie, the scheduler) complaining that it is not getting any time. If you do not want this behavior, it can be disabled with disableCore0WDT(). Note that it is there for a reason,and real time behavior can be lost if you lock up the cpu. |
I do want to use both cores and I do want to have a watchdog on both cores. Did you check my example? The question is why it is reseting the watchdog timer only when calling the Thanks! |
It is not your task that is tripping the watchdog. It is IDLE0 (read your error carefully). By putting in a delay, the scheduler gives time to IDLE0, so it does not panic. |
@lbernstone Thanks for your response. I read it very carefully and it is the Please understand that by calling If you remove
Please note the difference. |
PRO_CPU_NUM is defined as core zero, to pin to core one you will want APP_CPU_NUM likely.. However, there is a subtle flaw in your code posted originally. Each loop iteration appears to create another task without checking if it has already created it or not. This will very likely crash St some point as it will run out of heap or other unknown behaviors. Now, expanding on what @lbernstone wrote. In your task you are firing off on PRO CPU, if you do not have any form of delay in the task the task scheduler will not have any CPU time to run and that will trigger the WDT. The enableLoopWDT method enables the WDT for the APP CPU where both setup() and loop() are called from. The esp_task_wdt_reset API only resets for the "current" task and not others that may also run on the same core and not all tasks are tracked by the WDT. |
@atanisoft Thanks for your fast reply. Indeed I acknowledge the flaw, I just put something together really fast to demonstrate that the Please not that I used Could you reproduce this behaviour? |
WDT is doing it's job, the problem is in your task. It prevents the task scheduler from running on the PRO core since it monopolizes all CPU cycles. Without having delay/vTaskDelay/etc the task scheduler never runs and the idle task for the core (scheduler) will not reset the WDT for it's task and that will trigger the WDT. So no the WDT is not dependent on delay. WDT is dependent on cooperative scheduling of all running tasks on a core. And yes I can easily reproduce this behavior with your code or my own as there is a critical flaw in the cooperative nature of the task. |
OK - let me get this right. Isn't the ESP32 able to run simultaneously on both cores? Well it should as per tech spec. So why do I need to give control back to the This is very much intentional, to monopolize all CPU cycles on I'm pretty sure I didn't have this kind of issues while doing similar thing in ESP-IDF, but I can provide a proof of concept code to demonstrate that each core should be able to reset the WD while heavily using each core without "windows" ( Am I missing something here? How can I heavily use both cores in parallel, that are able to reset the WD individually? Thank you for your detailed explanation so far. BTW: I moved the creation of the new task on |
Yes, it is very capable of doing just that.
The usage of delay (or variants) does not shift control between cores. It shifts control between TASKS running on the same core (unless the task floats between cores in which case that is a different story).
What you are doing here is no different than running in ESP-IDF. The same problem would be easily displayed via ESP-IDF as it is starving the task scheduler which leads to the WDT triggering for that core.
The implementation on the ESP32 is such that each core operates independently with a task scheduler running on each core (IDLE0, IDLE1). These schedulers must have a few cycles periodically otherwise the WDT will be triggered as it assumes the task is hung. The usage of delay (which calls vTaskDelay internally) is simply to allow the scheduler to do it's maintenance activities, shift to another task with higher priority, etc. you could look at vTaskDelay(0) which is a light weight way to inform the scheduler that it shift to another higher priority task if there is one, if there isn't one it will return almost immediately (WDT will be reset in this case for the scheduler). |
Here is sample code. Unremarking either line will prevent WDT timeout. The first works with the OS, feeding the scheduler (every 2^12 passes). The other just turns off the scheduler WDT.
|
@lbernstone Thanks for the demo code. Alright I can understand now, I also made a proof of concept with ESP-IDF. I have read the docs https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/freertos.html# I know it's not the appropriate place, but would you please be kind and answer to this question, while closing this issue: What's the best practice when dealing with a timer interrupt, that is creating a task pinned to the other core, so it is entirely focused on sensitive blocking RS485 IO operations? Of course I can just add a I really appreciate your input here. |
If it is an interrupt, use interrupts along with queues. You don't need to micromanage and bitbang when there is a driver built in to the system. |
Thanks. It is much more complex than that. I saw it is a decent practice to give some windows for scheduler to feed the watchdog within the heavy blocking tasks. So I'm going to do just that. I appreciate your support in helping me figuring out. |
Is it possible that within a task running on
Core 0
theesp_task_wdt_reset()
to fail to reset the WD timer?Board: ESP-WROOM-32 WEMOS.
Please check the following example with and without the
delay()
before the WD reset function.If I don't use the
delay
I get this:When
delay
is called, then everything works as expected, resetting the WD timer.Thanks.
The text was updated successfully, but these errors were encountered: