diff --git a/arch/arm/src/stm32/stm32_irq.c b/arch/arm/src/stm32/stm32_irq.c index 0f9553210a..98adf74f36 100644 --- a/arch/arm/src/stm32/stm32_irq.c +++ b/arch/arm/src/stm32/stm32_irq.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/stm32/stm32_irq.c * - * Copyright (C) 2009-2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -389,6 +389,7 @@ void up_irqinitialize(void) #ifdef CONFIG_RTC /* RTC was initialized earlier but IRQs weren't ready at that time */ + stm32_rtc_irqinitialize(); #endif diff --git a/arch/arm/src/stm32/stm32_rtc.h b/arch/arm/src/stm32/stm32_rtc.h index 0c4e5ecbf3..6271a97ed7 100644 --- a/arch/arm/src/stm32/stm32_rtc.h +++ b/arch/arm/src/stm32/stm32_rtc.h @@ -2,7 +2,7 @@ * arch/arm/src/stm32/stm32_rtc.h * * Copyright (C) 2011 Uros Platise. All rights reserved. - * Copyright (C) 2011-2013, 2015-2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2013, 2015-2017 Gregory Nutt. All rights reserved. * Author: Uros Platise (Original for the F1) * Gregory Nutt (On-going support and development) * @@ -76,37 +76,40 @@ * Pre-processor Definitions ****************************************************************************/ -#define STM32_RTC_PRESCALER_SECOND 32767 /* Default prescaler to get a second base */ -#define STM32_RTC_PRESCALER_MIN 1 /* Maximum speed of 16384 Hz */ +#define STM32_RTC_PRESCALER_SECOND 32767 /* Default prescaler to get a + * second base */ +#define STM32_RTC_PRESCALER_MIN 1 /* Maximum speed of 16384 Hz */ #if defined(CONFIG_STM32_STM32F10XX) -/* RTC is only a counter, store RTC data in backup domain register DR1 (if CONFIG_RTC_HIRES) and DR2 (state) */ +/* RTC is only a counter, store RTC data in backup domain register DR1 (if + * CONFIG_RTC_HIRES) and DR2 (state). + */ #if !defined(CONFIG_RTC_MAGIC) -# define CONFIG_RTC_MAGIC (0xface) /* only 16 bit */ +# define CONFIG_RTC_MAGIC (0xface) /* only 16 bit */ #endif -#define RTC_MAGIC_REG STM32_BKP_DR2 +#define RTC_MAGIC_REG STM32_BKP_DR2 #else /* !CONFIG_STM32_STM32F10XX */ #if !defined(CONFIG_RTC_MAGIC) -# define CONFIG_RTC_MAGIC (0xfacefeee) +# define CONFIG_RTC_MAGIC (0xfacefeee) #endif #if !defined(CONFIG_RTC_MAGIC_REG) -# define CONFIG_RTC_MAGIC_REG (0) +# define CONFIG_RTC_MAGIC_REG (0) #endif -#define RTC_MAGIC_REG STM32_RTC_BKR(CONFIG_RTC_MAGIC_REG) +#define RTC_MAGIC_REG STM32_RTC_BKR(CONFIG_RTC_MAGIC_REG) #endif /* CONFIG_STM32_STM32F10XX */ -#define RTC_MAGIC CONFIG_RTC_MAGIC -#define RTC_MAGIC_TIME_SET CONFIG_RTC_MAGIC_TIME_SET +#define RTC_MAGIC CONFIG_RTC_MAGIC +#define RTC_MAGIC_TIME_SET CONFIG_RTC_MAGIC_TIME_SET #if !defined(CONFIG_RTC_MAGIC_TIME_SET) -# define CONFIG_RTC_MAGIC_TIME_SET (CONFIG_RTC_MAGIC + 1) +# define CONFIG_RTC_MAGIC_TIME_SET (CONFIG_RTC_MAGIC + 1) #endif /**************************************************************************** diff --git a/arch/arm/src/stm32/stm32_rtcc.c b/arch/arm/src/stm32/stm32_rtcc.c index b7c96f336a..1e03d89ba1 100644 --- a/arch/arm/src/stm32/stm32_rtcc.c +++ b/arch/arm/src/stm32/stm32_rtcc.c @@ -1,7 +1,7 @@ /************************************************************************************ * arch/arm/src/stm32/stm32_rtcc.c * - * Copyright (C) 2012-2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -788,7 +788,7 @@ int stm32_rtc_irqinitialize(void) #ifdef CONFIG_RTC_ALARM # warning "Missing EXTI setup logic" - /* then attach the ALARM interrupt handler */ + /* Attach the ALARM interrupt handler */ irq_attach(STM32_IRQ_RTC_WKUP, rtc_interrupt, NULL); up_enable_irq(STM32_IRQ_RTC_WKUP); diff --git a/arch/arm/src/stm32/stm32_rtcounter.c b/arch/arm/src/stm32/stm32_rtcounter.c index 5db3865c0d..b42740b0e1 100644 --- a/arch/arm/src/stm32/stm32_rtcounter.c +++ b/arch/arm/src/stm32/stm32_rtcounter.c @@ -6,7 +6,7 @@ * * With extensions, modifications by: * - * Copyright (C) 2011-2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2013, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregroy Nutt * * Redistribution and use in source and binary forms, with or without @@ -384,21 +384,22 @@ int up_rtc_initialize(void) stm32_pwr_enablebkp(true); regval = getreg32(RTC_MAGIC_REG); - if (regval != RTC_MAGIC && regval != RTC_MAGIC_TIME_SET) { - /* reset backup domain if bad magic */ + /* Reset backup domain if bad magic */ + modifyreg32(STM32_RCC_BDCR, 0, RCC_BDCR_BDRST); modifyreg32(STM32_RCC_BDCR, RCC_BDCR_BDRST, 0); putreg16(RTC_MAGIC, RTC_MAGIC_REG); } /* Select the lower power external 32,768Hz (Low-Speed External, LSE) oscillator - * as RTC Clock Source and enable the Clock */ + * as RTC Clock Source and enable the Clock. + */ modifyreg16(STM32_RCC_BDCR, RCC_BDCR_RTCSEL_MASK, RCC_BDCR_RTCSEL_LSE); - /* enable RTC and wait for RSF */ + /* Enable RTC and wait for RSF */ modifyreg16(STM32_RCC_BDCR, 0, RCC_BDCR_RTCEN); @@ -416,7 +417,10 @@ int up_rtc_initialize(void) stm32_rtc_wait4rsf(); #ifdef CONFIG_RTC_HIRES - /* enable overflow interrupt - alarm interrupt is enabled in stm32_rtc_setalarm */ + /* Enable overflow interrupt - alarm interrupt is enabled in + * stm32_rtc_setalarm. + */ + modifyreg16(STM32_RTC_CRH, 0, RTC_CRH_OWIE); #endif @@ -457,9 +461,9 @@ int up_rtc_initialize(void) int stm32_rtc_irqinitialize(void) { +#if defined(CONFIG_RTC_HIRES) || defined(CONFIG_RTC_ALARM) /* Configure RTC interrupt to catch overflow and alarm interrupts. */ -#if defined(CONFIG_RTC_HIRES) || defined(CONFIG_RTC_ALARM) irq_attach(STM32_IRQ_RTC, stm32_rtc_interrupt, NULL); up_enable_irq(STM32_IRQ_RTC); #endif diff --git a/arch/arm/src/stm32/stm32f40xxx_rtcc.c b/arch/arm/src/stm32/stm32f40xxx_rtcc.c index 751989b487..a2af73794e 100644 --- a/arch/arm/src/stm32/stm32f40xxx_rtcc.c +++ b/arch/arm/src/stm32/stm32f40xxx_rtcc.c @@ -1075,7 +1075,8 @@ int up_rtc_initialize(void) int stm32_rtc_irqinitialize(void) { - /* nothing to do */ + /* Nothing to do */ + return OK; } diff --git a/arch/arm/src/stm32l4/stm32l4_rtcc.c b/arch/arm/src/stm32l4/stm32l4_rtcc.c index 9ca5c7b9f8..05f4ff5ae2 100644 --- a/arch/arm/src/stm32l4/stm32l4_rtcc.c +++ b/arch/arm/src/stm32l4/stm32l4_rtcc.c @@ -1,7 +1,7 @@ /************************************************************************************ * arch/arm/src/stm32l4/stm32l4_rtcc.c * - * Copyright (C) 2012-2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * dev@ziggurat29.com (adaptations to stm32l4) * @@ -1020,7 +1020,8 @@ int up_rtc_initialize(void) int stm32_rtc_irqinitialize(void) { - /* nothing to do */ + /* Nothing to do */ + return OK; }