Skip to main content
Associate
November 17, 2023
Question

How to have full control over RTC and LSE with HAL lib only (not including LL lib)

  • November 17, 2023
  • 1 reply
  • 1185 views

In my project it can happen, that the LSE gets blocked due to a CSS failure detection after repowering. I found this good article on the ST community which maches alomost with my case: https://community.st.com/t5/stm32-mcus-products/lse-fault-recovery/td-p/349861

It uses the following code to solve the problem:

void HAL_RCCEx_LSECSS_Callback(void)
{
if(__HAL_RCC_LSECSS_EXTI_GET_FLAG() || __HAL_RCC_GET_FLAG(RCC_FLAG_LSECSSD))
{
HAL_PWR_EnableBkUpAccess();
HAL_RCCEx_DisableLSECSS();
__HAL_RCC_LSECSS_EXTI_DISABLE_IT();
LL_RCC_LSE_Disable();

if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_LSE)
{
__HAL_RCC_RTC_DISABLE();
__HAL_RCC_BACKUPRESET_FORCE();
__HAL_RCC_BACKUPRESET_RELEASE();
LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSI);
LL_RCC_EnableRTC();
MX_RTC_Init();
}

__HAL_RCC_LSECSS_EXTI_CLEAR_FLAG();
}
}

This works fine, as long as I could include both HAL and LL driver libraries.
Bute CubeMX doesn't allow for this. You can either choose HAL or LL drivers.

Then I searched for the HAL-functions corresponding the LL-functions in the HAL library but didn't find any.
Our code should be protable to other STM MCUs so I would prefer to use HAL.

Is there a possibility I did not see that provides the same functionality from HAL as

  • LL_RCC_LSE_Disable();
  • LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSI);
  • LL_RCC_EnableRTC();

Thanks for your ideas!

 

This topic has been closed for replies.

1 reply

Roger SHIVELY
ST Employee
November 20, 2023

Hello @ChrisK1 ,

There has been a case created to resolve this question and we will be reaching out to you directly.

Regards,
Roger