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

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

[复制链接]
STMCU小助手 发布时间:2022-3-30 11:00
01. 概述7 S; R7 f0 a) a; T% _; K
很多单片机都有低功耗模式,STM32F4 也不例外。在系统或电源复位以后,微控制器处于运行状态。运行状态下的 HCLK 为 CPU 提供时钟,内核执行程序代码。当 CPU 不需继续运行时,可以利用多个低功耗模式来节省功耗,例如等待某个外部事件时。用户需要根据最低电源消耗,最快速启动时间和可用的唤醒源等条件,选定一个最佳的低功耗模式。
3 N0 j9 M) H1 v( D. g* h3 \+ a# C; v$ p( X( Q0 m5 O* P) N7 ~
在stm32f4xx_pwr.c 和stm32f4xx_pwr.h 文件中。
! ?( v% M! ]: A* G* s+ K/ W/ _% r1 v- g
02. 相关类型. B* h0 ^8 z7 i/ U, l6 Y' ]6 ]
PWR_PVD_detection_level/ H- Q0 s$ n7 ?' K+ i- g" u% k

1 d4 O5 N% m# M2 d+ g$ a8 }1 e( K+ Z
  1. /** @defgroup PWR_PVD_detection_level 4 `4 Y2 N9 B  F$ g. d$ Q  x
  2.   * @{+ S( j) w7 B8 @( {, `( e' j3 F" X
  3.   */ + A; Q1 d* h% q6 S
  4. #define PWR_PVDLevel_0                  PWR_CR_PLS_LEV0
    1 a, I( h4 V' K+ o' D: c
  5. #define PWR_PVDLevel_1                  PWR_CR_PLS_LEV1
    - I# t0 {7 e4 @1 u8 v$ |, H- X) g
  6. #define PWR_PVDLevel_2                  PWR_CR_PLS_LEV2
    , m# v2 m* @; o* _6 L5 L
  7. #define PWR_PVDLevel_3                  PWR_CR_PLS_LEV36 k' _, o+ [- h* G
  8. #define PWR_PVDLevel_4                  PWR_CR_PLS_LEV4% y( P) W- _3 q1 M
  9. #define PWR_PVDLevel_5                  PWR_CR_PLS_LEV5
    ( R- B2 T% ?7 Y5 c
  10. #define PWR_PVDLevel_6                  PWR_CR_PLS_LEV6
    & E8 x! ]5 m: K0 J# S; J" p4 S& s
  11. #define PWR_PVDLevel_7                  PWR_CR_PLS_LEV7
    / F2 p5 y. H9 O& V/ ~
  12. , f" I9 Q+ ~( r) W' U
  13. #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_0) || ((LEVEL) == PWR_PVDLevel_1)|| \
    + u: h. Y( Q& [; v* G0 q
  14.                                  ((LEVEL) == PWR_PVDLevel_2) || ((LEVEL) == PWR_PVDLevel_3)|| \
    $ c9 Z( j- Q' U2 c
  15.                                  ((LEVEL) == PWR_PVDLevel_4) || ((LEVEL) == PWR_PVDLevel_5)|| \
    4 o, p; ~. ]5 F% I4 R: I9 A
  16.                                  ((LEVEL) == PWR_PVDLevel_6) || ((LEVEL) == PWR_PVDLevel_7))
复制代码

6 g. ?+ O8 c/ ?4 V1 QPWR_Regulator_state_in_STOP_mode
6 L4 D9 e& e+ `8 A
: b9 c/ O1 O; |9 X; T, Y
  1. /** @defgroup PWR_Regulator_state_in_STOP_mode # [% q9 A% z# |5 v
  2.   * @{
      U  P' x9 \3 b6 p1 t3 C
  3.   */+ d5 g; M, G) r: }" S5 z, `# l& O
  4. #define PWR_MainRegulator_ON                        ((uint32_t)0x00000000)
    & h* r; V. E1 ]& q9 M- {
  5. #define PWR_LowPowerRegulator_ON                    PWR_CR_LPDS
    * f0 ^" }8 z2 C" V
  6. 8 U3 \3 v( y  [& Q( V
  7. /* --- PWR_Legacy ---*/# j* t& h4 _2 K1 L6 u
  8. #define PWR_Regulator_ON                            PWR_MainRegulator_ON
    ( j( ?8 Y; z2 l
  9. #define PWR_Regulator_LowPower                      PWR_LowPowerRegulator_ON
    : d2 M4 u$ ~9 u- @7 k9 K5 a# H4 c

  10. - _7 U7 K# U5 D  w: ?
  11. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MainRegulator_ON) || \* x+ U/ e6 \  G- t
  12.                                      ((REGULATOR) == PWR_LowPowerRegulator_ON))
复制代码

6 ?& M8 O1 i. qPWR_Regulator_state_in_UnderDrive_mode
+ Y4 C% _7 D% S' y: O& F+ }8 u4 @6 l% I+ L
  1. /** @defgroup PWR_Regulator_state_in_UnderDrive_mode 1 X: |- u( C9 S" V! {( v0 Y& }
  2.   * @{+ Z+ y& N3 T9 m" Q
  3.   */
    # X% @. _0 u/ k$ w/ m8 M5 l! O, v
  4. #define PWR_MainRegulator_UnderDrive_ON               PWR_CR_MRUDS5 B; v  b3 j( S/ k# `6 \0 ?
  5. #define PWR_LowPowerRegulator_UnderDrive_ON           ((uint32_t)(PWR_CR_LPDS | PWR_CR_LPUDS))- E; k% v2 X6 D9 S: s$ _. a
  6. 1 A, J) _% |7 S8 g% e. I
  7. #define IS_PWR_REGULATOR_UNDERDRIVE(REGULATOR) (((REGULATOR) == PWR_MainRegulator_UnderDrive_ON) || \
    % C5 P$ K, w: X) P, r- T. P: N
  8.                                                 ((REGULATOR) == PWR_LowPowerRegulator_UnderDrive_ON))
复制代码

6 I, N; `8 G3 W; u2 _- j  rPWR_STOP_mode_entry
/ [) J$ c; {7 f3 r2 G! z: ?4 h/ c% V1 s# j7 n
  1. /** @defgroup PWR_STOP_mode_entry # h: K5 H; i) ^
  2.   * @{
    7 }. l. U6 [, r0 p3 t
  3.   */9 G* U' G1 N+ W4 A6 Y
  4. #define PWR_STOPEntry_WFI               ((uint8_t)0x01)$ r" T! r5 g4 g- \
  5. #define PWR_STOPEntry_WFE               ((uint8_t)0x02); G! U' P# w  N% D8 f1 w% i
  6. #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE))
复制代码
/ G- f; u* c3 t7 o7 O
PWR_Regulator_Voltage_Scale
! \9 ^2 _3 n, r; e0 G9 n
, L' K' Y' |# F
  1. /** @defgroup PWR_Regulator_Voltage_Scale + H* l" j& k) P7 r( y
  2.   * @{
    5 i' T! |  `* O0 x
  3.   */
    7 V1 j# _, n4 X( B) m
  4. #define PWR_Regulator_Voltage_Scale1    ((uint32_t)0x0000C000)* \1 E# |2 Q+ i7 N
  5. #define PWR_Regulator_Voltage_Scale2    ((uint32_t)0x00008000)
    & P2 \' Z- R. K3 S3 u
  6. #define PWR_Regulator_Voltage_Scale3    ((uint32_t)0x00004000)
    , J# K" r. G' s5 L
  7. #define IS_PWR_REGULATOR_VOLTAGE(VOLTAGE) (((VOLTAGE) == PWR_Regulator_Voltage_Scale1) || \
    - ]% o: X5 r( I: d5 K; W3 C- p
  8.                                            ((VOLTAGE) == PWR_Regulator_Voltage_Scale2) || \+ y2 {5 q% p* l% x. [4 \
  9.                                            ((VOLTAGE) == PWR_Regulator_Voltage_Scale3))
复制代码

( \( p% i" Z8 ]+ m/ ]: `8 F; ?" ZPWR_Flag

: E1 w- ~; `0 |* F, f
3 k% R1 l6 P# |' C1 l: X
  1. /** @defgroup PWR_Flag
    . z9 N: l9 _( S' X& K$ X6 Y+ \
  2.   * @{
    , J- b8 A; z6 l( ?% n" D* z
  3.   */
    " A* q) i$ T, Y4 p7 W
  4. #define PWR_FLAG_WU                     PWR_CSR_WUF: k/ Y# n* e+ z6 n* x' t
  5. #define PWR_FLAG_SB                     PWR_CSR_SBF
    ; Z) w+ c$ V+ t6 C! \7 _
  6. #define PWR_FLAG_PVDO                   PWR_CSR_PVDO- r6 [+ M7 E8 D; M/ T
  7. #define PWR_FLAG_BRR                    PWR_CSR_BRR: i0 q0 q) x1 \- e* k
  8. #define PWR_FLAG_VOSRDY                 PWR_CSR_VOSRDY5 k1 s) z# q* L3 U1 }- g4 W3 m
  9. #define PWR_FLAG_ODRDY                  PWR_CSR_ODRDY
    # H% ]' r4 ]6 a: Z
  10. #define PWR_FLAG_ODSWRDY                PWR_CSR_ODSWRDY
    5 |4 r4 \; t% J+ R9 j* e
  11. #define PWR_FLAG_UDRDY                  PWR_CSR_UDSWRDY% x* ]( m4 Y0 `

  12. 0 `0 E5 s4 F8 V% b3 A# s# s; a6 L" U  c
  13. /* --- FLAG Legacy ---*/
    ( S4 L: P8 ~& V  X2 C
  14. #define PWR_FLAG_REGRDY                  PWR_FLAG_VOSRDY               8 q; @6 W2 v# u$ T2 J+ v

  15. * _4 Z0 t+ a! T9 @# ]
  16. #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \8 X* }. j- v! @' j
  17.                                ((FLAG) == PWR_FLAG_PVDO) || ((FLAG) == PWR_FLAG_BRR) || \
    2 C/ S, z1 W+ u0 r
  18.                                ((FLAG) == PWR_FLAG_VOSRDY) || ((FLAG) == PWR_FLAG_ODRDY) || \' e0 L; W1 S% x
  19.                                ((FLAG) == PWR_FLAG_ODSWRDY) || ((FLAG) == PWR_FLAG_UDRDY))
    # @. U8 D  m) U
  20. : ^0 N# Z. h+ K

  21.   B) m. N' G7 D$ n( ]
  22. #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \+ r7 J; v. h+ x2 B' j4 E' w- X
  23.                                  ((FLAG) == PWR_FLAG_UDRDY))
复制代码
% K( B  ]) G% \5 n. J! a1 H( Y
03. 相关函数
# k1 h9 m2 P4 |$ h, Q
% g) y. W) j0 B5 s
  1. /* Function used to set the PWR configuration to the default reset state ******/
    / @! A# z3 |: w. F2 h, a: d
  2. void PWR_DeInit(void);
    8 q; V( Q  X$ H8 \4 X2 v
  3. $ V' Y$ j7 H" }$ g. u% G
  4. /* Backup Domain Access function **********************************************/ ! u1 T# A1 S7 j% T, s. J, x
  5. void PWR_BackupAccessCmd(FunctionalState NewState);
    1 |) U: j( E* ?; X, o
  6. - ^+ O; o" x; R% R$ x
  7. /* PVD configuration functions ************************************************/ 7 S8 d" ~/ B0 g( i/ C( J9 Y
  8. void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel);
    : D7 p4 ^% W, Y" p$ U! f% N
  9. void PWR_PVDCmd(FunctionalState NewState);
    1 n; J( T6 M) a
  10. ; I7 U4 o8 d7 }' f. o# e
  11. void PWR_WakeUpPinCmd(FunctionalState NewState);* g% x  H6 s0 g- K

  12. 6 @7 Z/ T) a  \: \9 C& G8 g
  13. /* Main and Backup Regulators configuration functions *************************/
    # m/ L: F0 X7 T  d) C
  14. void PWR_BackupRegulatorCmd(FunctionalState NewState);
    7 F: Q* O9 A8 L7 Q
  15. void PWR_MainRegulatorModeConfig(uint32_t PWR_Regulator_Voltage);$ V/ s- E6 }: l, S  j
  16. void PWR_OverDriveCmd(FunctionalState NewState);0 ~% G! w! C+ y" P2 z& c) @
  17. void PWR_OverDriveSWCmd(FunctionalState NewState);
    ! N0 _5 a7 Z% T: @4 j, M+ c
  18. void PWR_UnderDriveCmd(FunctionalState NewState);
    # W. f$ V9 L" v! J

  19. 7 b$ X/ T# T% n7 p" R
  20. /* FLASH Power Down configuration functions ***********************************/ ) G: ~; j; D  W9 z: f5 M6 j1 K
  21. void PWR_FlashPowerDownCmd(FunctionalState NewState);
    ! T* _- z/ _& s' h( J/ G
  22. 3 w; _" F8 P6 H; `# S* e1 {
  23. /* Low Power modes configuration functions ************************************/   p1 M; C8 t% I* p9 K: z6 G* B
  24. void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry);) l/ k7 P% ?5 h# Q( r4 A) I* G1 @
  25. void PWR_EnterUnderDriveSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry);
    - ]0 k$ \3 q% A/ l7 E
  26. void PWR_EnterSTANDBYMode(void);
    ) O; q4 ~" `( L% T8 s: F

  27. ) I- j$ Z  d' C
  28. /* Flags management functions *************************************************/
    % G* x% T! S: S3 {: {( C* c: E" u, ?
  29. FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG);
    * a- A8 m' G! P1 x) W. p
  30. void PWR_ClearFlag(uint32_t PWR_FLAG);' m9 R. H1 h+ O

  31. - y& P9 H( I) o  W
复制代码

7 Y- G1 F6 ^0 H04. 结构体封装. U* z# E. C, Z& c2 O5 T7 b
  1. /** 9 A  N$ f/ a4 X* z
  2.   * @brief Power Control  \* N" U1 ~% o
  3.   */
    9 ~. P0 N" w5 [# y( ^6 [9 Y

  4. 1 I. k4 F$ x2 C+ D* w
  5. typedef struct& U" g2 W* w2 m7 O
  6. {( Q: G2 a2 n% h3 \1 f0 B
  7.   __IO uint32_t CR;   /*!< PWR power control register,        Address offset: 0x00 */: z  @# Q2 z  T, k5 S4 j. d: b
  8.   __IO uint32_t CSR;  /*!< PWR power control/status register, Address offset: 0x04 */! T3 r3 a* ~9 K. |
  9. } PWR_TypeDef;
复制代码
5 V1 |3 T# W0 ~, i; Q
收藏 评论0 发布时间:2022-3-30 11:00

举报

0个回答

所属标签

相似分享

官网相关资源

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