9 static uint8_t awu_initialized=0;
11 void RTC_WKUP_IRQHandler(
void)
13 EXTI->PR = EXTI_PR_PR20;
15 PWR->CR |= PWR_CR_DBP;
16 RTC->ISR &= ~RTC_ISR_WUTF;
17 PWR->CR &= ~PWR_CR_DBP;
20 void __unlock_RTC_registers(
void)
23 PWR->CR |= PWR_CR_DBP;
28 void __lock_RTC_registers(
void)
31 PWR->CR &= ~PWR_CR_DBP;
37 uint32_t safety_counter;
39 NVIC_DisableIRQ(RTC_WKUP_IRQn);
41 __unlock_RTC_registers();
43 EXTI->PR = EXTI_PR_PR20;
45 RTC->ISR &= ~RTC_ISR_WUTF;
47 RTC->CR &= ~(RTC_CR_WUTE | RTC_CR_WUTIE);
50 while ((!(RTC->ISR & RTC_ISR_WUTWF)) && (safety_counter<AWU_MAX_WAIT))
55 if (wakeup_timeout_ms>16000)
57 wakeup_timeout_ms=16000;
60 RTC->WUTR = (((uint32_t)wakeup_timeout_ms)*4096UL)/1000UL - 1;
63 RTC->CR &= ~RTC_CR_WUCKSEL;
64 RTC->CR |= RTC_CR_WUCKSEL_0;
67 RTC->CR |= RTC_CR_WUTE | RTC_CR_WUTIE;
69 __lock_RTC_registers();
72 EXTI->IMR |= EXTI_IMR_MR20;
73 EXTI->RTSR |= EXTI_RTSR_TR20;
75 NVIC_EnableIRQ(RTC_WKUP_IRQn);
82 uint32_t safety_counter=0;
89 SCB->SCR |= SCB_SCR_SLEEPDEEP;
90 PWR->CR |= PWR_CR_LPSDSR | PWR_CR_CWUF;
91 PWR->CR &= ~PWR_CR_PDDS;
95 RCC->CR |= RCC_CR_HSION;
98 while ((!(RCC->CR & RCC_CR_HSIRDY)) && (safety_counter<AWU_MAX_WAIT))
103 RCC->CFGR &= ~RCC_CFGR_SW;
104 RCC->CFGR |= RCC_CFGR_SW_HSI;
107 while (((RCC->CFGR & RCC_CFGR_SW)==RCC_CFGR_SW_HSI) && (safety_counter<AWU_MAX_WAIT))