cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U575 with USBX, MSC and CDC causes sporadic USB disconnect

kumaichi
Senior

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

1 ACCEPTED SOLUTION

Accepted Solutions

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.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


View solution in original post

6 REPLIES 6
FBL
ST Employee

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.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


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

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

 

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.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


Hello @FBL 

Thank you for your response, I thought the _ux_utility_error_callback_register(&ux_host_error_callback) was invoked for both host & device paths, my mistake.

I'm at a loss here, what is the proper way to diagnose and handle device-side USB errors?  I've watched the videos, the latest one being, USBX on STM32C0 in practice - 4 USBX CDC I verified my implementation matches what is happening in the video or at least as much as I can, I believe that implementation is for Standalone mode.  I've been dissecting the U5 samples and haven't found anything that handles this case of random disconnects.  I've read the wiki as well.  Are there any other resources that can lead me in the right direction?

Kindest regards

Hi @kumaichi 

This article might be helpful to implement composite device using USBX.

If you are facing a new problem, I suggest opening a new community thread for it so we avoid confusing future readers. 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.