wakeup timer configuration moved to separate function

pull/7/head
Mateusz Lubecki 2021-08-22 12:13:12 +02:00
rodzic 7f66de28ce
commit 0d8a02e7fb
4 zmienionych plików z 37 dodań i 25 usunięć

Wyświetl plik

@ -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="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;peripherals&gt;&#10; &lt;peripheral name=&quot;RCC&quot;/&gt;&#10; &lt;peripheral name=&quot;PWR&quot;/&gt;&#10; &lt;peripheral name=&quot;RTC&quot;/&gt;&#10; &lt;peripheral name=&quot;EXTI&quot;/&gt;&#10;&lt;/peripherals&gt;&#10;"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.PERIPHERALS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;peripherals&gt;&#10; &lt;peripheral name=&quot;RTC&quot;/&gt;&#10;&lt;/peripherals&gt;&#10;"/>
<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"/>

Wyświetl plik

@ -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);

Wyświetl plik

@ -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_ */

Wyświetl plik

@ -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;
}