cancel
Showing results for 
Search instead for 
Did you mean: 

How to enter and exit standby mode on the STM32G071RB board using HAL commands and the automated timer?

SS_user
Associate II

I am using the STM32G071RB board; trying to enter standby mode and wakeup using the automated timer after a certain number of seconds. I can't find any documentation on what I need to enable/disable before entering standby mode and attempting to wakeup on interrupt. I am using the following sequence but am not seeing the board actually go into standby mode and then wakeup. Any suggestions would be appreciated.

int main(void)
{
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* Initialize all configured peripherals */
  MX_RTC_Init();
 
	// Enable Power Control clock //
	__HAL_RCC_PWR_CLK_ENABLE();
 
	/* Check and handle if the system was resumed from StandBy mode */
	if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET) {
		/* Clear Standby flag */
		__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
 
		// Check and Clear the Wakeup flag
		if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUF) != RESET) {
			__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF);
		}
	}
 
	/* Disable Wakeup Counter */
	HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
 
	HAL_RTCEx_PollForWakeUpTimerEvent(&hrtc,Timeout);
 
	HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0x2616, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
 
	/* Clear all related wakeup flags */
	__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF);
 
HAL_RTC_Init(&hrtc);
 
	HAL_PWR_EnterSTANDBYMode();
	
 
  /* Infinite loop */
	while (1) {
		}
}
 
// This Callback function is below and outside int main()
 
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(hrtc);
 
  /* NOTE : This function should not be modified, when the callback is needed,
            the HAL_RTCEx_WakeUpTimerEventCallback could be implemented in the user file
   */
  HAL_Delay(5000);
}

0 REPLIES 0