cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L053 LSE CSS not trigger

ShimiaoWang
Associate II

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Simon V.
ST Employee

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.

View solution in original post

7 REPLIES 7
TDK
Super User

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.

If you feel a post has answered your question, please click "Accept as Solution".

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

 

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

If you feel a post has answered your question, please click "Accept as Solution".

I checked the manual. CSS_LSE IT is mapped on RTC EXTI line 19.So I enabled the RTC interrupt. 

ShimiaoWang_0-1755745793455.png

I also tried to open this interrupt, but cannot be triggered.

ShimiaoWang_1-1755746048208.png

ShimiaoWang_2-1755746060026.png

 

Maxime_MARCHETTO
Community manager
Community manager

Hello @ShimiaoWang,

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

Best regards,
Maxime


In order 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.
Simon V.
ST Employee

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.

Hi,Simon

 

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