cancel
Showing results for 
Search instead for 
Did you mean: 

WAKEUP from STANDBY mode and EXTI/NVIC IRQs

JAlca
Senior

Hi all,

I'm learning about low power modes , and I'm testing the RTC wakeup timer function.

Datasheet talks about to set the IRQs for WakeUp timer on EXTI(IRQ 19) and NVIC(IRQ 3), but I tested in my code, with and without set these IRQs and the wakeup timer works well in both cases.

What I'm doing wrong?

The MCU is a STM32F3 family one.

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
 
/* USER CODE END Includes */
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
 
/* USER CODE END PTD */
 
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
 
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
 
/* USER CODE END PM */
 
/* Private variables ---------------------------------------------------------*/
 
/* USER CODE BEGIN PV */
uint8_t x;
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
 
/* USER CODE BEGIN PFP */
 
/* USER CODE END PFP */
 
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void ClockInit(void)
{
	//Queremos trabajar a 16MHz, con HSE y LSE
	//Cambiamos el SYSCLK source a HSI
	RCC->CFGR &= ~(RCC_CFGR_SW);
	while((RCC->CFGR & RCC_CFGR_SWS));
 
	//Para el PLL
	RCC->CR &= ~(RCC_CR_PLLON);
	while(RCC->CR & RCC_CR_PLLRDY);
 
	//El cristal es de 8MHz, por lo que hacemos PLL x2
	RCC->CFGR &= ~(RCC_CFGR_PLLMUL);
	RCC->CFGR |= RCC_CFGR_PLLMUL_0;
 
	//Enciende el HSE y espera a que HSE_RDY se ponga a 1
	RCC->CR |= RCC_CR_HSEON;
	while(!(RCC->CR & RCC_CR_HSERDY));
 
	//Hacemos que el source del PLL sea el HSE/PREDIV
	RCC->CFGR |= RCC_CFGR_PLLSRC_HSE_PREDIV;
 
	//Encendemos el PLL
	RCC->CR |= RCC_CR_PLLON;
	while(!(RCC->CR & RCC_CR_PLLRDY));
 
	//Hacemos que el APB1 sea de 16MHz
	RCC->CFGR &= ~(RCC_CFGR_PPRE1);
 
	//El valor de LATENCY se debe ajustar en función de la velocidad del SysClock. 0 para 16MHz
	FLASH->ACR &= ~FLASH_ACR_LATENCY;
 
	//El SYSCLK es el PLL
	RCC->CFGR &= ~(RCC_CFGR_SW);
	RCC->CFGR |= RCC_CFGR_SW_1;
	while((RCC->CFGR & RCC_CFGR_SWS_0) && !(RCC->CFGR & RCC_CFGR_SWS_1));
 
	//----------------------Programamos el LSE-------------------------------
	//Para poder programarlo se debe activar PWR_CR_DBP
	PWR->CR |= PWR_CR_DBP;
 
	//Habilitamos el reloj RTC
	RCC->BDCR |= RCC_BDCR_RTCEN;
 
	//Seleccionamos LSE como source
	RCC->BDCR &= ~(RCC_BDCR_RTCSEL);
	RCC->BDCR |= RCC_BDCR_RTCSEL_0;
 
	//Encendemos el RTC y esperamos a que esté listo
	RCC->BDCR |= RCC_BDCR_LSEON;
	while(!(RCC->BDCR & RCC_BDCR_LSERDY));
 
	//Bajamos el bit de PWR_CR_DBP
	PWR->CR &= ~(PWR_CR_DBP);
 
	SystemCoreClockUpdate();
	SysTick_Config(SystemCoreClock/1000);
}
 
void GpioInit(void)
{
	RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
 
	GPIOA->MODER &= ~(GPIO_MODER_MODER11);
	GPIOA->MODER |= GPIO_MODER_MODER11_0;
 
}
 
void SetWakeUpTimer(uint16_t segundos)
{
	//EXTI->IMR |= EXTI_IMR_IM20;
	//EXTI->RTSR |= EXTI_IMR_IM20;
	//EXTI->FTSR &= ~(EXTI_IMR_IM20);
	//NVIC_EnableIRQ(3);
 
	PWR->CR |= PWR_CR_DBP;
	RTC->WPR = 0xCA;
	RTC->WPR = 0x53;
 
	RTC->CR &= ~(RTC_CR_WUTE);
	while(!(RTC->ISR & RTC_ISR_WUTWF));
 
	RTC->WUTR = segundos;
 
	RTC->CR &= ~(RTC_CR_WUCKSEL);
	RTC->CR |= RTC_CR_WUCKSEL_2;
	RTC->CR |= RTC_CR_WUTIE;
	RTC->CR |= RTC_CR_WUTE;
}
/* USER CODE END 0 */
 
/**
  * @brief  The application entry point.
  * @retval int
  */
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();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  //SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
  ClockInit();
  GpioInit();
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
 
  /* USER CODE BEGIN 2 */
  SetWakeUpTimer(3);
 
  PWR->CR |= PWR_CR_CSBF;
  PWR->CR |= PWR_CR_CWUF;
  RTC->ISR &= ~(RTC_ISR_WUTF);
 
  GPIOA->BSRR |= GPIO_BSRR_BS_11;
  HAL_Delay(50);
  GPIOA->BSRR |= GPIO_BSRR_BR_11;
  HAL_Delay(50);
  GPIOA->BSRR |= GPIO_BSRR_BS_11;
  HAL_Delay(50);
  GPIOA->BSRR |= GPIO_BSRR_BR_11;
 
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  PWR->CR |= PWR_CR_PDDS;
  __WFI();
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
 
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}
 
/* USER CODE BEGIN 4 */
 
/* USER CODE END 4 */
 
/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}
 
#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

0 REPLIES 0