STM32L4: Add logic reset backup domain early in initialization

This commit is contained in:
Alan Carvalho de Assis 2016-06-16 13:43:09 -06:00 committed by Gregory Nutt
parent 865150f666
commit dd7297fb64
3 changed files with 73 additions and 9 deletions

View File

@ -89,7 +89,58 @@
****************************************************************************/
/************************************************************************************
* Name: stm32l4_clockconfig
* Name: rcc_resetbkp
*
* 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
*
************************************************************************************/
#if defined(CONFIG_STM32_PWR) && defined(CONFIG_RTC)
static inline rcc_resetbkp(void)
{
bool init_stat;
/* Check if the RTC is already configured */
init_stat = rtc_is_inits();
if(!init_stat)
{
/* Enable write access to the backup domain (RTC registers, RTC
* backup data registers and backup SRAM).
*/
(void)stm32l4_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(STM32L4_RCC_BDCR, 0, RCC_BDCR_BDRST);
modifyreg32(STM32L4_RCC_BDCR, RCC_BDCR_BDRST, 0);
(void)stm32l4_pwr_enablebkp(false);
}
}
#else
# define rcc_resetbkp()
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/************************************************************************************
* Name: stm32_clockconfig
*
* Description:
* Called to establish the clock settings based on the values in board.h. This

View File

@ -105,6 +105,26 @@ extern "C"
* Public Functions
****************************************************************************/
/************************************************************************************
* Name: rtc_is_inits
*
* Description:
* Returns 'true' if the RTC has been initialized (according to the RTC itself).
* It will be 'false' if the RTC has never been initialized since first time power
* up, and the counters are stopped until it is first initialized.
*
* Input Parameters:
* None
*
* Returned Value:
* bool -- true if the INITS flag is set in the ISR.
*
************************************************************************************/
#ifdef CONFIG_RTC_DRIVER
bool rtc_is_inits(void);
#endif
/****************************************************************************
* Name: stm32l4_rtc_getdatetime_with_subseconds
*

View File

@ -250,7 +250,7 @@ static void rtc_dumptime(FAR const struct tm *tp, FAR const char *msg)
*
************************************************************************************/
static bool rtc_is_inits(void)
bool rtc_is_inits(void)
{
uint32_t regval;
@ -832,13 +832,6 @@ int up_rtc_initialize(void)
(void)stm32l4_pwr_enablebkp(true);
#if 0
/* Do not reset the backup domain; you will lose your clock setup done in *rcc.c */
modifyreg32(STM32L4_RCC_BDCR, 0, RCC_BDCR_BDRST);
modifyreg32(STM32L4_RCC_BDCR, RCC_BDCR_BDRST, 0);
#endif
#if defined(CONFIG_STM32L4_RTC_HSECLOCK)
modifyreg32(STM32L4_RCC_BDCR, RCC_BDCR_RTCSEL_MASK, RCC_BDCR_RTCSEL_HSE);
#elif defined(CONFIG_STM32L4_RTC_LSICLOCK)