diff --git a/arch/arm/src/stm32/stm32_rcc.c b/arch/arm/src/stm32/stm32_rcc.c index 87afb59d3af..5fd2ffb8c7e 100644 --- a/arch/arm/src/stm32/stm32_rcc.c +++ b/arch/arm/src/stm32/stm32_rcc.c @@ -101,6 +101,53 @@ # define RCC_XXX_YYYRST RCC_BDCR_BDRST #endif +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/************************************************************************************ + * Name: rcc_enablebkp + * + * Description: + * The RTC needs to reset the Backup Domain to change RTCSEL and resetting the + * Backup Domain renders to disabling the LSE as consequence. In order to avoid + * resetting the Backup Domain when we already configured LSE we will reset the + * Backup Domain early (here). + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ************************************************************************************/ + +#ifdef CONFIG_STM32_PWR +static inline rcc_enablebkp(void) +{ + uint32_t regval; + + /* Check if the RTC is already configured */ + + regval = getreg32(RTC_MAGIC_REG); + if (regval != RTC_MAGIC) + { + (void)stm32_pwr_enablebkp(true); + + /* We might be changing RTCSEL - to ensure such changes work, we must + * reset the backup domain (having backed up the RTC_MAGIC token) + */ + + modifyreg32(STM32_RCC_XXX, 0, RCC_XXX_YYYRST); + modifyreg32(STM32_RCC_XXX, RCC_XXX_YYYRST, 0); + + (void)stm32_pwr_enablebkp(false); + } +} +#else +# define rcc_enablebkp() +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -134,28 +181,9 @@ void stm32_clockconfig(void) rcc_reset(); - /* The RTC needs to reset the Backup Domain to change RTCSEL and resetting the - * Backup Domain renders to disabling the LSE as consequence. In order to avoid - * resetting the Backup Domain when we already configured LSE we will reset the - * Backup Domain early (here). - */ + /* Reset backup domain */ - /* Check if the RTC is already configured */ - - regval = getreg32(RTC_MAGIC_REG); - if (regval != RTC_MAGIC) - { - (void)stm32_pwr_enablebkp(true); - - /* We might be changing RTCSEL - to ensure such changes work, we must - * reset the backup domain (having backed up the RTC_MAGIC token) - */ - - modifyreg32(STM32_RCC_XXX, 0, RCC_XXX_YYYRST); - modifyreg32(STM32_RCC_XXX, RCC_XXX_YYYRST, 0); - - (void)stm32_pwr_enablebkp(false); - } + rcc_enablebkp(); #if defined(CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG)