你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【经验分享】验证 STM32F401 在 STOP 模式下的电流

[复制链接]
STMCU小助手 发布时间:2022-3-5 09:44
问题:
该问题由某客户提出,发生在 STM32F401CEY6 401CEY6 401CEY6 器件上。据其工程师讲述:在程序中,在进入 STOP 模式之前他已经将 STM32F401 的 I/O 口做完处理了,但是电流仍然比数据手册写的数值还要大很多,不知道是在哪里消耗了电流。希望能帮他验证一下。

调研:
我们先来看一下 STM32F401 的数据手册中,对其在 STOP 模式下工作的电流的参数:

1@1I2[1{R[$~B6{MO08@A}8.png

按客户的要求,我们主要是验证在 STOP 模式下,调压器在低功耗模式下的电流,也就是表格中典型电流为 42uA 的那个值。
我们使用 STM32F401 的 Discovery 板进行验证,因为在 Discovery 板上只需要把 Idd 的那个 JP2 的跳线帽拿掉接上电流表就可以测试电流了,当然,我们必须要检查一下,这个电流供进来给 MCU 作为VDD 时,还可能连接什么电路会导致电流消耗的,检查了一遍,主要是要注意 BOOT0 以及 BOOT1脚。

LP_)IU6}S`I{1BSRZ_$()UI.png

由于运行用户代码,所以 BOOT0 和 BOOT1 都将接到低电平上,所以电路上要确保 SB19 和 SB20 短路,但是我们可以看到,BOOT1 上面从 VDD 到 R30 到 R31 再到 GND,将会有一个电流产生,所以必须要把 R30 取下来。BOOT0 由于本身 R29 就没有接,所以倒是没有关系。
好,那现在开始验证电流,我们使用 32F401CDISCOVERY 的固件库中的 PWR_STOP 的例程来验证。因为不使用 RTC,所以我们将程序中的 RTC 部分删掉:将 stm32f4xx_it.c 中的 voidRTC_WKUP_IRQHandler(void)函数中的内容删除,再将 main.c 中的 static void RTC_Config(void)函数删除,在 int main(void)主函数中也清除掉相关的内容,主函数如下:
  1. int main(void)
  2. {
  3. /*!< At this stage the microcontroller clock setting is already configured,
  4. this is done through SystemInit() function which is called from startup
  5. file (startup_stm32f401xx.s) before to branch to application main.
  6. To reconfigure the default setting of SystemInit() function, refer to
  7. system_stm32f4xx.c file
  8. */

  9. /* Configure the SysTick to generate an interrupt each 250 ms */
  10. SysTick_Configuration();
  11. /* Initialize LEDs and User Button mounted on STM32F401C-DISCO board */
  12. STM_EVAL_LEDInit(LED3);
  13. STM_EVAL_LEDInit(LED6);
  14. /* Key button (EXTI_Line0) will be used to wakeup ths system from STOP mode */
  15. STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI);
  16. while (1)
  17. {
  18. /* Insert 5 second delay */
  19. Delay(20);
  20. /* Turn OFF LED3 */
  21. STM_EVAL_LEDOff(LED3);
  22. /* Enter Stop Mode */
  23. PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
  24. /* Configures system clock after wake-up from STOP: enable HSE, PLL and select
  25. PLL as system clock source (HSE and PLL are disabled in STOP mode) */
  26. SYSCLKConfig_STOP();
  27. }
  28. }
复制代码

编译,下载测试电流,进入 STOP 模式后电流为 2.23mA 左右。
大家应该已经发现,此例程在进入 STOP 模式之前,并没有对 I/O 口进行处理,导致很多配置为输入浮空的 I/O 口在受到外界干扰的时候,状态不定,消耗了大量的电流。在实际应用中,在进入 STOP模式前,可以根据实际情况,将 I/O 口设置成模拟输入,输入+上下拉电阻,或者输出固定电平。所以,在这里,我们将我们没用到的 I/O 通通设置为模拟输入,只保留 PA0 作为按键,产生外部中断来将 MCU 从 STOP 模式中唤醒。配置 I/O 口后,为了方便从 STOP 模式唤醒后还能直观地看到 LED灯,我们需要在 stm32f4xx_it.c 的 void EXTI0_IRQHandler(void)函数中加入 LED6 的初始化函数STM_EVAL_LEDInit(LED6),在 main()主函数的 SYSCLKConfig_STOP()之后加上STM_EVAL_LEDInit(LED3)。
void EXTI0_IRQHandler(void)如下:
  1. void EXTI0_IRQHandler(void)
  2. {
  3. if(EXTI_GetITStatus(USER_BUTTON_EXTI_LINE) != RESET)
  4. {
  5. /* Clear the USER Button EXTI line pending bit */
  6. EXTI_ClearITPendingBit(USER_BUTTON_EXTI_LINE);
  7. /* Toggle LED6 */
  8. STM_EVAL_LEDInit(LED6);
  9. STM_EVAL_LEDToggle(LED6);
  10. }
  11. }
复制代码

Int main(void)中的主循环 while(1)中的内容如下:
  1. while (1)
  2. {
  3. /* Insert 5 second delay */
  4. Delay(20);
  5. /* Turn OFF LED3 */
  6. STM_EVAL_LEDOff(LED3);

  7. /* Configure all I/O ports */
  8. GPIO_InitTypeDef GPIO_InitStructure;
  9. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  10. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  11. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
  12. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  13. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
  14. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  15. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  16. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  17. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  18. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  19. GPIO_Init(GPIOB, &GPIO_InitStructure);
  20. GPIO_Init(GPIOC, &GPIO_InitStructure);
  21. GPIO_Init(GPIOD, &GPIO_InitStructure);
  22. GPIO_Init(GPIOE, &GPIO_InitStructure);
  23. GPIO_InitStructure.GPIO_Pin = (~GPIO_Pin_0);
  24. GPIO_Init(GPIOA, &GPIO_InitStructure);
  25. /* Enter Stop Mode */
  26. PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
  27. /* Configures system clock after wake-up from STOP: enable HSE, PLL and select
  28. PLL as system clock source (HSE and PLL are disabled in STOP mode) */
  29. SYSCLKConfig_STOP();
  30. STM_EVAL_LEDInit(LED3);
  31. }
复制代码

编译,下载测试电流,进入 STOP 模式后电流为 155uA 左右。这不对啊,距离我们看到的 42uA 还有很大的差距。客户就是在这里不知道为什么了。
我们来继续查找原因,客户跟 32F401CDISCOVERY 板一样,使用了外部 8MHz 晶振,所以当使用HSE 的时候,PH0/PH1 被作为 OSC_IN 和 OSC_OUT。问题来了,当进入 STOP 模式时,HSE RC振荡器被禁止,PH0/PH1 这个时候就不再是 OSC_IN 和 OSC_OUT 了,变成普通的 I/O 口,而且是处理浮空输入状态。所以我们还得需要对这两个引脚的 I/O 配置进行处理。再来修改 main()主函数中的while(1)主循环,加入对 PH0/PH1 的处理,程序如下:
  1. while (1)
  2. {
  3. /* Insert 5 second delay */
  4. Delay(20);
  5. /* Turn OFF LED3 */
  6. STM_EVAL_LEDOff(LED3);

  7. /* Configure all I/O ports */
  8. GPIO_InitTypeDef GPIO_InitStructure;
  9. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  10. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  11. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
  12. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  13. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
  14. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE);
  15. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  16. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  17. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  18. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  19. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  20. GPIO_Init(GPIOB, &GPIO_InitStructure);
  21. GPIO_Init(GPIOC, &GPIO_InitStructure);
  22. GPIO_Init(GPIOD, &GPIO_InitStructure);
  23. GPIO_Init(GPIOE, &GPIO_InitStructure);
  24. GPIO_Init(GPIOH, &GPIO_InitStructure);
  25. GPIO_InitStructure.GPIO_Pin = (~GPIO_Pin_0);
  26. GPIO_Init(GPIOA, &GPIO_InitStructure);
  27. /* Enter Stop Mode */
  28. PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
  29. /* Configures system clock after wake-up from STOP: enable HSE, PLL and select
  30. PLL as system clock source (HSE and PLL are disabled in STOP mode) */
  31. SYSCLKConfig_STOP();
  32. STM_EVAL_LEDInit(LED3);
  33. }
复制代码

编译,下载测试电流,进入 STOP 模式后电流为 38.5uA。已经比我们从表格中看到 42uA 还小了,任务完成。当然,数据手册中 42uA 是在 VDD=3.3V 的情况下数值,而我们的 Discovery 板的 VDD 为3V。

我们还可以再测一下让 Flash 进入掉电模式下的电流,修改 while(1)程序如下:
  1. while (1)
  2. {
  3. /* Insert 5 second delay */
  4. Delay(20);
  5. /* Turn OFF LED3 */
  6. STM_EVAL_LEDOff(LED3);

  7. /* Configure all I/O ports */
  8. GPIO_InitTypeDef GPIO_InitStructure;
  9. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  10. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  11. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
  12. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  13. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
  14. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE);
  15. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  16. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  17. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  18. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  19. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  20. GPIO_Init(GPIOB, &GPIO_InitStructure);
  21. GPIO_Init(GPIOC, &GPIO_InitStructure);
  22. GPIO_Init(GPIOD, &GPIO_InitStructure);
  23. GPIO_Init(GPIOE, &GPIO_InitStructure);
  24. GPIO_Init(GPIOH, &GPIO_InitStructure);
  25. GPIO_InitStructure.GPIO_Pin = (~GPIO_Pin_0);
  26. GPIO_Init(GPIOA, &GPIO_InitStructure);
  27. /* Configure flash power down mode */
  28. PWR_FlashPowerDownCmd(ENABLE);
  29. /* Enter Stop Mode */
  30. PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
  31. /* Configures system clock after wake-up from STOP: enable HSE, PLL and select
  32. PLL as system clock source (HSE and PLL are disabled in STOP mode) */
  33. SYSCLKConfig_STOP();
  34. STM_EVAL_LEDInit(LED3);
  35. }
复制代码

编译,下载测试电流,进入 STOP 模式后电流为 10.2uA,与数据手册中的典型值基本一致。

结论:
客户在硬件上使用了 HSE,而在进入 STOP 模式前,只对其他 I/O 进行了处理,漏掉了 HSE 对应的两个I/O 口,导致电流过大。

处理:
对 PH0/PH1 进行处理,进入 STOP 模式前配置成模拟输入。

建议:
在进入 STOP 模式之前,一定要根据实际电路情况,细致地对各个 I/O 口进行处理。




收藏 评论0 发布时间:2022-3-5 09:44

举报

0个回答
关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版