cancel
Showing results for 
Search instead for 
Did you mean: 

RTC_EnterInitMode(hrtc) returns HAL_TIMEOUT. LSEState is ON and HAL_PWR_EnableBkUpAccess() is also called. How to solve this issue?

RVarg.1
Associate

HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc) function returns HAL_ERROR because RTC_EnterInitMode(hrtc) returns HAL_TIMEOUT. When checked in community, I can see solutions as to call HAL_PWR_EnableBkUpAccess(); before setting RTC functions. IT is provided in SystemClock_Config() as shown below

void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct = {0};

RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

/** Configure the main internal regulator output voltage

*/

__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

/** Configure LSE Drive Capability

*/

HAL_PWR_EnableBkUpAccess();

__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);

/** Initializes the CPU, AHB and APB busses clocks

*/

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;

RCC_OscInitStruct.LSEState = RCC_LSE_ON;

RCC_OscInitStruct.MSIState = RCC_MSI_ON;

RCC_OscInitStruct.MSICalibrationValue = 0;

RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_5;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

{

Error_Handler();

}

/** Initializes the CPU, AHB and APB busses clocks

*/

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;

RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)

{

Error_Handler();

}

PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USART2

|RCC_PERIPHCLK_I2C3|RCC_PERIPHCLK_RTC;

PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;

PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;

PeriphClkInit.I2c3ClockSelection = RCC_I2C3CLKSOURCE_PCLK1;

PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;

if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

{

Error_Handler();

}

}

What else could be the reason for TimeOut in RTC_EnterInitMode(hrtc) ?

3 REPLIES 3

Which STM32?

RTC clock is enabled in RCC (usually RCC_BDTR)?

You can try to enter the Init mode of RTC manually in debugger, as described in RTC initialization and configuration subchapter of RTC chapter in RM. That should show you the steps needed for this, you can then duplicate them in your own routine, or use that knowledge to debug the Cube-based code.

JW

RVarg.1
Associate

Hi,

Sorry, I did not include the MCU. It is STM32L072RZT6.

Check LSERDY, RTCSEL and RTCEN in RCC_CSR.

And then try to manipulate the RTC registers as I've outlined above.

JW