cancel
Showing results for 
Search instead for 
Did you mean: 

Getting sleep to work when USB CDC is enabled?

PMath.4
Senior III

My program has the option of sleeping for a period using the RTC to wake or sleeping until the wakeup pin is set high. Both these functions work perfectly if I talk to the outside world using a uart.

However, I configure CDC as a serial port SLEEP doesn't work - or at least the USB never disconnects.

I'm using USB STOP and USB DEINIT before the sleep command but these don't seem to do anything. Any ideas appreciated

            while(totalseconds>0){
                if(totalseconds>30.0){
                    timetosleep=30*2048;
                    totalseconds-=30.0;
                } else {
                    timetosleep= (int)(totalseconds*2048.0);
                    totalseconds=0.0;
                }
                USBD_Stop(&hUsbDeviceFS);
                USBD_DeInit(&hUsbDeviceFS);
                HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 0x0F, 0);
                HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
                HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, timetosleep, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
                HAL_SuspendTick();
                HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFE);
                HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
                HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
            }
             SYSCLKConfig_STOP();
             HAL_ResumeTick();
             MX_USB_DEVICE_Init();

13 REPLIES 13
Ons KOOLI
Senior III

Hi PMath.4,

Can you please provide the product or the MCU family you are working with ?

Best Regards,

Ons.

PMath.4
Senior III

Oops - sorry. STM32F407VET

And the hardware? Is this some "known good" board like Nucleo or Disco? Is there any external pullup to DP/DM?

What exactly means "USB never disconnects"?

JW

PMath.4
Senior III

Standard wiring using the internal phy with a 22R to the pins and a 1.5K pulldown up on D+ at the USB socket.

"What exactly means "USB never disconnects"?"

Don't get the windows chime when a USB device disconnects even after calling the STOP and DEINIT commands. The chime only happens when I press reset to get out of whatever state the H/W is in i.e. completely unresponsive

What is

> 1.5K pulldown up on D+

so is it a pull*down* or a pull*up* (i.e. where is the other end connected)?

There is no such resistor to be on DM/DP in the 'F4xx. Read the Full-speed OTG PHY subchapter in RM0090.

JW

PMath.4
Senior III

Operating as device only not OTG. Pullup is standard to indicate to USB host that a device is connected and should be enumerated as full speed.

There is nothing wrong with the basic USB connection - it works perfectly. The issue is that it isn't releasing and as, unlike the NXP chips, the ST doesn't have a programmable pullup in the UP it has to be external.

Resetting the processor causes the PC to drop the connection and re-connect so there is something not happening in either STOP or DEINIT that isn't signalling the loss of connection to the PC as it should

> unlike the NXP chips, the ST doesn't have a programmable pullup in the UP it has to be external.

This for 'F4 is not true. Have you read the chapter I told you to? Have you already thrown out that resistor?

JW

PMath.4
Senior III

"This for 'F4 is not true. "

Accepted, but it says that is dependent on using VBUS which isn't configured or connected (optional in CubeMX) and can't be as the pin is in use.

All irrelevant though as the issue is that a simple reset frees the bus whereas stopping and de-initing doesn't so there is something missing in the implementation of either stop or de-init or I'm missing a step which I can't find

And have you already undone that resistor? It's a 10 seconds operation after the soldering iron has heated up.

JW