Firmware/src/hardware.c
void go_to_sleep_mode(uint32_t delay_ms)
{
  RTC_SetAlarm(RTC_GetCounter() + (delay_ms / 10));
  RTC_WaitForLastTask();
  
  RTC_ClearFlag(RTC_IT_ALR);
  RTC_ITConfig(RTC_IT_ALR, ENABLE);
  
  hardware_init_exti(ENABLE);
  NVIC_InitTypeDef NVIC_InitStructure;
  NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority  = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
  SysTick->CTRL = 0;// disable Systick
  uint32_t irq_state;
  ENTER_CRITICAL(irq_state);//Disable interrupts
  RTC_ClearFlag(RTC_IT_ALR);
  EXTI_ClearFlag(EXTI_Line17);//EXTI_Line17 - RTC alarm

  //STOP - HSI and HSE oscillators OFF
  PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
  //here program is running again
  
  LEAVE_CRITICAL(irq_state);//Enable interrupts
  hardware_restart_systick();
  hardware_init_exti(DISABLE);
  init_sys_clock();
}
//Go to sleep mode
//Go to stanby - RAM is enabled, 2mA
Go to sleep mode
Go to stanby - RAM is enabled, 2mA
Go to sleep mode Go to stanby - RAM is enabled 2mA
void go_to_sleep_mode(uint32_t delay_ms)
{
  RTC_SetAlarm(RTC_GetCounter() + (delay_ms / 10));
  RTC_WaitForLastTask();
  RTC_ClearFlag(RTC_IT_ALR);
  RTC_ITConfig(RTC_IT_ALR, ENABLE);
  hardware_init_exti(ENABLE);
  NVIC_InitTypeDef NVIC_InitStructure;
  NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority  = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  SysTick->CTRL = 0;
  uint32_t irq_state;
  ENTER_CRITICAL(irq_state);
  RTC_ClearFlag(RTC_IT_ALR);
  EXTI_ClearFlag(EXTI_Line17);
  PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
  LEAVE_CRITICAL(irq_state);
  hardware_restart_systick();
  hardware_init_exti(DISABLE);
  init_sys_clock();
}
void go_to_sleep_mode ( uint32_t delay_ms ) { RTC_SetAlarm ( RTC_GetCounter ( ) + ( delay_ms / 10 ) ) ; RTC_WaitForLastTask ( ) ; RTC_ClearFlag ( RTC_IT_ALR ) ; RTC_ITConfig ( RTC_IT_ALR , ENABLE ) ; hardware_init_exti ( ENABLE ) ; NVIC_InitTypeDef NVIC_InitStructure ; NVIC_InitStructure . NVIC_IRQChannel = RTCAlarm_IRQn ; NVIC_InitStructure . NVIC_IRQChannelPreemptionPriority = 0 ; NVIC_InitStructure . NVIC_IRQChannelSubPriority = 0 ; NVIC_InitStructure . NVIC_IRQChannelCmd = ENABLE ; NVIC_Init ( & NVIC_InitStructure ) ; SysTick -> CTRL = 0 ; uint32_t irq_state ; ENTER_CRITICAL ( irq_state ) ; RTC_ClearFlag ( RTC_IT_ALR ) ; EXTI_ClearFlag ( EXTI_Line17 ) ; PWR_EnterSTOPMode ( PWR_Regulator_LowPower , PWR_STOPEntry_WFI ) ; LEAVE_CRITICAL ( irq_state ) ; hardware_restart_systick ( ) ; hardware_init_exti ( DISABLE ) ; init_sys_clock ( ) ; }
Go to sleep mode
Go to stanby - RAM is enabled, 2mA
Go to sleep mode Go to stanby - RAM is enabled 2mA
// disable Systick //Disable interrupts //EXTI_Line17 - RTC alarm //STOP - HSI and HSE oscillators OFF //here program is running again //Enable interrupts