查看: 1149|回复: 0
打印 上一主题 下一主题

STM32LXXX系列低功耗测试代码

[复制链接]
跳转到指定楼层
沙发
发表于 2015-5-20 08:20:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
拿到STM32L的样片后,一直纠结于低功耗的测试,因为和STM32F系列的配置不同,所以导致了杯具,通过和ST公司不停的咨询,终于得到了最终的结果,
经过测试,功耗在STOP模式下为 500nA ,性能还是不错的,代码如下:

/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32l1xx_md.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32l1xx.c file
     */
     /* Configure all unused GPIO port pins in Analog Input mode (floating input
     trigger OFF), this will reduce the power consumption and increase the device
     immunity against EMI/EMC *************************************************/
    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC

                        | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH, ENABLE);

    /* config all IO to Analog Input to reduce parasite power consumption */

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_400KHz;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

    GPIO_Init(GPIOC, &GPIO_InitStructure);

    GPIO_Init(GPIOD, &GPIO_InitStructure);

    GPIO_Init(GPIOE, &GPIO_InitStructure);

    GPIO_Init(GPIOH, &GPIO_InitStructure);

    GPIO_Init(GPIOA, &GPIO_InitStructure);

    GPIO_Init(GPIOB, &GPIO_InitStructure);  

    /* Enable PB7 as external PVD input so as to set it as AIN_IN */
    Set_PVD_To_Config_PB7();

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA
                          | RCC_AHBPeriph_GPIOB
                          | RCC_AHBPeriph_GPIOC
                          | RCC_AHBPeriph_GPIOD
                          | RCC_AHBPeriph_GPIOE
                          | RCC_AHBPeriph_GPIOH, DISABLE);

    PWR_UltraLowPowerCmd(ENABLE);
    PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
    while(1);
}
/**
  * @brief  Enable PB7 as external PVD input so as to set it as AIN_IN
  * @param  None
  * @retval None
  */
void Set_PVD_To_Config_PB7(void)
{
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

  /* Configure the PVD Level to 3 (2.5V) */
  PWR_PVDLevelConfig(PWR_PVDLevel_7);

  /* Enable the PVD Output */
  PWR_PVDCmd(ENABLE);  
}
转载

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入中科因仑

本版积分规则

快速回复 返回顶部 返回列表