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

【经验分享】STM32 低功耗相关函数和类型

[复制链接]
STMCU小助手 发布时间:2022-3-30 11:00
01. 概述5 N  Z1 |. |, {& f7 N
很多单片机都有低功耗模式,STM32F4 也不例外。在系统或电源复位以后,微控制器处于运行状态。运行状态下的 HCLK 为 CPU 提供时钟,内核执行程序代码。当 CPU 不需继续运行时,可以利用多个低功耗模式来节省功耗,例如等待某个外部事件时。用户需要根据最低电源消耗,最快速启动时间和可用的唤醒源等条件,选定一个最佳的低功耗模式。8 A0 U3 N+ e( h* [8 d

2 i  v; |5 D) ?- c; a在stm32f4xx_pwr.c 和stm32f4xx_pwr.h 文件中。* |( T+ S2 [8 u5 l0 t, P4 ^

" W# k# O7 v, ^! `02. 相关类型% j! ?  |3 L  g$ J
PWR_PVD_detection_level/ ]3 x/ H$ w& T9 P6 Z6 P
/ h3 {$ \% J) x- O4 K2 n' `/ [- \
  1. /** @defgroup PWR_PVD_detection_level 7 S) r, Z2 ]* e% Z7 b
  2.   * @{. E& X8 ~3 ?* i( x+ _5 t
  3.   */
    # P8 W0 u( z0 {- |1 W
  4. #define PWR_PVDLevel_0                  PWR_CR_PLS_LEV0
    # u% t$ \* u4 l2 o' H( y
  5. #define PWR_PVDLevel_1                  PWR_CR_PLS_LEV1  b& }- R# V/ O! z& Z; X5 ]0 j
  6. #define PWR_PVDLevel_2                  PWR_CR_PLS_LEV2
    - i- |& U% z, E1 i9 Q1 \! `2 P
  7. #define PWR_PVDLevel_3                  PWR_CR_PLS_LEV3
    5 [- ]) O" g- [, w) \
  8. #define PWR_PVDLevel_4                  PWR_CR_PLS_LEV49 \' J- D+ F' J1 M6 k* H; P4 c
  9. #define PWR_PVDLevel_5                  PWR_CR_PLS_LEV5
    7 s8 P- S1 E! {' \
  10. #define PWR_PVDLevel_6                  PWR_CR_PLS_LEV6
    7 `+ g6 o* x& Z; h, C7 m
  11. #define PWR_PVDLevel_7                  PWR_CR_PLS_LEV7
    3 f, ]' j" ]1 M: \$ i* Q" B8 Y% a

  12. * ~) U0 h- F! H; N. ?( @; x. ]
  13. #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_0) || ((LEVEL) == PWR_PVDLevel_1)|| \) I5 f/ R7 |: ]9 T3 k$ G
  14.                                  ((LEVEL) == PWR_PVDLevel_2) || ((LEVEL) == PWR_PVDLevel_3)|| \
    ' V5 q  A3 h5 p0 V/ s4 {
  15.                                  ((LEVEL) == PWR_PVDLevel_4) || ((LEVEL) == PWR_PVDLevel_5)|| \
    & l6 c% `/ a+ Z0 x- v
  16.                                  ((LEVEL) == PWR_PVDLevel_6) || ((LEVEL) == PWR_PVDLevel_7))
复制代码

( {. T9 n. {5 x: Z8 Y+ yPWR_Regulator_state_in_STOP_mode
2 |3 `% B, b! }" p( e( O3 I7 ]5 ]8 z! {+ y% I5 L2 b
  1. /** @defgroup PWR_Regulator_state_in_STOP_mode 2 A0 k0 u* A' {- _1 p
  2.   * @{
    . n$ [& @( q1 h5 d2 k& q
  3.   */
    0 H0 \& m& G9 H  S' D* n1 a
  4. #define PWR_MainRegulator_ON                        ((uint32_t)0x00000000)' |# D1 M, A; W2 l
  5. #define PWR_LowPowerRegulator_ON                    PWR_CR_LPDS- X' ?+ z7 E* a7 f3 X

  6. % o1 K6 l9 U' [& p7 [! G
  7. /* --- PWR_Legacy ---*/
    ' J7 w* l# G/ i9 q( {0 v
  8. #define PWR_Regulator_ON                            PWR_MainRegulator_ON
    , m4 ?/ p8 S0 q- f1 v& a
  9. #define PWR_Regulator_LowPower                      PWR_LowPowerRegulator_ON
    ) c+ K6 K/ q- Z: s# M  t% @
  10. 8 r: ]5 B7 M" @: i% y
  11. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MainRegulator_ON) || \
    : O" v+ D& b" }0 }* ~* [' H' O' H
  12.                                      ((REGULATOR) == PWR_LowPowerRegulator_ON))
复制代码
$ Z$ {  }! M/ X4 y) e
PWR_Regulator_state_in_UnderDrive_mode
3 _& k- [& F5 o0 e7 Y
! z- x/ c5 G  h
  1. /** @defgroup PWR_Regulator_state_in_UnderDrive_mode 9 L( \% ~8 K- ~) j: v0 [- R0 g
  2.   * @{
    ( L, n1 g7 @8 e  w* O  A" t- s; e
  3.   */
    ) r& m0 A" W4 A9 i5 i
  4. #define PWR_MainRegulator_UnderDrive_ON               PWR_CR_MRUDS
    " V1 \' n/ I/ n% k! m
  5. #define PWR_LowPowerRegulator_UnderDrive_ON           ((uint32_t)(PWR_CR_LPDS | PWR_CR_LPUDS))
    0 @/ n5 V* }7 @! v) [" f
  6. # l7 o/ Q. @7 h, X7 [1 s- |) ]
  7. #define IS_PWR_REGULATOR_UNDERDRIVE(REGULATOR) (((REGULATOR) == PWR_MainRegulator_UnderDrive_ON) || \
    # i% c* s1 z, a2 {
  8.                                                 ((REGULATOR) == PWR_LowPowerRegulator_UnderDrive_ON))
复制代码

* r: l7 z7 f# Y/ @6 Q9 y1 F7 NPWR_STOP_mode_entry* i/ F+ M+ g; T: m8 w
: H$ M+ C' V; h3 Q
  1. /** @defgroup PWR_STOP_mode_entry 9 P6 r" m  v9 N- `4 v
  2.   * @{
    3 g4 i, Z3 L' Z+ O6 V6 |
  3.   */4 A8 |) R4 T  `. ~$ x# x: Y7 S
  4. #define PWR_STOPEntry_WFI               ((uint8_t)0x01)4 d" d/ O8 h; q! t9 r! |
  5. #define PWR_STOPEntry_WFE               ((uint8_t)0x02)
    2 L' r8 ~; C' {/ i: V1 E# o
  6. #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE))
复制代码
2 \& U/ s0 z0 R0 B' d' E! U% D* Y/ @
PWR_Regulator_Voltage_Scale6 h% x4 u' ?. ^' J

  x; [* L/ @  P4 i" l7 s  E5 \5 t+ S/ a
  1. /** @defgroup PWR_Regulator_Voltage_Scale
    $ Y# h9 I1 i4 u9 g* v7 y
  2.   * @{: C( C: s- g: s5 A3 T: ]) _
  3.   */
    , `$ g, C6 s/ V3 @+ E6 m
  4. #define PWR_Regulator_Voltage_Scale1    ((uint32_t)0x0000C000)7 c/ U) j/ }2 G7 {$ y
  5. #define PWR_Regulator_Voltage_Scale2    ((uint32_t)0x00008000)( s1 T) s& @4 `0 r5 y4 }( Z& w+ c
  6. #define PWR_Regulator_Voltage_Scale3    ((uint32_t)0x00004000)
    ! x1 a% z: a7 v0 O
  7. #define IS_PWR_REGULATOR_VOLTAGE(VOLTAGE) (((VOLTAGE) == PWR_Regulator_Voltage_Scale1) || \, y* N( ^& `6 o1 V8 w1 j8 @
  8.                                            ((VOLTAGE) == PWR_Regulator_Voltage_Scale2) || \3 Q. Z: p! H+ p& I1 `4 h. ]
  9.                                            ((VOLTAGE) == PWR_Regulator_Voltage_Scale3))
复制代码
4 L  J9 @7 p" _' k. S& X
PWR_Flag
/ v. ?0 a6 y* K- D. v: l

- r& A! R# m: e/ `; I; N5 s) R+ f
  1. /** @defgroup PWR_Flag ' q2 A3 _& }) X) s2 c6 H
  2.   * @{
    8 I2 o# ^1 Y( l
  3.   */" H' m, e9 E3 J% R; [1 V
  4. #define PWR_FLAG_WU                     PWR_CSR_WUF2 W( p# c, D1 P. u, v/ O
  5. #define PWR_FLAG_SB                     PWR_CSR_SBF/ N9 b, [4 }' _0 Q! X4 U* g0 [
  6. #define PWR_FLAG_PVDO                   PWR_CSR_PVDO* u" p" b4 _2 F' f: _( O
  7. #define PWR_FLAG_BRR                    PWR_CSR_BRR
    " g+ `/ X" w/ m
  8. #define PWR_FLAG_VOSRDY                 PWR_CSR_VOSRDY
    ; o9 {. D5 ]% ~
  9. #define PWR_FLAG_ODRDY                  PWR_CSR_ODRDY
    / d/ W9 [0 p5 `( y
  10. #define PWR_FLAG_ODSWRDY                PWR_CSR_ODSWRDY
    ! J" A! M0 N! V! H' F  A* [
  11. #define PWR_FLAG_UDRDY                  PWR_CSR_UDSWRDY( U7 f* I) l+ U7 ^

  12.   D6 C; a6 N- S* Q( b! A0 ?
  13. /* --- FLAG Legacy ---*/
    , R" i* s; X2 j8 J
  14. #define PWR_FLAG_REGRDY                  PWR_FLAG_VOSRDY               5 N$ @$ O9 k3 K+ @5 Y, P

  15. 1 K+ R& Z% J' U% n2 |% Z4 ]
  16. #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \
    + D5 O( S6 w' C# k# P
  17.                                ((FLAG) == PWR_FLAG_PVDO) || ((FLAG) == PWR_FLAG_BRR) || \# {3 |7 t& n" ]0 y* p! ^
  18.                                ((FLAG) == PWR_FLAG_VOSRDY) || ((FLAG) == PWR_FLAG_ODRDY) || \
      F: C- X( n# g, c. z1 j
  19.                                ((FLAG) == PWR_FLAG_ODSWRDY) || ((FLAG) == PWR_FLAG_UDRDY))
    & D6 j; _% s' H! H% V1 ]
  20. : a4 {" j$ {8 |, I

  21. ' p5 {9 }- ]$ k# b
  22. #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \- i+ \: k3 Y! P- s
  23.                                  ((FLAG) == PWR_FLAG_UDRDY))
复制代码
$ U. M( B2 U" a
03. 相关函数
8 {* u: j5 s! G( |3 @
! p  F( p. ?* J( m" ^8 Z
  1. /* Function used to set the PWR configuration to the default reset state ******/ 9 _9 e8 I! Y& Z' _9 h9 s/ x- P6 r! Y
  2. void PWR_DeInit(void);/ Y: S, f1 T  I1 Q
  3. 3 J' U& ^7 o' L7 t0 h
  4. /* Backup Domain Access function **********************************************/
    % V8 j" x. A( u- X7 K: V" s
  5. void PWR_BackupAccessCmd(FunctionalState NewState);0 F- P+ z2 I% D* _

  6. 1 b7 [) y2 |5 q; ]' U
  7. /* PVD configuration functions ************************************************/
    $ T) W+ m# `* _5 o  o3 }0 K* ^2 R
  8. void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel);
    ; P5 @7 A8 o! l1 R
  9. void PWR_PVDCmd(FunctionalState NewState);
    % K) B- e& y  @5 }9 C: [2 n- j

  10. 2 O- L, N0 H, q2 ^# `
  11. void PWR_WakeUpPinCmd(FunctionalState NewState);
    + s- b% |5 d1 u6 E6 Q# S3 i

  12. 8 l/ ]+ A, @& z5 f* v, \1 R
  13. /* Main and Backup Regulators configuration functions *************************/
    : \0 Q7 m, n! d+ @) e
  14. void PWR_BackupRegulatorCmd(FunctionalState NewState);; O2 ^1 L, @3 H6 O+ x
  15. void PWR_MainRegulatorModeConfig(uint32_t PWR_Regulator_Voltage);
    , K( Y3 M7 U: S; [4 a
  16. void PWR_OverDriveCmd(FunctionalState NewState);
    5 {7 Q5 A( a3 E* m) O/ U) \0 @1 t
  17. void PWR_OverDriveSWCmd(FunctionalState NewState);
    ! P- s. U; D8 o, ?. g
  18. void PWR_UnderDriveCmd(FunctionalState NewState);
    & V5 c$ t& N/ r

  19. 8 Z: Y5 f. S- ^" G
  20. /* FLASH Power Down configuration functions ***********************************/ 4 g; g. q9 x! ]* |1 i  d
  21. void PWR_FlashPowerDownCmd(FunctionalState NewState);
    ' N6 T/ R! P- S0 N

  22. ! O/ Z: q5 b& J5 ^2 r) G' C( Z
  23. /* Low Power modes configuration functions ************************************/
    / o1 m* `1 z- T0 p, m4 s* \- L
  24. void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry);4 m+ T5 A4 s5 E5 s3 M. {
  25. void PWR_EnterUnderDriveSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry);
    0 q- T( e, E* C2 |* r, W8 ?
  26. void PWR_EnterSTANDBYMode(void);' b- R) u, J) F1 j8 g( U
  27. * x1 k9 T9 }+ V% A$ j# O+ M
  28. /* Flags management functions *************************************************/ ' Q, W1 ]7 {# P+ F, J' z+ G  C
  29. FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG);
    . P( t: s( M0 A9 V+ w% y7 N
  30. void PWR_ClearFlag(uint32_t PWR_FLAG);1 r0 {8 O$ d' d9 A, G+ y

  31. " R8 B9 d' @! D# i) c  p
复制代码
9 y! A! p3 d& l' W1 @4 \: c
04. 结构体封装3 I- e3 S3 R. ~8 ~
  1. /** % n) r& @: d; B% B* B; X+ U
  2.   * @brief Power Control& m! U" G4 K/ @5 d6 ?* ]
  3.   */
    2 @7 ]3 ~; ^, y* Q% Q$ Q; Y/ t8 f
  4. $ r, Z- {- E& b+ O$ }" p$ v
  5. typedef struct
    3 X% Q% L4 n0 J# c
  6. {
    $ u6 c2 F4 l7 ?$ m5 Q4 S
  7.   __IO uint32_t CR;   /*!< PWR power control register,        Address offset: 0x00 */. i' y  z9 \$ d$ L
  8.   __IO uint32_t CSR;  /*!< PWR power control/status register, Address offset: 0x04 */
    8 Y6 e+ _8 U  n
  9. } PWR_TypeDef;
复制代码

3 ^1 @) W1 \- {8 ]# Z" A6 r
赞 收藏 评论0 发布时间:2022-3-30 11:00

举报

0个回答

所属标签

相似技术帖

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
人形机器人运动控制、感知与智能配电
半导体创新技术与应用方向
EE架构与软件定义汽车
12V/48V 汽车智能配电(SPD)
区域控制单元(ZCU)与分区架构
关注我们
st-img 微信公众号
st-img 手机版