vTaskDelay hangs

clarkster
Posts: 47
Joined: Sat Sep 23, 2017 12:36 pm

vTaskDelay hangs

Postby clarkster » Fri Apr 13, 2018 3:35 am

Here is one of the functions I use to test some stepper drivers:

Code: Select all

abs_stepper_run(STEPPER_0, 10, 45, 8);
ESP_LOGE(STEPPER_TAG, "1st command sent");
vTaskDelay(1000 / portTICK_PERIOD_MS);
ESP_LOGE(STEPPER_TAG, "1st delay done");
abs_stepper_run(STEPPER_0, 10, -45, 8);
ESP_LOGE(STEPPER_TAG, "2nd command sent");
vTaskDelay(1000 / portTICK_PERIOD_MS);
ESP_LOGE(STEPPER_TAG, "2nd delay done");
This code misbehaves. The log shows "1st command sent" is printed, but none of the other commands are printed. The code appears to hang in the 1st vTaskDelay.

If I change the task delays to 500ms, the code works properly.

What is going on?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: vTaskDelay hangs

Postby kolban » Fri Apr 13, 2018 4:15 am

I personally don't see anything obviously wrong with the fragment ... however, context is everything. In what state/context is this code being executed? Is it in the main task or some other task? If you comment out your abs_stepper_run() calls in this code, are there any differences?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

clarkster
Posts: 47
Joined: Sat Sep 23, 2017 12:36 pm

Re: vTaskDelay hangs

Postby clarkster » Fri Apr 13, 2018 5:09 pm

Thanks for your help, kolban.

There are several tasks in my program. Here is a jpg image describing my task architecture.
StepperTaskArchitecture.jpg
StepperTaskArchitecture.jpg (47.65 KiB) Viewed 8876 times
The abs_stepper_run function is called in the run_steppers task.

When I comment out the abs_stepper_run calls, the code works normally - all the messages are printed, but of course the stepper code is not run.

I suspect I am missing some basic knowledge about tasks / FreeRTOS / low level ESP32 stuff, because it doesn't seem possible to me that the app is behaving the way it is.

Without commenting out the abs_stepper_run calls, I can see that abs_stepper_run is returning. Otherwise the "1st command sent" message would not be printed. Also, I am printing out a message after the stepper_task processes the command it receives from the queue and right before it returns to get another command. So I know the stepper_task is not hanging.

The problem occurs in the next line, the first vTaskDelay call. The code hangs somewhere in here. That is shown in two different ways,
1. the "1st delay done" message is not printed
2. the stepper_task never receives another message from the queue.

How could vTaskDelay not return?

Had the vTaskDelay call not hung, the 2nd abs_stepper_run call would have been executed, another command would be put on the queue to the stepper, stepper_task would receive the command, and it would proceed to control the stepper motor in accordance with that command.

If anyone wants I can provide more details about my architecture.

Here's something else that is interesting. After looking at my architecture, I determined I probably do not want app_main to spawn the run_steppers task. That call should probably be done within app_main. When I do this, my code sort of works. No hangs...not doing what I want but my code is probably still full of bugs. It won't take me long to find what is wrong here. Nevertheless, I am clueless as to why moving the initialization code from a task to the app_main made any difference at all.

As I said earlier, I suspect I am missing some basic knowledge about tasks / FreeRTOS / low level ESP32 stuff. How can I learn this better?

chegewara
Posts: 2228
Joined: Wed Jun 14, 2017 9:00 pm

Re: vTaskDelay hangs

Postby chegewara » Fri Apr 13, 2018 7:35 pm

Hi,
could you try to create all tasks on one core with PinnedToCore function? Also, do you use the same priority for all tasks or some tasks got higher priority? Last question, do you use priorityIDLE task for set priority or some value higher than 0?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: vTaskDelay hangs

Postby kolban » Fri Apr 13, 2018 9:40 pm

Studying the FreeRTOS web pages and architecture is not a bad thing.

https://www.freertos.org/

Also, switch on all verbosity of logging and make sure that you have enabled watchdogs to report on stalled tasks. Check for anything going into super tight loops. Also check out (as Chegewara says) priorities of tasks ... especially ones which aren't themselves blocking.

If you get really stuck, take a copy of your code and pull out logic piece by piece until you have a minimal recreate of your issue and post that. Good folks on the community will then take time to assist as long as it is paired down to just the minimal logic to recreate.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

clarkster
Posts: 47
Joined: Sat Sep 23, 2017 12:36 pm

Re: vTaskDelay hangs

Postby clarkster » Fri Apr 13, 2018 10:10 pm

Thanks for the help, guys. Looks like I need to do some study.

How do I do this - "make sure that you have enabled watchdogs to report on stalled tasks"?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: vTaskDelay hangs

Postby kolban » Sat Apr 14, 2018 4:10 am

Howdy,
See the following link and the instructions for changing these settings:

http://esp-idf.readthedocs.io/en/latest ... ml#int-wdt
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Who is online

Users browsing this forum: axellin, MicroController, tanmanh0707 and 103 guests