cancel
Showing results for 
Search instead for 
Did you mean: 

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

j_filipe
Associate II

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! 

3 REPLIES 3
TDK
Super User

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.

If you feel a post has answered your question, please click "Accept as Solution".

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_filipe
Associate II

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