Page 1 of 1

ESP32 kernel hang

Posted: Fri Aug 08, 2025 11:17 am
by Vitalii_Bondarenko
I am writing a program for ESP 32, in the platformio environment, using the Arduino framework. IDF-5.3.2 .
I use as a basis a debug board - ESP-WROOM-32 ESP32 30 Pin, which is inserted into my cross board with the rest of the harness.

Platform.ini file -

Code: Select all

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
upload_port = COM31
monitor_port = COM31
board_build.partitions = partitions.csv
monitor_filters = esp32_exception_decoder
lib_deps = 
	arduino-libraries/Arduino_JSON @ 0.1.0
	esp32async/ESPAsyncWebServer@^3.7.0
The program works on ModBus, I have two lines. It works on MQTT, transmitting and receiving data. And it also works as a web server. I use wired Internet via W5500.

I write all the code using only the functions of the IDF framework, except for the web server, this is the only Arduino library that I use.

Once a day I do a forced reboot of the controller, through - esp_restart();

Initially, I did not configure any WDT myself, but the controller froze once every three days, although I reboot it every day(24 h).
I assumed that the system itself turns on the WDT timer and in case of freezing it will reset the MС.
Then I added some code where I also set the WDT for one of the tasks, a simple task that just resets the timer. Here is the WDT setup code.

Code: Select all

void FnInitWDT(void)
{
  esp_err_t err;
  esp_task_wdt_config_t cfg_wdt;
  cfg_wdt.timeout_ms = WDT_TIME_OUT;
  cfg_wdt.trigger_panic = true;
  cfg_wdt.idle_core_mask = 0x00;

  err = esp_task_wdt_init(&cfg_wdt);
  if(err!=ESP_OK) ESP_LOGE(TAG,"ERR_INIT WDT");
  err = esp_task_wdt_add(NULL);
    if(err!=ESP_OK) ESP_LOGE(TAG,"ERR_ADD WDT");
}
Code in task -

Code: Select all


for(;;) //infinite cycle in task
{
  ulTaskNotifyTake(pdTRUE, 100/portTICK_PERIOD_MS);
      esp_task_wdt_reset();
}
Well, two weeks after my modification, with the timer, the controller froze again. That is, it worked for two weeks without freezing and froze.

How can it be that the WDT does not reset the MC in case of a freeze?
No other MC works like this, if the system freezes - the hardware timer of the WDT must reset the microcontroller.

I ask for help with this problem.

Re: ESP32 kernel hang

Posted: Fri Aug 08, 2025 11:33 am
by MicroController
but the controller froze once every three days
...
How can it be that the WDT does not reset the MC in case of a freeze?
How do you come to the conclusion that the "controller" or the "system" freezes?
No other MC works like this, if the system freezes - the hardware timer of the WDT must reset the microcontroller.
Every WDT works like this. As long as the WDT is reset regularily, it doesn't do anything.
This suggests that "the system" did not "freeze", at least as far as the idle tasks and your watchdog-resetting task are concerned. So the question remains: What is the symptom you observe that indicates a freeze of "the system"? Which of your tasks stops working properly? Are your tasks registered with the task WDT?

Re: ESP32 kernel hang

Posted: Sun Aug 10, 2025 4:01 am
by vvb333007
2 weeks delays before freeze may tell about some counter overflows.
Some counters somewhere.

Did you try to run your code with parts of it disabled? Still freezes?

Re: ESP32 kernel hang

Posted: Sun Aug 10, 2025 4:45 am
by dmitrij999
Could you please check and try to use vTaskDelay([at least one tick]) in loops?
In FreeRTOS, it says to scheduler that "not to switch to this task for this number of ticks". As well, it lets the scheduler to switch to another tasks and handle them correctly

Re: ESP32 kernel hang

Posted: Mon Aug 11, 2025 8:19 am
by Vitalii_Bondarenko
2 weeks delays before freeze may tell about some counter overflows.
Some counters somewhere.

Did you try to run your code with parts of it disabled? Still freezes?
I haven't tried running it with separate parts, so I can't say, unfortunately.

Re: ESP32 kernel hang

Posted: Mon Aug 11, 2025 8:23 am
by Vitalii_Bondarenko
Could you please check and try to use vTaskDelay([at least one tick]) in loops?
In FreeRTOS, it says to scheduler that "not to switch to this task for this number of ticks". As well, it lets the scheduler to switch to another tasks and handle them correctly
I do a forced reboot of the MС inside the program once a day to avoid such problems. Although I am already working on the program so that such a problem does not exist in principle. Even if some counters were to overflow, it would simply affect the correct operation of the system, but not freeze.

Re: ESP32 kernel hang

Posted: Mon Aug 11, 2025 8:43 am
by Vitalii_Bondarenko
Could you please check and try to use vTaskDelay([at least one tick]) in loops?
In FreeRTOS, it says to scheduler that "not to switch to this task for this number of ticks". As well, it lets the scheduler to switch to another tasks and handle them correctly
All my tasks have a section of code where they pass control to the scheduler. Calls -xRingbufferReceive, ulTaskNotifyTake, xQueueReceive.
If at least one task did not have a function that transferred it to the state - Blocked. Then I would have received the WDT triggering a few seconds after the program started, I can say that for sure.
The waiting time that I set in the blocking function of FreeRTOS is either 100 ms, or even portMAX_DELAY.