Skip to main content
mhitchman-cc
Associate
February 16, 2010
Question

Entering Sleep mode for STM32F103RBT6

  • February 16, 2010
  • 2 replies
  • 793 views
Posted on February 16, 2010 at 23:48

Entering Sleep mode for STM32F103RBT6

    This topic has been closed for replies.

    2 replies

    mhitchman-cc
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 13:40

    hey guys, sorry about the simple question, I am a student and am still learning, any help would be greatly appreciated

    Tesla DeLorean
    Guru
    May 17, 2011
    Posted on May 17, 2011 at 13:40

    Try looking at the ST Library code, typically in \Keil\ARM\RV31\LIB\ST\STM32F10x\stm32f10x_pwr.c

    /*******************************************************************************

    * Function Name  : PWR_EnterSTOPMode

    * Description    : Enters STOP mode.

    * Input          : - PWR_Regulator: specifies the regulator state in STOP mode.

    *                    This parameter can be one of the following values:

    *                       - PWR_Regulator_ON: STOP mode with regulator ON

    *                       - PWR_Regulator_LowPower: STOP mode with

    *                         regulator in low power mode

    *                  - PWR_STOPEntry: specifies if STOP mode in entered with WFI or

    *                    WFE instruction.

    *                    This parameter can be one of the following values:

    *                       - PWR_STOPEntry_WFI: enter STOP mode with WFI instruction

    *                       - PWR_STOPEntry_WFE: enter STOP mode with WFE instruction

    * Output         : None

    * Return         : None

    *******************************************************************************/

    void PWR_EnterSTOPMode(u32 PWR_Regulator, u8 PWR_STOPEntry)

    {

      u32 tmpreg = 0;

      /* Check the parameters */

      assert_param(IS_PWR_REGULATOR(PWR_Regulator));

      assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));

      /* Select the regulator state in STOP mode ---------------------------------*/

      tmpreg = PWR->CR;

      /* Clear PDDS and LPDS bits */

      tmpreg &= CR_DS_Mask;

      /* Set LPDS bit according to PWR_Regulator value */

      tmpreg |= PWR_Regulator;

      /* Store the new value */

      PWR->CR = tmpreg;

      /* Set SLEEPDEEP bit of Cortex System Control Register */

      *(vu32 *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set;

      /* Select STOP mode entry --------------------------------------------------*/

      if(PWR_STOPEntry == PWR_STOPEntry_WFI)

      {

        /* Request Wait For Interrupt */

        __WFI();

      }

      else

      {

        /* Request Wait For Event */

        __WFE();

      }

    }

    /*******************************************************************************

    * Function Name  : PWR_EnterSTANDBYMode

    * Description    : Enters STANDBY mode.

    * Input          : None

    * Output         : None

    * Return         : None

    *******************************************************************************/

    void PWR_EnterSTANDBYMode(void)

    {

      /* Clear Wake-up flag */

      PWR->CR |= CR_CWUF_Set;

      /* Select STANDBY mode */

      PWR->CR |= CR_PDDS_Set;

      /* Set SLEEPDEEP bit of Cortex System Control Register */

      *(vu32 *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set;

      /* Request Wait For Interrupt */

      __WFI();

    }

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..