Getting sleep to work when USB CDC is enabled?
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();