HAL RTC driver doesn't set RTC Clock Select bits in RCC_BDCR register.
I am using the stm32f7xx_hal_rtc.c driver to initialize the RTC. I have configured the high speed clock source as the external crystal (HSE) and I have configured the low speed (32 KHz) clock source as the external crystal (LSE). Prior to calling the HAL_RTC_Init routine to initialize the RTC, I read the contents of the RCC_CR and RCC_BDCR registers. The bits in these registers are as follows:
RCC_CR = 0x0003 3483 which means the following bits are set:
HSEON, HSIRDY, HSITRIM=0x10, HSICAL=0x84, HSEON, HSERDY
All of the other bits are clear.
RCC_BDCR = 0x0000 8003 which means the following bits are set:
LSEON, LSIRDY, RTCEN
All of the other bits are clear.
After analyzing the bits in the RCC_BDCR register, I have several questions. Most importantly, while the RTCEN bit is set, the RTCSEL (clock source select bits) are 00 which specifies no clock source selected. The bits should be 01 which specifies the LSE as the clock source.
Also, in spite of the fact that the LSERDY is set in the RCC_CR register, I do not see any sine wave signal when probing the 32 KHz crystal!!
The HAL_EnterInitMode routine hangs when waiting for the RTC_ISR_INITF flag to be set. The routine times out and takes the error exit. I am suspecting that the reason that the RTC initalization is failing is that there is no clock source selected for the RTC.
HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc)
{
uint32_t tickstart = 0;
/* Check if the Initialization mode is set */
if((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
{
/* Set the Initialization mode */
hrtc->Instance->ISR = (uint32_t)RTC_INIT_MASK;
/* Get tick */
tickstart = HAL_GetTick();
/* Wait till RTC is in INIT state and if Time out is reached exit */
while((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
{
if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}
}
}
Any help with either of these issues would be appreciated.
