/**
  ******************************************************************************
  * @file     PWR_user.c
  * @author   SINOMCU-AE
  * @brief    Power function
  *    
  *          This file provides functions :
  *    EnterSTOP_LPREGUMode();
  *  
  ******************************************************************************
  * @attention 
  *                           DISCLAIMER
  * The present firmware which is for guidance only aims at providing customers
  * with coding information regarding their products in order for them to save
  * time. As a result, SinoMCU shall not be held liable for any direct,indirect
  * or consequential damages with respect to any claims arising from the content 
  * of such firmware and/or the use made by customers of the coding information 
  * contained herein in connection with their products.
  *
  * <h2><center>&copy; Copyright (c) 2021 sinomcu All rights reserved.</center></h2>
  *
  ******************************************************************************
  */
    
#include "PWR_user.h"

/**
  * @brief  Function to configure and enter in STOP LDO LowPower Mode.
  * @param  None
  * @retval None
  */
void EnterSTOP_LPREGUMode(void) {
#if( defined(TEST_STOP_CURRENT) && (TEST_STOP_CURRENT) )
  // all GPIO analog mode 
  MS32_GPIO_InitTypeDef gpio_initstruct = {MS32_GPIO_PIN_ALL, MS32_GPIO_MODE_ANALOG, 
                                         MS32_GPIO_SPEED_FREQ_HIGH, MS32_GPIO_OUTPUT_PUSHPULL, 
                                         MS32_GPIO_PULL_NO, MS32_GPIO_AF_0};

  MS32_AHB1_GRP1_EnableClock(MS32_AHB1_GRP1_PERIPH_GPIOA |
                           MS32_AHB1_GRP1_PERIPH_GPIOF |
                           MS32_AHB1_GRP1_PERIPH_GPIOB |
                           MS32_AHB1_GRP1_PERIPH_GPIOC);

  MS32_GPIO_Init(GPIOA, &gpio_initstruct);
  MS32_GPIO_Init(GPIOB, &gpio_initstruct);
  MS32_GPIO_Init(GPIOC, &gpio_initstruct);
  MS32_GPIO_Init(GPIOF, &gpio_initstruct);

  MS32_AHB1_GRP1_DisableClock(MS32_AHB1_GRP1_PERIPH_GPIOA |
                           MS32_AHB1_GRP1_PERIPH_GPIOF |
                           MS32_AHB1_GRP1_PERIPH_GPIOB |
                           MS32_AHB1_GRP1_PERIPH_GPIOC);
#endif
  // LDO LowPower mode,enter stop mode
  MS32_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); 
}

/******************************** END OF FILE *********************************/
