2025-03-13 8:01 AM
Hi ST community,
I'm working on a project using an STM32WB55VGY, with the base code generated by STM32CubeMX v6.13.0 and HAL drivers v1.21.0.
We aim to enable HSE and LSE Clock Security System (CSS) to detect clock failures and put the device into an error mode (e.g., turning on an LED when an error occurs). However, when testing LSECSS with an interrupt, I noticed that the callback function is never triggered.
Here is the code I have implemented:
Init:
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Config code for STM32_WPAN (HSE Tuning must be done before system clock configuration) */
MX_APPE_Config();
/* USER CODE BEGIN Init */
#ifdef DBG_RTT
log_init();
log_info("START!\r\n");
#endif
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* Configure the peripherals common clocks */
PeriphCommonClock_Config();
/* IPCC initialisation */
MX_IPCC_Init();
/* USER CODE BEGIN SysInit */
// Enable Clock security system for HSE
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_RF_Init();
MX_GPIO_Init();
MX_DMA_Init();
MX_RTC_Init();
MX_I2C3_Init();
MX_TIM1_Init();
MX_LPTIM1_Init();
MX_ADC1_Init();
/* USER CODE BEGIN 2 */
HAL_RCC_EnableCSS();
HAL_RCCEx_EnableLSECSS_IT();
[...]
}
Callback:
void HAL_RCC_CSSCallback(void)
{
HAL_GPIO_WritePin(UC_LED_GPIO_Port, UC_LED_Pin, GPIO_PIN_SET);
log_error("HSE Clock error detected !\n");
err_setEuError(CLOCK_FAILURE_DETECTED);
__HAL_RCC_HSE_CONFIG(RCC_HSE_OFF); // Disable HSE
__HAL_RCC_SYSCLK_CONFIG(RCC_SYSCLKSOURCE_HSI); // Pass on HSI
}
void HAL_RCCEx_LSECSS_Callback(void)
{
HAL_GPIO_WritePin(UC_LED_GPIO_Port, UC_LED_Pin, GPIO_PIN_SET);
log_error("LSE Clock error detected !\n");
err_setEuError(CLOCK_FAILURE_DETECTED);
}
Hal functions for LSECSS:
void HAL_RCCEx_EnableLSECSS_IT(void)
{
/* Enable LSE CSS */
LL_RCC_LSE_EnableCSS();
/* Enable LSE CSS IT */
__HAL_RCC_ENABLE_IT(RCC_IT_LSECSS);
/* Enable IT on EXTI Line 18 */
__HAL_RCC_LSECSS_EXTI_ENABLE_IT();
__HAL_RCC_LSECSS_EXTI_ENABLE_RISING_EDGE();
}
/**
* @brief Handle the RCC LSE Clock Security System interrupt request.
* @retval None
*/
void HAL_RCCEx_LSECSS_IRQHandler(void)
{
/* Check RCC LSE CSSF flag */
if (__HAL_RCC_GET_IT(RCC_IT_LSECSS))
{
/* RCC LSE Clock Security System interrupt user callback */
HAL_RCCEx_LSECSS_Callback();
/* Clear RCC LSE CSS pending bit */
__HAL_RCC_CLEAR_IT(RCC_IT_LSECSS);
}
}
/**
* @brief RCCEx LSE Clock Security System interrupt callback.
* @retval none
*/
__weak void HAL_RCCEx_LSECSS_Callback(void)
{
/* NOTE : This function should not be modified, when the callback is needed,
the HAL_RCCEx_LSECSS_Callback should be implemented in the user file
*/
}
Do you see anything that seems incorrect? I need your help because the PCB for this project is very small, and a test bench is required to retrieve the logs. However, when the PCB is placed in the test bench, I no longer have access to the clock signals, which prevents me from perturbing the signal to test the code.