Skip to main content
Explorer
August 21, 2025
Solved

STM32L053 LSE CSS not trigger

  • August 21, 2025
  • 3 replies
  • 766 views

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.

ShimiaoWang_0-1755742211333.png

 

    This topic has been closed for replies.
    Best answer by Simon V.

    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

    3 replies

    Super User
    August 21, 2025

    RTC_IRQHandler is not the handler for the CSS.

     

    Is the interrupt enabled?

    TDK_0-1755743414420.png

     

    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.

    Explorer
    August 21, 2025

    Thank you for your reply

    RTC interrupt has been enabled.

    ShimiaoWang_0-1755744799651.pngShimiaoWang_1-1755744816214.png

    HAL_RCCEx_LSECSS_IRQHandler  in the HAL library.

    ShimiaoWang_2-1755744936729.png

     

    Super User
    August 21, 2025

    I don't see how the RTC or its interrupt is relevant here. Maybe I'm missing something.

    ST Employee
    August 22, 2025

    Hello @ShimiaoWang,

    This post has been escalated to the ST Online Support Team for additional assistance. We'll contact you directly.

    Best regards,
    Maxime

    Simon V.Answer
    ST Employee
    August 26, 2025

    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

    Explorer
    August 27, 2025

    Hi,Simon

     

    Thank you very much, I have successfully triggered the RTC CSSLSE interrupt.