KugleFirmware/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c
/**
  * @brief  Enter the system to STOP mode.
  * @note   In System Stop mode, all I/O pins keep the same state as in Run mode.
  * @note   When exiting System Stop mode by issuing an interrupt or a wakeup event,
  *         the HSI RC oscillator is selected as default system wakeup clock.
  * @note   In System STOP mode, when the voltage regulator operates in low power mode,
  *         an additional startup delay is incurred when the system is waking up.
  *         By keeping the internal regulator ON during Stop mode, the consumption
  *         is higher although the startup time is reduced.
  * @param  Regulator: Specifies the regulator state in Stop mode.
  *          This parameter can be one of the following values:
  *            @arg PWR_MAINREGULATOR_ON: Stop mode with regulator ON
  *            @arg PWR_LOWPOWERREGULATOR_ON: Stop mode with low power regulator ON
  * @param  STOPEntry: Specifies if Stop mode in entered with WFI or WFE instruction.
  *          This parameter can be one of the following values:
  *            @arg PWR_STOPENTRY_WFI: Enter Stop mode with WFI instruction
  *            @arg PWR_STOPENTRY_WFE: Enter Stop mode with WFE instruction
  * @retval None
  */
@brief  Enter the system to STOP mode.
@note   In System Stop mode, all I/O pins keep the same state as in Run mode.
@note   When exiting System Stop mode by issuing an interrupt or a wakeup event,
the HSI RC oscillator is selected as default system wakeup clock.
@note   In System STOP mode, when the voltage regulator operates in low power mode,
an additional startup delay is incurred when the system is waking up.
By keeping the internal regulator ON during Stop mode, the consumption
is higher although the startup time is reduced.
@param  Regulator: Specifies the regulator state in Stop mode.
This parameter can be one of the following values:
@arg PWR_MAINREGULATOR_ON: Stop mode with regulator ON
@arg PWR_LOWPOWERREGULATOR_ON: Stop mode with low power regulator ON
@param  STOPEntry: Specifies if Stop mode in entered with WFI or WFE instruction.
This parameter can be one of the following values:
@arg PWR_STOPENTRY_WFI: Enter Stop mode with WFI instruction
@arg PWR_STOPENTRY_WFE: Enter Stop mode with WFE instruction
@retval None
@brief Enter the system to STOP mode . @note In System Stop mode all I / O pins keep the same state as in Run mode . @note When exiting System Stop mode by issuing an interrupt or a wakeup event the HSI RC oscillator is selected as default system wakeup clock . @note In System STOP mode when the voltage regulator operates in low power mode an additional startup delay is incurred when the system is waking up . By keeping the internal regulator ON during Stop mode the consumption is higher although the startup time is reduced . @param Regulator : Specifies the regulator state in Stop mode . This parameter can be one of the following values : @arg PWR_MAINREGULATOR_ON : Stop mode with regulator ON @arg PWR_LOWPOWERREGULATOR_ON : Stop mode with low power regulator ON @param STOPEntry : Specifies if Stop mode in entered with WFI or WFE instruction . This parameter can be one of the following values : @arg PWR_STOPENTRY_WFI : Enter Stop mode with WFI instruction @arg PWR_STOPENTRY_WFE : Enter Stop mode with WFE instruction @retval None
void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
{
  uint32_t tmpreg = 0;
  assert_param(IS_PWR_REGULATOR(Regulator));
  assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
  tmpreg = PWR->CR1;
  tmpreg &= (uint32_t)~(PWR_CR1_LPDS);
  tmpreg |= Regulator;
  PWR->CR1 = tmpreg;
  CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D1);
  CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D2);
  CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D3);
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  __DSB();
  __ISB();
  if(STOPEntry == PWR_STOPENTRY_WFI)
  {
    __WFI();
  }
  else
  {
    __SEV();
    __WFE();
    __WFE();
  }
  SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
}
void HAL_PWR_EnterSTOPMode ( uint32_t Regulator , uint8_t STOPEntry ) { uint32_t tmpreg = 0 ; assert_param ( IS_PWR_REGULATOR ( Regulator ) ) ; assert_param ( IS_PWR_STOP_ENTRY ( STOPEntry ) ) ; tmpreg = PWR -> CR1 ; tmpreg &= ( uint32_t ) ~ ( PWR_CR1_LPDS ) ; tmpreg |= Regulator ; PWR -> CR1 = tmpreg ; CLEAR_BIT ( PWR -> CPUCR , PWR_CPUCR_PDDS_D1 ) ; CLEAR_BIT ( PWR -> CPUCR , PWR_CPUCR_PDDS_D2 ) ; CLEAR_BIT ( PWR -> CPUCR , PWR_CPUCR_PDDS_D3 ) ; SCB -> SCR |= SCB_SCR_SLEEPDEEP_Msk ; __DSB ( ) ; __ISB ( ) ; if ( STOPEntry == PWR_STOPENTRY_WFI ) { __WFI ( ) ; } else { __SEV ( ) ; __WFE ( ) ; __WFE ( ) ; } SCB -> SCR &= ( uint32_t ) ~ ( ( uint32_t ) SCB_SCR_SLEEPDEEP_Msk ) ; }
@brief  Enter the system to STOP mode.
@brief Enter the system to STOP mode .
/* Check the parameters */ /* Select the regulator state in Stop mode */ /* Clear PDDS and LPDS bits */ /* Set LPDS bit according to Regulator value */ /* Store the new value */ /* Keep DSTOP mode when D1 domain enters Deepsleep */ /* Keep DSTOP mode when D2 domain enters Deepsleep */ /* Keep DSTOP mode when D3 domain enters Deepsleep */ /* Set SLEEPDEEP bit of Cortex System Control Register */ /* Ensure that all instructions done before entering STOP mode */ /* Select Stop mode entry */ /* Request Wait For Interrupt */ /* Request Wait For Event */ /* Reset SLEEPDEEP bit of Cortex System Control Register */