kopia lustrzana https://github.com/SP8EBC/ParaTNC
wakeup timer configuration moved to separate function
rodzic
7f66de28ce
commit
0d8a02e7fb
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="ilg.gnumcueclipse.debug.gdbjtag.openocd.launchConfigurationType">
|
||||
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.PERIPHERALS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <peripherals> <peripheral name="RCC"/> <peripheral name="PWR"/> <peripheral name="RTC"/> <peripheral name="EXTI"/> </peripherals> "/>
|
||||
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.PERIPHERALS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <peripherals> <peripheral name="RTC"/> </peripherals> "/>
|
||||
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doContinue" value="true"/>
|
||||
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doDebugInRam" value="false"/>
|
||||
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doFirstReset" value="true"/>
|
||||
|
|
|
@ -266,9 +266,11 @@ int main(int argc, char* argv[]){
|
|||
// enable access to PWR control registers
|
||||
RCC->APB1ENR1 |= RCC_APB1ENR1_PWREN;
|
||||
|
||||
system_clock_update_l4();
|
||||
|
||||
system_clock_configure_rtc_l4();
|
||||
|
||||
system_clock_update_l4();
|
||||
system_clock_configure_auto_wakeup_l4(300);
|
||||
|
||||
RCC->APB1ENR1 |= (RCC_APB1ENR1_TIM2EN | RCC_APB1ENR1_TIM3EN | RCC_APB1ENR1_TIM4EN | RCC_APB1ENR1_TIM7EN | RCC_APB1ENR1_USART2EN | RCC_APB1ENR1_USART3EN | RCC_APB1ENR1_DAC1EN | RCC_APB1ENR1_I2C1EN);
|
||||
RCC->APB2ENR |= (RCC_APB2ENR_TIM1EN | RCC_APB2ENR_USART1EN);
|
||||
|
|
|
@ -11,5 +11,6 @@
|
|||
void system_clock_update_l4(void); // SystemCoreClockUpdateL4
|
||||
int system_clock_configure_l4(void); // SystemClock_Config_L4
|
||||
int system_clock_configure_rtc_l4(void);
|
||||
void system_clock_configure_auto_wakeup_l4(uint16_t seconds);
|
||||
|
||||
#endif /* INCLUDE_CMSIS_STM32L4XX_SYSTEM_STM32L4XX_H_ */
|
||||
|
|
|
@ -482,25 +482,43 @@ int system_clock_configure_rtc_l4(void) {
|
|||
// exit RTC set mode
|
||||
RTC->ISR &= (0xFFFFFFFF ^ RTC_ISR_INIT);
|
||||
|
||||
// disable wakeup timer
|
||||
RTC->CR &= (0xFFFFFFFF ^ RTC_CR_WUTE);
|
||||
|
||||
// wait for wakeup timer to disable
|
||||
while((RTC->ISR & RTC_ISR_WUTWF) == 0);
|
||||
|
||||
// set the source clock for RTC as CK_SPRE
|
||||
// set the source clock for RTC wakeup as CK_SPRE
|
||||
RTC->CR |= RTC_CR_WUCKSEL_2;
|
||||
|
||||
// set auto wakeup every 300 seconds
|
||||
RTC->WUTR = 300;
|
||||
|
||||
// start wakeup timer once again
|
||||
RTC->CR |= RTC_CR_WUTE;
|
||||
|
||||
// enabling wakeup interrupt
|
||||
RTC->CR |= RTC_CR_WUTIE;
|
||||
}
|
||||
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void system_clock_configure_auto_wakeup_l4(uint16_t seconds) {
|
||||
|
||||
// enable access to backup domain
|
||||
PWR->CR1 |= PWR_CR1_DBP;
|
||||
|
||||
// enable write access to RTC registers by writing two magic words
|
||||
RTC->WPR = 0xCA;
|
||||
RTC->WPR = 0x53;
|
||||
|
||||
// disable wakeup timer
|
||||
RTC->CR &= (0xFFFFFFFF ^ RTC_CR_WUTE);
|
||||
|
||||
// wait for wakeup timer to disable
|
||||
while((RTC->ISR & RTC_ISR_WUTWF) == 0);
|
||||
|
||||
// clear wakeup flag
|
||||
RTC->ISR &= (0xFFFFFFFF ^ RTC_ISR_WUTF_Msk);
|
||||
|
||||
// set auto wakeup timer
|
||||
RTC->WUTR = seconds;
|
||||
|
||||
// start wakeup timer once again
|
||||
RTC->CR |= RTC_CR_WUTE;
|
||||
|
||||
// enabling wakeup interrupt
|
||||
RTC->CR |= RTC_CR_WUTIE;
|
||||
|
||||
// enable 20th EXTI Line (RTC wakeup timer)
|
||||
EXTI->IMR1 |= EXTI_IMR1_IM20;
|
||||
|
||||
|
@ -510,17 +528,8 @@ int system_clock_configure_rtc_l4(void) {
|
|||
// by enabling this all pending interrupt will wake up cpu from low-power mode, even from those disabled in NVIC
|
||||
SCB->SCR |= SCB_SCR_SEVONPEND_Msk;
|
||||
|
||||
// enable write access to RTC registers by writing two magic words (in case that backup domain hasn't been reseted
|
||||
RTC->WPR = 0xCA;
|
||||
RTC->WPR = 0x53;
|
||||
|
||||
RTC->ISR &= (0xFFFFFFFF ^ RTC_ISR_WUTF_Msk);
|
||||
|
||||
// enable wakeup interrupt
|
||||
NVIC_EnableIRQ(RTC_WKUP_IRQn);
|
||||
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue