2025-08-20 7:20 PM
I tested the LSE CSS function on the Nucleo-L053, but I found that short-circuiting the crystal oscillator pins failed to trigger the CSS interrupt. The code configuration is as follows
plz give a clue or the flow of LSECSS
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 RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_4;
RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
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_1) != HAL_OK)
{
Error_Handler();
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2|RCC_PERIPHCLK_RTC;
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/** Enables the Clock Security System
*/
HAL_RCCEx_EnableLSECSS_IT();
HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_LSE, RCC_MCODIV_1);
}
void RTC_IRQHandler(void)
{
/* USER CODE BEGIN RTC_IRQn 0 */
HAL_RCCEx_LSECSS_IRQHandler();
/* USER CODE END RTC_IRQn 0 */
HAL_RTC_AlarmIRQHandler(&hrtc);
/* USER CODE BEGIN RTC_IRQn 1 */
/* USER CODE END RTC_IRQn 1 */
}
void HAL_RCCEx_LSECSS_Callback(void)
{
printf("LSE CSS\r\n");
}
No print output was observed when the crystal oscillator was short-circuited, and debugging showed that the interrupt service routine was not entered.
Solved! Go to Solution.
2025-08-26 7:30 AM
Hello,
LSI oscillator must be enabled as described in the product RM manual :
CSSLSEON must be enabled after the LSE and LSI oscillators are enabled (LSEON and
LSION bits enabled) and ready (LSERDY and LSIRDY flags set by hardware).
After adding LSION to your code example, the STM32L0 was able to trigger the RTC CSSLSE interrupt
Regards,
Simon
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-08-20 7:32 PM
RTC_IRQHandler is not the handler for the CSS.
Is the interrupt enabled?
Should be a HAL_NVIC_EnableIRQ call somewhere. It's not in the code you presented.
Is HAL_RCCEx_LSECSS_IRQHandler defined? It's not in the code you presented.
2025-08-20 7:56 PM
Thank you for your reply
RTC interrupt has been enabled.
HAL_RCCEx_LSECSS_IRQHandler in the HAL library.
2025-08-20 8:03 PM - edited 2025-08-20 8:07 PM
I don't see how the RTC or its interrupt is relevant here. Maybe I'm missing something.
2025-08-20 8:16 PM
I checked the manual. CSS_LSE IT is mapped on RTC EXTI line 19.So I enabled the RTC interrupt.
I also tried to open this interrupt, but cannot be triggered.
2025-08-22 12:32 AM
Hello @ShimiaoWang,
This post has been escalated to the ST Online Support Team for additional assistance. We'll contact you directly.
Best regards,
Maxime
2025-08-26 7:30 AM
Hello,
LSI oscillator must be enabled as described in the product RM manual :
CSSLSEON must be enabled after the LSE and LSI oscillators are enabled (LSEON and
LSION bits enabled) and ready (LSERDY and LSIRDY flags set by hardware).
After adding LSION to your code example, the STM32L0 was able to trigger the RTC CSSLSE interrupt
Regards,
Simon
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-08-26 6:29 PM
Hi,Simon
Thank you very much, I have successfully triggered the RTC CSSLSE interrupt.