Skip to main content
Graduate
October 13, 2025
Solved

STM32U575 with USBX, MSC and CDC causes sporadic USB disconnect

  • October 13, 2025
  • 1 reply
  • 493 views

Hello All,

I'm trying to keep my MSC + CDC USBX connection alive on my STM32U575.  When I connect the device via USB cable, Windows Explorer opens and displays the files on the W25Q NOR Flash.  I can select a file and open it from the flash.  I can also open Tera Term and connect to the device.  I created a ThreadX task to write out text over CDC every 5 seconds.  After a random amount of time, Tera Term stops writing out the text and lock up and even though the device is displayed in Windows Explorer, if I try to open a file, it fails, with a timeout error.

I've explored the U5 samples, but I can't find any differences between the MSC or CDC projects and my project.  None of the samples, that I've found, are doing anything in the callbacks or change methods that would indicate the handling of some kind of "timeout" issue from the USB host.

Any guidance to why the device just stops communicating with the windows machine would be greatly appreciated.  If any of my source would be worthwhile, I'd be happy to show what I've got.

Kindest regards

    This topic has been closed for replies.
    Best answer by FBL

    Hi @kumaichi 

    ux_host_error_callback() is part of the USBX Host stack, used when your device acts as a USB host (e.g., controlling other USB devices).

    In your case, the STM32U575 is running a USB device (MSC + CDC) application, not a host. Therefore, implementing ux_host_error_callback() in your device firmware is not appropriate and will not help diagnose or handle device-side USB errors.

    1 reply

    Technical Moderator
    October 13, 2025

    Hi @kumaichi 

    It appears that the issue may be related to the integration of the USBX stack with your RTOS. Specifically, the USBX thread responsible for handling USB events might not have a sufficiently high priority, which could cause it to be preempted or starved by other application threads. This can lead to delayed or missed USB event processing, resulting in communication timeouts or freezes.

    To assist you effectively, could you share a minimal reproducible project that demonstrates the issue?

    Otherwise, try to analyze the USBX thread configuration, task priorities, and overall integration. Verify there is no stack overflow or memory corruption in your RTOS tasks.

    kumaichiAuthor
    Graduate
    October 13, 2025

    Hello @FBL 

    Thank you for your response.  I changed the thread priority of the USBX from 20 to 5.  This change increased the amount of time the device is connected.  However, it will still disconnect itself.  I also added the method, ux_host_error_callback and it does break on this method when the device disconnects itself.  The values are:

    system_level = 0x2
    system_context = 0x7
    error_code = 0x54

    I'm unclear what this information means.  I've also attached my project.  Any insight would be greatly appreciated.

    Kindest regards

    kumaichiAuthor
    Graduate
    October 15, 2025

    After doing more debugging, the error seems to be triggered by the OTG_FS_IRQHandler, which then climbs up the stack triggering a reset callback.  Am I correct in my thinking that maybe the CDC is trying to write out the text when the stack is disconnected thus throwing the error?  Or is it something else that is causing the issue.  Below is a screenshot of the call stack when the error occurs.

    kumaichi_0-1760497101957.png

    Any insight would be greatly appreciated.

    Kindest regards