cancel
Showing results for 
Search instead for 
Did you mean: 

RTC 1Hz interrupt

Kolab
Senior

Hello! I have configured the RTC in cube with a frequency of 1Hz in the board STM32WB55, and I want so as to each second the RTC interruption set a task. I found out that I should use RTC_IRQHandler, but in my project I can't found this function, I don't know how to enable RTC interruption, in cube V1.5 I only see the alarm's interruptions. How should I proceed?

7 REPLIES 7
Peter BENSCH
ST Employee

Enable the RTC Wakeup in STMCubeMx and set it to 1Hz. You can then use the callback function created by CubeMX to do whatever you want within the programm.

Good luck!

/Peter

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.
Kolab
Senior

thanks for the answer Peter. Could you say how it's called the callback?

I used HAL_RTCEx_WakeUpTimerEventCallback and the program seems not to achieve this function even after overloading it.

Peter BENSCH
ST Employee

First: did you enable the internal wakeup within CubeMX?

Did you also enable the RTC wake-up through EXTI.22 within the NVIC settings?

Then you should put your subroutine in a user code area, e.g. USER CODE 4:

void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) {

// do something

}

You probably forgot to activate the NVIC line, right?

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.
Kolab
Senior

I have done all that you have mentioned. Here is my configurations

0693W000003RUIaQAO.png

Kolab
Senior

I tried to take out APPE_Init(); and UTIL_SEQ_Run(UTIL_SEQ_DEFAULT); and it got working. But I need BLE too

Mecanix
Senior

Use virtual timers.

// add to structure definition
uint8_t					led_timer_Id;
 
 
/* USER CODE BEGIN PD */
#define LED_BLINK			(1.0*1000*1000/CFG_TS_TICK_VAL)		//1.0sec, 1Hz
//#define LED_BLINK			(0.1*1000*1000/CFG_TS_TICK_VAL)		//100ms, 10Hz
/* USER CODE END PD */
 
 /* USER CODE BEGIN PFP */
static void Led_blink_Timer_Callback(void);
/* USER CODE END PFP */
 
 
void Custom_APP_Init(void)
{
    // Virtual timer blink blue LED
    HW_TS_Create(CFG_TIM_PROC_ID_ISR, &(Custom_App_Context.led_timer_Id), hw_ts_Repeated, Led_blink_Timer_Callback);
    //HW_TS_Start(Custom_App_Context.led_timer_Id, LED_BLINK); // <--start with this
    //HW_TS_Stop(Custom_App_Context.led_timer_Id); // <--stop with that
     return;
}
 
 
static void Led_blink_Timer_Callback(void){
	 HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, 1);
	 HAL_Delay(1);
	 HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, 0);
}

Ensure you have this into your "stm32wbxx_it.c"

/* USER CODE BEGIN Includes */
	#include "app_common.h"
/* USER CODE END Includes */
 
/* USER CODE BEGIN 1 */
 
	void RTC_WKUP_IRQHandler(void)
	{
	  HW_TS_RTC_Wakeup_Handler();
	}
  
	void IPCC_C1_TX_IRQHandler(void)
	{
	  HW_IPCC_Tx_Handler();
	  return;
	}
 
	void IPCC_C1_RX_IRQHandler(void)
	{
	  HW_IPCC_Rx_Handler();
	  return;
	}
 
/* USER CODE END 1 */

lizerd
Associate III

For me CubeMX initialized the RTC with

static void MX_RTC_Init(void)

{

..

 if (HAL_RTCEx_SetWakeUpTimer(&hrtc, 0, RTC_WAKEUPCLOCK_CK_SPRE_16BITS) != HAL_OK)

..

}

And when I checked the P2Pserver reference example, the Init code hade

(HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0, RTC_WAKEUPCLOCK_RTCCLK_DIV16) != HAL_OK)

instead, and after chaning my code to the RTC_WAKEUPCLOCK_RTCCLK_DIV16 it worked!!

2 days worth of chasing en error other parts of the code