cancel
Showing results for 
Search instead for 
Did you mean: 

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

ChrisK1
Associate II

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!

 

1 REPLY 1
Roger SHIVELY
ST Employee

Hello @ChrisK1 ,

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

Regards,
Roger