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

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

[复制链接]
STMCU小助手 发布时间:2022-3-30 11:00
01. 概述
! e$ [' R5 Z: K很多单片机都有低功耗模式,STM32F4 也不例外。在系统或电源复位以后,微控制器处于运行状态。运行状态下的 HCLK 为 CPU 提供时钟,内核执行程序代码。当 CPU 不需继续运行时,可以利用多个低功耗模式来节省功耗,例如等待某个外部事件时。用户需要根据最低电源消耗,最快速启动时间和可用的唤醒源等条件,选定一个最佳的低功耗模式。- M2 u1 k& y& D0 z3 T; w+ \. K' t

  w, z4 b3 ?4 x7 V+ f3 [在stm32f4xx_pwr.c 和stm32f4xx_pwr.h 文件中。* V' b  ]6 ^5 q! b0 `( i

; M/ U6 R: l, ]4 k02. 相关类型
# J8 l5 U1 b1 ]) ?* {PWR_PVD_detection_level
) U. _8 k% F! q, G1 F* h$ v3 ]% E3 K* W# {( D
  1. /** @defgroup PWR_PVD_detection_level 5 u, i8 x7 R/ ?( g% F2 J+ Z
  2.   * @{3 H; @, ~! q0 G/ }/ j& |
  3.   */
    ( Z& B/ O" D7 D0 O$ Z7 H
  4. #define PWR_PVDLevel_0                  PWR_CR_PLS_LEV0
    4 i/ m0 f+ j7 i( k6 g! l- Y
  5. #define PWR_PVDLevel_1                  PWR_CR_PLS_LEV1% R$ v5 H4 r. w" t, I- }
  6. #define PWR_PVDLevel_2                  PWR_CR_PLS_LEV2
    3 o# M+ S# g0 ^7 d6 B# A( {1 M
  7. #define PWR_PVDLevel_3                  PWR_CR_PLS_LEV36 \, }; j' ?) B# r" P" M' H
  8. #define PWR_PVDLevel_4                  PWR_CR_PLS_LEV4, a/ r6 [2 X1 `3 x
  9. #define PWR_PVDLevel_5                  PWR_CR_PLS_LEV5
    5 M4 x3 v& [0 p" L. z" V
  10. #define PWR_PVDLevel_6                  PWR_CR_PLS_LEV6# P0 A; _3 Q/ w, f( `
  11. #define PWR_PVDLevel_7                  PWR_CR_PLS_LEV7+ g- F; J  M* f* d7 `
  12. 4 O! P6 B: E) Y$ |5 ~  ^' l
  13. #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_0) || ((LEVEL) == PWR_PVDLevel_1)|| \
    3 d& F. Z! G( L9 j- w" o0 Z
  14.                                  ((LEVEL) == PWR_PVDLevel_2) || ((LEVEL) == PWR_PVDLevel_3)|| \
    8 E0 G, \! n* N5 J/ q
  15.                                  ((LEVEL) == PWR_PVDLevel_4) || ((LEVEL) == PWR_PVDLevel_5)|| \4 Q: m- v% q* W( F' l; g6 y
  16.                                  ((LEVEL) == PWR_PVDLevel_6) || ((LEVEL) == PWR_PVDLevel_7))
复制代码

6 w& P! X6 R: e5 M) TPWR_Regulator_state_in_STOP_mode# Z* Y+ X) m) G) w! W" n

) D8 ?2 d- \: _2 a) t) a
  1. /** @defgroup PWR_Regulator_state_in_STOP_mode
    3 @- m6 a0 z4 V
  2.   * @{# P( M" |) S. ~. x5 i4 Z
  3.   */
    $ J& P& |% ?8 \# N) K
  4. #define PWR_MainRegulator_ON                        ((uint32_t)0x00000000)% U2 G8 `0 d- k6 ~
  5. #define PWR_LowPowerRegulator_ON                    PWR_CR_LPDS+ Z$ P: l2 Y% d2 e
  6. 4 |  l4 ?3 Y& W) F+ C  T
  7. /* --- PWR_Legacy ---*/3 S6 v; E9 M; J) n2 Z. n
  8. #define PWR_Regulator_ON                            PWR_MainRegulator_ON
    3 ]. P6 f& i" f: Q
  9. #define PWR_Regulator_LowPower                      PWR_LowPowerRegulator_ON
    . m( d) s2 O' q7 J  w1 S- w& K
  10. 4 U% b$ Z/ F& a- m3 [9 S
  11. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MainRegulator_ON) || \3 q5 Y+ @! y3 p, v: X0 n" D4 Q
  12.                                      ((REGULATOR) == PWR_LowPowerRegulator_ON))
复制代码

) N9 C" Z  p1 p1 |PWR_Regulator_state_in_UnderDrive_mode" ~: P3 Q; [& Q! H  \

# r/ \6 h9 @* l- M/ P; E. k. A
  1. /** @defgroup PWR_Regulator_state_in_UnderDrive_mode
    ; F, k5 R( z( Q5 @' z- P" ~
  2.   * @{
    # \( O" H6 J) \. a, r
  3.   */
    , g8 [: v) T8 H% {
  4. #define PWR_MainRegulator_UnderDrive_ON               PWR_CR_MRUDS
    1 _# R3 |& A& k
  5. #define PWR_LowPowerRegulator_UnderDrive_ON           ((uint32_t)(PWR_CR_LPDS | PWR_CR_LPUDS))
    0 P# {+ U5 g. e: D  Y

  6. 8 D6 a' e" R* V) [, U, m. v
  7. #define IS_PWR_REGULATOR_UNDERDRIVE(REGULATOR) (((REGULATOR) == PWR_MainRegulator_UnderDrive_ON) || \/ p2 M! i) v" J
  8.                                                 ((REGULATOR) == PWR_LowPowerRegulator_UnderDrive_ON))
复制代码
3 ]; U  ^9 u: {6 Q0 S
PWR_STOP_mode_entry
$ g/ {" O4 ]5 N0 `6 |# ^7 E
4 D2 ~- y0 |; p& l) g
  1. /** @defgroup PWR_STOP_mode_entry
    * g  @! C( I4 f3 k; _
  2.   * @{* Q" T: ~4 I, P/ ?
  3.   */
    5 A% x3 M+ D" A8 E
  4. #define PWR_STOPEntry_WFI               ((uint8_t)0x01)
    & \9 b0 H9 z+ ?; E5 m
  5. #define PWR_STOPEntry_WFE               ((uint8_t)0x02)
    : \. B) z; E2 L. G! m2 Y8 l
  6. #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE))
复制代码

# E2 x" ?2 H% E: ^7 I0 aPWR_Regulator_Voltage_Scale: Z; `5 Q, Q2 Q& e

, C0 P- f! R8 D* @9 I' d
  1. /** @defgroup PWR_Regulator_Voltage_Scale ; z) z1 x! r% s4 P2 G! @
  2.   * @{* L  c3 m/ e6 s1 Z
  3.   */
    4 w! x  @( J" X+ Q- N$ A' I
  4. #define PWR_Regulator_Voltage_Scale1    ((uint32_t)0x0000C000)
    ) \/ V* u/ |: Q7 X/ N9 @! w# U
  5. #define PWR_Regulator_Voltage_Scale2    ((uint32_t)0x00008000)
    % s! ?* [9 K& a
  6. #define PWR_Regulator_Voltage_Scale3    ((uint32_t)0x00004000)2 w: j1 {8 N; a. n& S  X& x( s
  7. #define IS_PWR_REGULATOR_VOLTAGE(VOLTAGE) (((VOLTAGE) == PWR_Regulator_Voltage_Scale1) || \
    : l# `" m* O8 d6 ]! z: u: f
  8.                                            ((VOLTAGE) == PWR_Regulator_Voltage_Scale2) || \% x- C( Q' e8 N0 n# p
  9.                                            ((VOLTAGE) == PWR_Regulator_Voltage_Scale3))
复制代码

' M! Y8 z# P+ @# |PWR_Flag
# f) V1 U  C& y1 a# G/ i

7 C1 B9 r) V6 |; ]( }
  1. /** @defgroup PWR_Flag * h9 _4 _! T8 v! B. D# O" }
  2.   * @{
    2 ?8 d$ h- w. Z! @
  3.   */9 b6 v& S) O6 F$ N% ^
  4. #define PWR_FLAG_WU                     PWR_CSR_WUF
      L4 M2 _" A* \3 {3 w' H
  5. #define PWR_FLAG_SB                     PWR_CSR_SBF
    7 ~3 C" Y0 F1 H3 U& C. B/ V1 d
  6. #define PWR_FLAG_PVDO                   PWR_CSR_PVDO
    4 q$ y& ]* t$ C, W+ _! q3 W
  7. #define PWR_FLAG_BRR                    PWR_CSR_BRR
    8 h/ ]: H  u1 S8 K0 d, z# P! T$ L
  8. #define PWR_FLAG_VOSRDY                 PWR_CSR_VOSRDY
    $ w" Y5 ~/ |, z' c, d0 e
  9. #define PWR_FLAG_ODRDY                  PWR_CSR_ODRDY2 y, P  N, W$ N/ m+ W: B9 W
  10. #define PWR_FLAG_ODSWRDY                PWR_CSR_ODSWRDY+ F$ x' d6 z% s; ~
  11. #define PWR_FLAG_UDRDY                  PWR_CSR_UDSWRDY" `- B& ]7 R& H
  12. : x  l) A6 \2 y  _0 u5 I' V# N
  13. /* --- FLAG Legacy ---*/
    6 t$ p' A. x4 N6 Y" J2 r5 `
  14. #define PWR_FLAG_REGRDY                  PWR_FLAG_VOSRDY               
    ! D$ S" _; J' n$ v
  15.   ^0 K: x+ N2 \* L$ o4 \0 _$ q) Y
  16. #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \
    ; Z& X* u) }! Z
  17.                                ((FLAG) == PWR_FLAG_PVDO) || ((FLAG) == PWR_FLAG_BRR) || \
    4 [2 Z% P0 g4 c! l! `. \
  18.                                ((FLAG) == PWR_FLAG_VOSRDY) || ((FLAG) == PWR_FLAG_ODRDY) || \
    / q7 D( j( f# t' ^$ M
  19.                                ((FLAG) == PWR_FLAG_ODSWRDY) || ((FLAG) == PWR_FLAG_UDRDY))
    , f+ [& p7 ^5 P: Y
  20. / B3 p8 k* b! S

  21. & V( B- Q' x  n2 c6 ?7 C
  22. #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \0 {) W- K# M2 _* R3 o; r) ^8 z% E
  23.                                  ((FLAG) == PWR_FLAG_UDRDY))
复制代码

) K  G0 a! W9 ]* v* N! a9 H03. 相关函数
. X3 o# g/ V' K* \5 \
9 b5 z5 Y0 }+ t4 L
  1. /* Function used to set the PWR configuration to the default reset state ******/
    * N5 ~. I! r3 B+ K/ ~3 o) W8 [
  2. void PWR_DeInit(void);7 v3 Y, g+ F& I7 J) L$ O5 S4 }( [5 A

  3. 9 o* T; |4 w5 f4 v- N2 ^4 a7 M
  4. /* Backup Domain Access function **********************************************/
    0 _8 o$ {- B3 n6 m& ~
  5. void PWR_BackupAccessCmd(FunctionalState NewState);% B# S( f% r. H: q. \
  6. 1 T6 e' {% w  y: \
  7. /* PVD configuration functions ************************************************/
    9 D; q; R9 c1 F  G0 W* a) T4 P
  8. void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel);, |% f; }% k7 G2 R/ H3 v4 h
  9. void PWR_PVDCmd(FunctionalState NewState);8 [8 A, @3 N3 w1 s& q3 b* r! n

  10. / I6 j; F6 [) G# V& E; F1 z" ?8 e5 o  m
  11. void PWR_WakeUpPinCmd(FunctionalState NewState);
    4 q1 ~3 `' @" \' K. x6 G! v
  12. % M$ d0 i: a4 D. }
  13. /* Main and Backup Regulators configuration functions *************************/ % |5 s% F4 ]: U1 q, j6 {% V
  14. void PWR_BackupRegulatorCmd(FunctionalState NewState);! ]4 S: d$ L( v0 ?8 [) Z+ {
  15. void PWR_MainRegulatorModeConfig(uint32_t PWR_Regulator_Voltage);2 H$ s, }/ z# V; {3 H: l( G
  16. void PWR_OverDriveCmd(FunctionalState NewState);
    - x3 D: c" c2 s2 n  V% z6 r
  17. void PWR_OverDriveSWCmd(FunctionalState NewState);
    7 G, |* o% R7 g' ^1 |
  18. void PWR_UnderDriveCmd(FunctionalState NewState);3 \# y. r$ A: A
  19. % |4 Z, p, ^! n# |: T. l( m
  20. /* FLASH Power Down configuration functions ***********************************/
    , \1 }5 `2 Z4 ]8 H$ t4 @+ d2 T
  21. void PWR_FlashPowerDownCmd(FunctionalState NewState);
    3 w4 W7 P$ _: h2 ~0 g% o% A
  22.   f$ J, f8 s! ^; N$ R& q! v  p' y
  23. /* Low Power modes configuration functions ************************************/ % f' c4 r* u" g4 E
  24. void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry);
    . \. @' ^5 j; E! c
  25. void PWR_EnterUnderDriveSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry);6 F4 R! H$ C5 T. z' A
  26. void PWR_EnterSTANDBYMode(void);& V2 I% J; v' d' f, a

  27. 6 s5 x5 S9 h: Q& j% p6 G, Z
  28. /* Flags management functions *************************************************/ 0 x! ^0 Z) J3 v' x; X* i1 W! v/ ]
  29. FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG);
    6 A4 h. O8 p  Q4 \7 c
  30. void PWR_ClearFlag(uint32_t PWR_FLAG);
    / U4 u# `  D+ D( i. i9 W6 A: _5 Q- H
  31. 4 |& b) h! c; H) g' o3 E9 G
复制代码
2 Y/ I, O9 R" z; X
04. 结构体封装
- _2 O$ i! a8 c
  1. /** 0 @3 J  Q+ Z; o# W0 k1 w
  2.   * @brief Power Control7 b; n0 V% C( R' j2 K+ ?
  3.   */5 D9 Z6 O) L8 ]0 u

  4.   |2 G) u4 Y! W: ^8 T5 x6 l
  5. typedef struct4 `5 X1 s. H/ U2 Z1 ^' D  ^, Q
  6. {
    ! k% G! \) N, \
  7.   __IO uint32_t CR;   /*!< PWR power control register,        Address offset: 0x00 */+ ~; q0 \3 B9 r
  8.   __IO uint32_t CSR;  /*!< PWR power control/status register, Address offset: 0x04 */8 H8 B! a$ V- [4 o8 }6 W1 [4 D8 O
  9. } PWR_TypeDef;
复制代码

; h( v' O% M. {$ k0 i
收藏 评论0 发布时间:2022-3-30 11:00

举报

0个回答

所属标签

相似分享

官网相关资源

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