Skip to main content
Graduate II
June 11, 2025
Solved

USBX CDC-ACM + Sleep Mode: How to wake STM32U5 on USB activity?

  • June 11, 2025
  • 6 replies
  • 1030 views

Hi everyone,

I'm working with an STM32U5 and using USBX with the CDC-ACM class.

My setup is as follows:

  • I have a USBX CDC ACM receive thread that calls usbx_cdc_acm_read_thread_entry() in ux_device_cdc_acm.c file.

  • Alongside, I have a state machine running in another context (main loop).

  • If the device stays idle (no USB activity) for a certain timeout, the state machine puts the MCU into Sleep Mode using:

HAL_SuspendTick();
HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
HAL_ResumeTick();

The goal is to wake up the MCU only when data is received on the USB.

To achieve this, I tried relying on USB interrupts:

  • OTG_FS_IRQn is enabled in NVIC.

  • The USB OTG FS peripheral is initialized properly via HAL_PCD_Init().

  • OTG_FS_IRQHandler() is defined and calls HAL_PCD_IRQHandler()

But I'm not getting out from the Sleep mode, I'm completely stuck and running out of ideas. 
Any assistance would be greatly appreciated. 
Thank you! 

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

    Hi @j_filipe,

    To avoid any confusion, it’s best to start a new discussion for this topic.

    In summary, waking the MCU from Sleep mode can be achieved by using a resistor divider combined with a GPIO interrupt triggered by USB signals such as VBUS sensing or session valid signals.

    Regarding the temperature not dropping in Stop mode:

    • Ensure that all unnecessary peripherals are either disabled or set to low power mode before entering Stop mode.
    • Verify that the debug interface (SWD/JTAG) is disabled or configured so it does not interfere with low power operation, as debug mode can prevent proper power saving.

    I hope this helps clarify the situation. If your initial question has been resolved, you may consider closing this thread.

    6 replies

    Super User
    June 11, 2025

    Should be working. Any interrupt is able to wake the processor out of sleep mode from WFI. No special setup required.

    TDK_0-1749664648618.png

     

    If you don't disable systicks, do systicks wake it up?

    > But I'm not getting out from the Sleep mode

    How exactly are you determining this? Have an LED light up only when you're in sleep mode. Ensure it goes off.

     

    Are you entering sleep within the main thread? It may not work as you expect if you're in an interrupt.

    j_filipeAuthor
    Graduate II
    June 12, 2025

    Greetings TDK, 
    I'm determining this by toggling a GPIO signal in the OTG_FS_IRQHandler callback. While it is not in sleeping mode, I can watch the signal changing in the osciloscope, but when I enter in sleep mode, I cannot watch any signal changes. 
    But yes, even if I don't disable systicks, it doesn't wake up from sleep. 
    So, basically I've a receive usb data thread that generates the interrupt, if it's not in sleep mode, it generates an interrupt, but if I go into sleep mode (disabling or not the systicks), it doesn't generate the interrupt. 

    j_filipeAuthor
    Graduate II
    June 12, 2025

    More... 
    If I use debug mode, it gets out from sleep.

    j_filipeAuthor
    Graduate II
    June 13, 2025

    Ok what is happening: So I start the debug mode, it goes to sleep mode. I press any key from the keyboard to generate the interrupt , nothing happens, I can't see anything in the osciloscope. I press the pause button and it is on __WFI(); in the HAL_PWR_EnterSLEEPMode. As soon as I press the resume button, it generates the interrupt (cause I see the signal in the osciloscope) and wakes up from sleep. So I can only manage to exit the sleep mode in debug mode.

    Technical Moderator
    June 13, 2025

    Hi @j_filipe 

    Would you attach minimum firmware to reproduce the issue? Are you using a reference board?

    j_filipeAuthor
    Graduate II
    June 16, 2025

    Greetings FBL, 
    Unfortunately I can't attach minimum firmware to reproduce the issue due to the possibility of copyright infringement. I'm not using any reference board, just making use of the STM32U5 series MCU. At least I would like to know which front I should look on, or what could be the possible cause of this issue. 
    Best regards!

    Technical Moderator
    June 17, 2025

    Hi @j_filipe 

    For STM32U5 there isn’t a dedicated USB line in the vector table to wake up the MCU, as was available in older products like the STM32F429 : OTG_HS_WKUP.

    FBL_0-1750155840906.png

    Instead, you can use simple resistor divider combined with GPIO to trigger a wake up via USB controller. Check section 2.6.1 Simple resistor divider in AN4879 for better details.

    Make sure main regulator voltage scale is not in range 4 (or 3 depending on your product). Otherwise, this won't be possible as detailed in corresponding datasheet.

    j_filipeAuthor
    Graduate II
    June 18, 2025

    Thank you for the insight FBL. 
    However I checked the RM0456, which is referred to the STM32U5 series MCUs and it shows the the OTG_FS_WKUP / OTG_HS_WKUP line. Screenshot_20250618_112544.png

    Technical Moderator
    June 19, 2025

    Hi @j_filipe 

    In footnote, it is noted:

    1. OTG_FS_WKUP becomes active (high state) when resume condition occurs during L1 SLEEP or L2 SUSPEND states.

    This is not direct EXTI wakeup. 

    You can refer also to Table 190: EXTI line connections: we don't have direct USB wakeup over EXTI on STM32U5. 

    FBL_0-1750340379832.jpeg

    You have 40ms to detect vbus cable loss.

    With aggressive low power mode, we can poll SESSVLD in OTG_GCCFG for about 40 ms every 25us to monitor vbus state. There should be no event generated.

    j_filipeAuthor
    Graduate II
    July 3, 2025

    Update, 
    So I managed to get to STOP mode. I have a state machine that can change state in asynchronous or synchronous way and I managed to put it in STOP mode in asynchronous way. 
    I can wake up if I click in a key in the keyboard but the temperature of the board is not dropping, don't know why. I can see that it entered in STOP mode because I've a LED that is toggling while the program is running, and when it gets to STOP mode it stops toggling. The thing is, temperature is not dropping. I guess something is missing. 

    Technical Moderator
    July 3, 2025

    Hi @j_filipe 

    Maybe a heat sink could help in your case?

    if your initial questions have been resolved, you can close the thread by marking the most helpful response as accepted to adhere to community guidelines. 

    j_filipeAuthor
    Graduate II
    July 4, 2025

    Hi FBL,
    So, the situation that I mentioned yesterday, it only worked for Stop mode, not for Sleep mode. The device doesn't overheat, so there's no need for an heat sink, but while in idle, the temperature reaches undesirable levels, hence the sleep or stop mode. Since the device reaches the same level of temperature in Stop mode (same as Idle), I guess that something is not right. 
    Should I create a new thread for this situation? 
    Thank you.