espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
12.98k stars 7.12k forks source link

When closing an open usb-cdc connection, the timer svc stops executing some periodic functions, but calls others (IDFGH-7624) #9176

Open moefear85 opened 2 years ago

moefear85 commented 2 years ago

Environment

Problem Description

I have 5 functions periodically executed by the timer service, 3 of them about every 1-3 seconds, the other 2 every 10ms and 40ms, but they only start running once the usb-cdc port is opened on the pc side.

Everything works right before and during the pc connection. But once I close the cdc port from the pc side, the two fast functions continue getting called by the timer, while the slower 3 stop getting called. I set up log statements at the very start and very end of each function to determine the moments each enters and exists. I am sure no function is hanging mid-way. This isn't even possible, as it would have to stall the entire timer service to my knowledge, causing the whole timer thread to hang. But the timer thread doesn't hang, as evident by the continued calling of the fast functions. Yet the other 3 are not entered again at all until the cdc port is opened again.

I tried twiddling the tinyusb and timer priorities, making each higher than the other. this has no effect on the problematic behavior. The only way this scenario is even possible, to my knowledge, is if the timer service explicitly decides to skip executing some functions. I'm not aware it can do this, nor why it would do this for the slow functions. Either way, I don't see why the choice would depend on whether usb-cdc is open or not. All functions, expecially the fast executing ones, do read and/or write operations to usb-cdc, so I don't see why some would behave differently than others.

If I increase the periods of the fast functions to 100ms and 400ms, the problem disappears. But this is not an acceptable workaround.

Code

I can't upload the whole project, and it is time consuming to produce a minimal example of a bug for github. So I will do it as soon as I can. sdkconfig.txt

0xjakob commented 2 years ago

@moefear85 Just to clarify: with "timer svc" or "timer service", you mean the esp_timer component and not the General purpose timer, correct?

igrr commented 2 years ago

Or the FreeRTOS timers? (https://github.com/espressif/esp-idf/blob/8b902739ac6ef46c0f5c6f25491aa8ed79a4e898/components/freertos/FreeRTOS-Kernel-SMP/timers.c#L63)

moefear85 commented 2 years ago

hi, i mean the freertos timer task