panicdave wrote on Friday, March 08, 2019:
I’m running FreeRTOS 10.1.1 (originally ran into this problem on 8.2.1) on a STM32F746.
I have a main thread and two threads, separate read and write, to service the usb serial port. Everything works fine until I cycle the device into and back out of low power (“stop”) mode. At some random point after this, can be in an instant or a minute or more later, the processor hangs in xQueueSemaphoreTake(), called from the the read thread. I added some logging and see that in normal operation it looks like the CPU only passes through xQueueSemaphoreTake() once each time it’s called, but in the hang condition it’s comes back around to call vTaskPlaceOnEventList() a second time, which creates a loop in the linked list, then on the third time around it hangs in vListInsert() since the task’s pxNext points back to itself. I added a listIS_CONTAINED_WITHIN() check to vListInsert before adding the item, but it just punted the error down the road a little bit. (It would then be stuck in the xQueueSemaphoreTake() loop, as I recall…)
I suspect the problem is how I’m putting the device to sleep and waking it up. Here’s the order I’m doing things in:
USB_deinit(); // de-init USB device, doesn't touch threads
HAL_SuspendTick();
osThreadSuspendAll();
enterLowPower(); // turns off peripherals, slows clock speed to minimum
while ( !unlock )
{
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON,PWR_STOPENTRY_WFI);
}
exitLowPower();
HAL_ResumeTick();
USB_Init();
osThreadResumeAll();
Does anything there look suspicious? I’ve tweaked the order of those steps and played around with the semaphore timeouts but it only moves the hang from one place to another. Is there any other information I can dig up to help sort this out?
Many thanks!