Skip to content

usb: stm32: MCU fall in deadlock when calling sleep API during USB transfer #30187

@easternblack

Description

@easternblack

Describe the bug
during USB transfer, If main or thread calls sleep API(ex. k_sleep, k_msleep, k_usleep), MCU fall in deadlock.

To Reproduce
To simplify the situation, I made simple usb stack and sample program for test.
easternblack@d1cf0a6

Before make, you should modify a little in main.c
There's 2 ways to reproduce the matter.

  1. Use k_sleep() or k_msleep(), or k_usleep() instead of k_yield() in the main while().
  2. Uncomment thread_create() in the main().

then, make and flash.

  1. mkdir build; cd build
  2. cmake -DBOARD=stm32f746g_disco ..
  3. make

Expected behavior
If host send BULK_OUT data start with 'a' 'b' 'c', then device response 100 bytes length of BULK_IN data.

Impact
If there's sleep API in main() or other thread, MCU falls in deadlock.

Logs and console output
BULK_OUT data sended by host start with 'a', 'b', 'c'
wire_shark

BULK_IN data from device after host send correct data.
wire_shark_2

With repeating this transfer, and main() or other threads calls sleep API periodically, MCU fall in deadlock and never wake up until hardware reset.

If there's more often USB transfer, the situation also occurs more often too.
Shorter period of sleep API makes the problem more often.(k_usleep(1) > k_msleep(1)).

Environment (please complete the following information):
TEST environment:

  • HOST: Window 7 USB Host Program.
  • Test Board: stm32f746i_disco.
  • based on bc6d16e

Additional context
My purpose was make mass transfer via USB.
at first, I thought other functions and works are cause of the problem. so, I cut off other functions one by one and finally found k_sleep-things makes this situation.
I made USB stack by reference USB loopback in zephyr origin.

I also read #28333 and #28408 but did not work on this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions