Im trying to configure wakeup event on stm32f4 discovery, and i'm using a bit modified example from coocox.
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
PWR_BackupAccessCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);
RTC_WriteProtectionCmd(DISABLE);
RCC_RTCCLKConfig(RCC_RTCCLKSource_HSE_Div8);
RCC_RTCCLKCmd(ENABLE);
RTC_WaitForSynchro();
RTC_InitTypeDef rtcinit;
rtcinit.RTC_HourFormat = RTC_HourFormat_24;
rtcinit.RTC_AsynchPrediv = 99;
rtcinit.RTC_SynchPrediv = 9999;
RTC_Init(&rtcinit);
EXTI_ClearITPendingBit(EXTI_Line22);
EXTI_InitStructure.EXTI_Line = EXTI_Line22;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits);
RTC_SetWakeUpCounter(0x0);
RTC_ITConfig(RTC_IT_WUT, ENABLE);
RTC_WakeUpCmd(ENABLE);
RTC_TimeTypeDef time;
RTC_TimeStructInit(&time);
time.RTC_Hours = 12;
RTC_SetTime(RTC_Format_BIN,&time);
The problem i have is that interrupt never happens. RTC itself works just fine.
It seems I forgot to use
RTC_ClearFlag(RTC_FLAG_WUTF);
RTC_ClearITPendingBit(RTC_IT_WUT);
after
RTC_WakeUpCmd(ENABLE);
now it should work, but weird problems begins here
im using this library https://github.com/xenovacivus/STM32DiscoveryVCP
for USB VCP.
I noticed, that when I remove
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb);
Wakeup works correctly, but when i use this function interrupt only happens once, twice or never (based on diode blinks), depending on where i put it (tested between initialisations of other peripherials)
In the file usb_bsp.c
, comment the line
RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
It worked for me. Regards.