cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 USB wake up from Stop0/1

Dim N
Associate II

Hello,

I am developing a USB HID application on STM32L443. The HID communication works in both directions when I put the controller in Sleep mode with WFI and Sleep on Exit. I am currently experimenting on the suspend/resume capability of the USB. I have 2 LED on my board and I toggle them in the USB interrupt routine on suspend and resume events. On a Linux host machine I am using the powertop utility to manually send suspend and wake-up signals. I assume this setup works, because the LEDs flash the way they should when I send the suspend/wake-up commands. According to the datasheet, the USB peripheral is able to wake up the MCU from Stop0/1 modes. So I try the following in the USB interrupt routine:

if (USB->ISTR & USB_ISTR_SUSP)

{

       USB->ISTR = USB_CLR_SUSP;

       USB->CNTR |= USB_CNTR_FSUSP;

       USB->CNTR |= USB_CNTR_LPMODE;

if(device_status == USB_CONFIGURED)

{

SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;

}

}

if (USB->ISTR & USB_ISTR_WKUP)

{

       USB->ISTR = USB_CLR_WKUP;

       USB->CNTR &= ~USB_CNTR_LPMODE;

RCC->AHB2ENR |= RCC_AHB2ENR_GPIOCEN;

GPIOC->ODR ^= GPIO_ODR_OD14;

SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;

       USB->CNTR &= ~USB_CNTR_FSUSP;

}

I am using HSE with PLLs for SystemClock and USB clock. I have set up HSI16 as a wake up clock in RCC->CFGR. EXTI line 17 (USB FS) is enabled by default, according to the reference manual. The device does enter Stop0 after sending suspend command with powertop - the current consumption drops from 3mA in Sleep mode to around 350uA. I expect that when I send a resume signal, the MCU will power on the HSI16 and deal with the USB interrupt, where as you can see, I simply start the GPIO clock (the pin is configured as an output before the USB initialization) and toggle the LED, I am not restarting the HSE and the USB yet. And it does not work. If I do not enter Stop0 after a suspend signal, the wake-up signal is recognized and the LED lights up. Does anyone know how to correctly wake up a STM32 from stop mode with USB?

1 ACCEPTED SOLUTION

Accepted Solutions
Dim N
Associate II

Thanks for the reply. It turned out to be a simple thing - I was using another EXTI channel, but instead of setting its bit in EXTI->IMR, I was overwriting the whole register, clearing the USB FS on line 17.

View solution in original post

3 REPLIES 3

I have no experience with this and don't use the lower-end L4, but if you want to wake up the mcu from STOP0/1, you need to configure EXTI for line 17 which is the USB FS wakeup event (and of course have wakeup enabled in USB_CNTR). Read the Low-power Modes and the Wakeup event management chapter in RM.

JW

Dim N
Associate II

Thanks for the reply. It turned out to be a simple thing - I was using another EXTI channel, but instead of setting its bit in EXTI->IMR, I was overwriting the whole register, clearing the USB FS on line 17.

Thanks for coming back with the solution.

Please select your post as Best, so that the thread is marked as solved.

JW