RTC. Added possibility of changing RTC clock source.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3809 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
685286c5c8
commit
a41f12ad8a
|
@ -101,6 +101,10 @@ CH_IRQ_HANDLER(RTC_IRQHandler) {
|
||||||
|
|
||||||
CH_IRQ_PROLOGUE();
|
CH_IRQ_PROLOGUE();
|
||||||
|
|
||||||
|
/* This wait works only when AHB1 bus was previously powered off by any
|
||||||
|
reason (standby, reset, etc). In other cases it does nothing.*/
|
||||||
|
rtc_lld_apb1_sync();
|
||||||
|
|
||||||
/* Mask of all enabled and pending sources.*/
|
/* Mask of all enabled and pending sources.*/
|
||||||
flags = RTC->CRH & RTC->CRL;
|
flags = RTC->CRH & RTC->CRL;
|
||||||
RTC->CRL &= ~(RTC_CRL_SECF | RTC_CRL_ALRF | RTC_CRL_OWF);
|
RTC->CRL &= ~(RTC_CRL_SECF | RTC_CRL_ALRF | RTC_CRL_OWF);
|
||||||
|
|
|
@ -43,22 +43,25 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initializes the backup domain.
|
* @brief Initializes the backup domain.
|
||||||
|
* @note WARNING! Changing clock source impossible without resetting
|
||||||
|
* of the whole BKP domain.
|
||||||
*/
|
*/
|
||||||
static void hal_lld_backup_domain_init(void) {
|
static void hal_lld_backup_domain_init(void) {
|
||||||
|
|
||||||
/* Backup domain access enabled and left open.*/
|
/* Backup domain access enabled and left open.*/
|
||||||
PWR->CR = PWR_CR_DBP;
|
PWR->CR |= PWR_CR_DBP;
|
||||||
|
|
||||||
|
/* Reset BKP domain if different clock source selected.*/
|
||||||
|
if ((RCC->BDCR & STM32_RTCSEL_MSK) != STM32_RTCSEL){
|
||||||
|
RCC->BDCR = RCC_BDCR_BDRST;
|
||||||
|
RCC->BDCR = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* If enabled then the LSE is started.*/
|
/* If enabled then the LSE is started.*/
|
||||||
#if STM32_LSE_ENABLED
|
#if STM32_LSE_ENABLED
|
||||||
if ((RCC->BDCR & RCC_BDCR_LSEON) == 0) {
|
RCC->BDCR |= RCC_BDCR_LSEON;
|
||||||
/* Backup domain reset.*/
|
while ((RCC->BDCR & RCC_BDCR_LSERDY) == 0)
|
||||||
RCC->BDCR = RCC_BDCR_BDRST;
|
; /* Waits until LSE is stable. */
|
||||||
RCC->BDCR = 0;
|
|
||||||
RCC->BDCR = RCC_BDCR_LSEON;
|
|
||||||
while ((RCC->BDCR & RCC_BDCR_LSERDY) == 0)
|
|
||||||
; /* Waits until LSE is stable. */
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if STM32_RTCSEL != STM32_RTCSEL_NOCLOCK
|
#if STM32_RTCSEL != STM32_RTCSEL_NOCLOCK
|
||||||
|
@ -66,7 +69,7 @@ static void hal_lld_backup_domain_init(void) {
|
||||||
initialization.*/
|
initialization.*/
|
||||||
if ((RCC->BDCR & RCC_BDCR_RTCEN) == 0) {
|
if ((RCC->BDCR & RCC_BDCR_RTCEN) == 0) {
|
||||||
/* Selects clock source.*/
|
/* Selects clock source.*/
|
||||||
RCC->BDCR = (RCC->BDCR & ~RCC_BDCR_RTCSEL) | STM32_RTCSEL;
|
RCC->BDCR |= STM32_RTCSEL;
|
||||||
|
|
||||||
/* RTC clock enabled.*/
|
/* RTC clock enabled.*/
|
||||||
RCC->BDCR |= RCC_BDCR_RTCEN;
|
RCC->BDCR |= RCC_BDCR_RTCEN;
|
||||||
|
@ -213,7 +216,7 @@ void stm32_clock_init(void) {
|
||||||
/* HSE activation.*/
|
/* HSE activation.*/
|
||||||
RCC->CR |= RCC_CR_HSEON;
|
RCC->CR |= RCC_CR_HSEON;
|
||||||
while (!(RCC->CR & RCC_CR_HSERDY))
|
while (!(RCC->CR & RCC_CR_HSERDY))
|
||||||
; /* Waits until HSE is stable. */
|
; /* Waits until HSE is stable. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if STM32_LSI_ENABLED
|
#if STM32_LSI_ENABLED
|
||||||
|
@ -231,14 +234,14 @@ void stm32_clock_init(void) {
|
||||||
#if STM32_ACTIVATE_PLL2
|
#if STM32_ACTIVATE_PLL2
|
||||||
RCC->CR |= RCC_CR_PLL2ON;
|
RCC->CR |= RCC_CR_PLL2ON;
|
||||||
while (!(RCC->CR & RCC_CR_PLL2RDY))
|
while (!(RCC->CR & RCC_CR_PLL2RDY))
|
||||||
; /* Waits until PLL2 is stable. */
|
; /* Waits until PLL2 is stable. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* PLL3 setup, if activated.*/
|
/* PLL3 setup, if activated.*/
|
||||||
#if STM32_ACTIVATE_PLL3
|
#if STM32_ACTIVATE_PLL3
|
||||||
RCC->CR |= RCC_CR_PLL3ON;
|
RCC->CR |= RCC_CR_PLL3ON;
|
||||||
while (!(RCC->CR & RCC_CR_PLL3RDY))
|
while (!(RCC->CR & RCC_CR_PLL3RDY))
|
||||||
; /* Waits until PLL3 is stable. */
|
; /* Waits until PLL3 is stable. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* PLL1 setup, if activated.*/
|
/* PLL1 setup, if activated.*/
|
||||||
|
|
|
@ -174,6 +174,7 @@
|
||||||
#define STM32_RTCSEL_LSI (2 << 8) /**< LSI used as RTC clock. */
|
#define STM32_RTCSEL_LSI (2 << 8) /**< LSI used as RTC clock. */
|
||||||
#define STM32_RTCSEL_HSEDIV (3 << 8) /**< HSE divided by 128 used as
|
#define STM32_RTCSEL_HSEDIV (3 << 8) /**< HSE divided by 128 used as
|
||||||
RTC clock. */
|
RTC clock. */
|
||||||
|
#define STM32_RTCSEL_MSK (3 << 8) /**< RTC clock source mask. */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
|
@ -184,6 +184,7 @@
|
||||||
#define STM32_RTCSEL_LSI (2 << 8) /**< LSI used as RTC clock. */
|
#define STM32_RTCSEL_LSI (2 << 8) /**< LSI used as RTC clock. */
|
||||||
#define STM32_RTCSEL_HSEDIV (3 << 8) /**< HSE divided by 128 used as
|
#define STM32_RTCSEL_HSEDIV (3 << 8) /**< HSE divided by 128 used as
|
||||||
RTC clock. */
|
RTC clock. */
|
||||||
|
#define STM32_RTCSEL_MSK (3 << 8) /**< RTC clock source mask. */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
|
@ -194,6 +194,7 @@
|
||||||
#define STM32_RTCSEL_LSI (2 << 8) /**< LSI used as RTC clock. */
|
#define STM32_RTCSEL_LSI (2 << 8) /**< LSI used as RTC clock. */
|
||||||
#define STM32_RTCSEL_HSEDIV (3 << 8) /**< HSE divided by 128 used as
|
#define STM32_RTCSEL_HSEDIV (3 << 8) /**< HSE divided by 128 used as
|
||||||
RTC clock. */
|
RTC clock. */
|
||||||
|
#define STM32_RTCSEL_MSK (3 << 8) /**< RTC clock source mask. */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,13 +26,8 @@ RTCAlarm alarmspec;
|
||||||
|
|
||||||
#define TEST_ALARM_WAKEUP FALSE
|
#define TEST_ALARM_WAKEUP FALSE
|
||||||
|
|
||||||
#if TEST_ALARM_WAKEUP
|
|
||||||
|
|
||||||
static void my_cb(RTCDriver *rtcp, rtcevent_t event) {
|
#if TEST_ALARM_WAKEUP
|
||||||
(void)rtcp;
|
|
||||||
(void)event;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* sleep indicator thread */
|
/* sleep indicator thread */
|
||||||
static WORKING_AREA(blinkWA, 128);
|
static WORKING_AREA(blinkWA, 128);
|
||||||
|
@ -55,9 +50,6 @@ int main(void) {
|
||||||
alarmspec.tv_sec = timespec.tv_sec + 30;
|
alarmspec.tv_sec = timespec.tv_sec + 30;
|
||||||
rtcSetAlarm(&RTCD1, 0, &alarmspec);
|
rtcSetAlarm(&RTCD1, 0, &alarmspec);
|
||||||
|
|
||||||
/* Needed just to switch interrupts on.*/
|
|
||||||
rtcSetCallback(&RTCD1, my_cb);
|
|
||||||
|
|
||||||
while (TRUE){
|
while (TRUE){
|
||||||
chThdSleepSeconds(10);
|
chThdSleepSeconds(10);
|
||||||
chSysLock();
|
chSysLock();
|
||||||
|
|
Loading…
Reference in New Issue