cancel
Showing results for 
Search instead for 
Did you mean: 

Issue to generate an alarm interupt on STM32C031

mjacquin
Associate

Hi,

I try to configure a STM32C031K6 to generate an interupt every seconds using RTC Alarm A (RTC clocked by 32.768KHz crystal).
I am working on STM32Cube IDE 1.15.1. First issue was that the device configuration tool does not generate any code regarding the Alarm Sub Second Mask (nothing change in the MX_RTC_Init() if you change the parameter).

Here is my settings :

mjacquin_0-1718371573119.pngmjacquin_1-1718371641930.png

Here is the code generated, with the 5 last code lines entered manually :

/**
* @brief RTC Initialization Function
* @PAram None
* @retval None
*/
static void MX_RTC_Init(void)
{

/* USER CODE BEGIN RTC_Init 0 */

/* USER CODE END RTC_Init 0 */

LL_RTC_InitTypeDef RTC_InitStruct = {0};
LL_RTC_TimeTypeDef RTC_TimeStruct = {0};
LL_RTC_DateTypeDef RTC_DateStruct = {0};
LL_RTC_AlarmTypeDef RTC_AlarmStruct = {0};

if(LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE)
{
FlagStatus pwrclkchanged = RESET;
if (LL_APB1_GRP1_IsEnabledClock (LL_APB1_GRP1_PERIPH_PWR) != 1U)
{
/* Enables the PWR Clock and Enables access to the backup domain */
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
pwrclkchanged = SET;
}
LL_RCC_ForceBackupDomainReset();
LL_RCC_ReleaseBackupDomainReset();
LL_RCC_LSE_SetDriveCapability(LL_RCC_LSEDRIVE_LOW);
LL_RCC_LSE_Enable();

/* Wait till LSE is ready */
while(LL_RCC_LSE_IsReady() != 1)
{
}
LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE);
/* Restore clock configuration if changed */
if (pwrclkchanged == SET)
{
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_PWR);
}
}

/* Peripheral clock enable */
LL_RCC_EnableRTC();
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_RTC);

/* RTC interrupt Init */
NVIC_SetPriority(RTC_IRQn, 0);
NVIC_EnableIRQ(RTC_IRQn);

/* USER CODE BEGIN RTC_Init 1 */

/* USER CODE END RTC_Init 1 */
RTC_InitStruct.HourFormat = LL_RTC_HOURFORMAT_24HOUR;
RTC_InitStruct.AsynchPrescaler = 127;
RTC_InitStruct.SynchPrescaler = 255;
LL_RTC_Init(RTC, &RTC_InitStruct);
RTC_TimeStruct.Hours = 0x0;
RTC_TimeStruct.Minutes = 0x0;
RTC_TimeStruct.Seconds = 0x0;

LL_RTC_TIME_Init(RTC, LL_RTC_FORMAT_BCD, &RTC_TimeStruct);
RTC_DateStruct.WeekDay = LL_RTC_WEEKDAY_MONDAY;
RTC_DateStruct.Month = LL_RTC_MONTH_JANUARY;
RTC_DateStruct.Day = 0x1;
RTC_DateStruct.Year = 0x0;

LL_RTC_DATE_Init(RTC, LL_RTC_FORMAT_BCD, &RTC_DateStruct);

/** Enable the Alarm A
*/
RTC_AlarmStruct.AlarmTime.Hours = 0x0;
RTC_AlarmStruct.AlarmTime.Minutes = 0x0;
RTC_AlarmStruct.AlarmTime.Seconds = 0x0;
RTC_AlarmStruct.AlarmMask = LL_RTC_ALMA_MASK_ALL;
RTC_AlarmStruct.AlarmDateWeekDaySel = LL_RTC_ALMA_DATEWEEKDAYSEL_DATE;
RTC_AlarmStruct.AlarmDateWeekDay = 0x1;
LL_RTC_ALMA_Init(RTC, LL_RTC_FORMAT_BCD, &RTC_AlarmStruct);
LL_RTC_EnableIT_ALRA(RTC);
LL_RTC_DisableAlarmPullUp(RTC);
/* USER CODE BEGIN RTC_Init 2 */
//Alarm configuration and activation for 1 sec period
LL_RTC_DisableWriteProtection(RTC);
LL_RTC_ALMA_Disable(RTC);
LL_RTC_ALMA_SetSubSecond(RTC, 0x0F000000);
LL_RTC_ALMA_Enable(RTC);
LL_RTC_EnableWriteProtection(RTC);
/* USER CODE END RTC_Init 2 */

}

 

MX_RTC_Init() is called at startup. If I place the following lines in my main loop, I can see the output test pin toggled every seconds :

if (LL_RTC_IsActiveFlag_ALRA(RTC))
{
LL_RTC_ClearFlag_ALRA(RTC);
LL_GPIO_TogglePin(TP15_GPIO_Port, TP15_Pin);
}

 

But if I removed it and move the toggled in the interrupt handler, the output is no more toggled :

void RTC_IRQHandler(void)
{
/* USER CODE BEGIN RTC_IRQn 0 */
if (LL_RTC_IsActiveFlag_ALRA(RTC))
{
LL_GPIO_TogglePin(TP15_GPIO_Port, TP15_Pin);
LL_RTC_ClearFlag_ALRA(RTC);
}
/* USER CODE END RTC_IRQn 0 */

/* USER CODE BEGIN RTC_IRQn 1 */

/* USER CODE END RTC_IRQn 1 */
}

 

In debug mode, I check, the interrupt is never triggered. Another interupt (Timer1) is working fine.

Can anyone help me find what I missed ?

0 REPLIES 0