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

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

[复制链接]
STMCU小助手 发布时间:2022-6-14 14:39
01. 概述
# u  Q7 H" i8 ~2 I$ V很多单片机都有低功耗模式,STM32F4 也不例外。在系统或电源复位以后,微控制器处于运行状态。运行状态下的 HCLK 为 CPU 提供时钟,内核执行程序代码。当 CPU 不需继续运行时,可以利用多个低功耗模式来节省功耗,例如等待某个外部事件时。用户需要根据最低电源消耗,最快速启动时间和可用的唤醒源等条件,选定一个最佳的低功耗模式。
" t6 o1 A) C: v% X( M' w4 R) Z. ~4 u: o
在stm32f4xx_pwr.c 和stm32f4xx_pwr.h 文件中。/ ~6 ?; e2 E* D' o  j0 f* V: h0 K

; T  k4 B8 i( ~. `" m& g02. 相关类型
+ U! g( L+ s/ i5 {PWR_PVD_detection_level
7 W- Q) A8 R, r# ~1 Y9 Z/ A, N( K7 |# j
  1. /** @defgroup PWR_PVD_detection_level
    / g* d, s, w' A8 y6 Q$ a
  2.   * @{2 n' j8 d5 S2 b8 q! r! l# F* j. ^
  3.   */
    ( q1 S: [6 v0 m9 L
  4. #define PWR_PVDLevel_0                  PWR_CR_PLS_LEV0! H" o# r. h7 f% q  A+ G: Z! u
  5. #define PWR_PVDLevel_1                  PWR_CR_PLS_LEV1, P1 M' I/ G8 @8 B: V
  6. #define PWR_PVDLevel_2                  PWR_CR_PLS_LEV2$ [6 X2 M  N. E# d% {: p7 [+ Q
  7. #define PWR_PVDLevel_3                  PWR_CR_PLS_LEV3. |) G, f' m+ x) y. P+ f  Q1 {
  8. #define PWR_PVDLevel_4                  PWR_CR_PLS_LEV4
    ) j7 j0 R! O5 \- q7 f! x6 D1 ^
  9. #define PWR_PVDLevel_5                  PWR_CR_PLS_LEV5
    2 v5 W5 q& k" a) k
  10. #define PWR_PVDLevel_6                  PWR_CR_PLS_LEV6
    * z$ t- m* f. `! X
  11. #define PWR_PVDLevel_7                  PWR_CR_PLS_LEV7
    5 \% s3 x+ h1 p% j

  12. 1 l6 W5 d$ C3 I% P* x! f, }
  13. #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_0) || ((LEVEL) == PWR_PVDLevel_1)|| \  x6 Y+ ?7 q* _! p
  14.                                  ((LEVEL) == PWR_PVDLevel_2) || ((LEVEL) == PWR_PVDLevel_3)|| \
    6 j& R4 C+ C6 B% U  r- r
  15.                                  ((LEVEL) == PWR_PVDLevel_4) || ((LEVEL) == PWR_PVDLevel_5)|| \
    $ ]4 s9 w  _: u# s0 C" p& o
  16.                                  ((LEVEL) == PWR_PVDLevel_6) || ((LEVEL) == PWR_PVDLevel_7))
复制代码

3 o6 r) ]) h2 m7 ^  \. e1 hPWR_Regulator_state_in_STOP_mode" D' ]1 c& n. ]/ C. W  f
8 e" o& ?* A3 M: ^
  1. /** @defgroup PWR_Regulator_state_in_STOP_mode ) ]" E7 p- W; J4 C
  2.   * @{3 w* ?8 i, y6 ?4 F0 s. P
  3.   */. b+ }, u$ M" Q. u& {
  4. #define PWR_MainRegulator_ON                        ((uint32_t)0x00000000)
    3 V( G/ F. l0 L2 v
  5. #define PWR_LowPowerRegulator_ON                    PWR_CR_LPDS
    8 ~$ B  A9 j# u; _* W, H. W2 G
  6. , T5 A; [4 D! b$ U
  7. /* --- PWR_Legacy ---*/) M, D8 q$ S0 w2 P; ^# m' V5 W
  8. #define PWR_Regulator_ON                            PWR_MainRegulator_ON
    1 D3 F0 {; n1 A7 t
  9. #define PWR_Regulator_LowPower                      PWR_LowPowerRegulator_ON
    2 @; j! U* C- o9 e! h
  10. % V( y: ^! x6 A
  11. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MainRegulator_ON) || \
    1 Y" p& F# `) J6 `' j0 A
  12.                                      ((REGULATOR) == PWR_LowPowerRegulator_ON))
复制代码
* K0 ?" c: H0 W7 a6 w. m
PWR_Regulator_state_in_UnderDrive_mode6 k  n: e2 [  Q) e9 a. F
" Q7 A1 K: T' H5 f$ w9 a
  1. /** @defgroup PWR_Regulator_state_in_UnderDrive_mode
    3 i5 E5 w6 m7 d9 o5 v( s1 }( V
  2.   * @{2 f. m: p, m- f0 x
  3.   */7 A: G4 M. [# ^$ ], A( k/ y4 y: Y
  4. #define PWR_MainRegulator_UnderDrive_ON               PWR_CR_MRUDS
    , `: F- C% F; \4 C
  5. #define PWR_LowPowerRegulator_UnderDrive_ON           ((uint32_t)(PWR_CR_LPDS | PWR_CR_LPUDS)): ]0 L! ]% k+ m+ ]

  6. 3 [) l# F3 r" k) \3 N1 V% |
  7. #define IS_PWR_REGULATOR_UNDERDRIVE(REGULATOR) (((REGULATOR) == PWR_MainRegulator_UnderDrive_ON) || \
    8 }' J. E! ^) r
  8.                                                 ((REGULATOR) == PWR_LowPowerRegulator_UnderDrive_ON))
复制代码

: s1 B% n5 d: T3 b  _PWR_STOP_mode_entry, a! _& z5 c  ^7 S5 j- i3 x
6 z; A6 I/ m& z" _, l
  1. /** @defgroup PWR_STOP_mode_entry 8 {7 R  U) {* z' R' k% r
  2.   * @{
    7 I# s' X7 W( V2 V5 K
  3.   */
    ) \0 u# C& n$ L
  4. #define PWR_STOPEntry_WFI               ((uint8_t)0x01)# O! y5 x* F9 R& k2 `; E( f: Y' s
  5. #define PWR_STOPEntry_WFE               ((uint8_t)0x02)
    8 m2 N4 ^* R; l6 Z! _
  6. #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE))
复制代码
/ |& u  S) g1 `1 b" N% l
PWR_Regulator_Voltage_Scale% G, K  R0 ?6 F" G

* g& ^: `( f' V$ b( [- \
  1. /** @defgroup PWR_Regulator_Voltage_Scale 6 B/ w- l# ~, @  h" Z
  2.   * @{; s/ V1 y( D4 \' ]* T; C' i
  3.   */4 {* b: t# G6 t  l) A, [
  4. #define PWR_Regulator_Voltage_Scale1    ((uint32_t)0x0000C000)
    0 h5 [6 E- n) D+ I
  5. #define PWR_Regulator_Voltage_Scale2    ((uint32_t)0x00008000)! f4 x/ |" L+ j
  6. #define PWR_Regulator_Voltage_Scale3    ((uint32_t)0x00004000)
    ! I, i; I3 d7 _
  7. #define IS_PWR_REGULATOR_VOLTAGE(VOLTAGE) (((VOLTAGE) == PWR_Regulator_Voltage_Scale1) || \
    % [0 h8 h0 u0 j( f- e4 @; J
  8.                                            ((VOLTAGE) == PWR_Regulator_Voltage_Scale2) || \
    ' [6 E8 g6 _0 g; V0 E' _7 o
  9.                                            ((VOLTAGE) == PWR_Regulator_Voltage_Scale3))
复制代码

: O" g0 ?8 R2 q6 }, |  \6 xPWR_Flag* o/ V! N' {- Q4 i0 a$ t
% e, K7 i  h# [" F
  1. /** @defgroup PWR_Flag . q; f5 g& d6 c  z: n
  2.   * @{
    3 D! _/ j' e, a* L$ k9 V# E
  3.   */  U! y/ a& [2 V4 g. J4 s* D8 A! B
  4. #define PWR_FLAG_WU                     PWR_CSR_WUF
    + k# Q! |  X: G1 @4 y% g3 ^7 }8 I
  5. #define PWR_FLAG_SB                     PWR_CSR_SBF
    + `, T, G- h1 l- n. t
  6. #define PWR_FLAG_PVDO                   PWR_CSR_PVDO/ w4 t! Q  k' T
  7. #define PWR_FLAG_BRR                    PWR_CSR_BRR, e& c# r* A5 N: K$ S/ o
  8. #define PWR_FLAG_VOSRDY                 PWR_CSR_VOSRDY
    # @/ v) u) `  a" ~" v
  9. #define PWR_FLAG_ODRDY                  PWR_CSR_ODRDY
    , i' y8 L$ K& q$ {
  10. #define PWR_FLAG_ODSWRDY                PWR_CSR_ODSWRDY7 ~1 |4 E9 M8 z% o) j. z
  11. #define PWR_FLAG_UDRDY                  PWR_CSR_UDSWRDY
    . B, |: P; Q: Y* ~1 I: k

  12. ' m- u! S2 F6 [( x( \
  13. /* --- FLAG Legacy ---*/) }$ ~: ]0 S+ \2 ~+ x$ q
  14. #define PWR_FLAG_REGRDY                  PWR_FLAG_VOSRDY               
    + n! l" O5 i% P3 B

  15. 3 L% T8 c/ W0 c7 P/ k
  16. #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \. k: A' P) c, o5 ^& I+ N7 z
  17.                                ((FLAG) == PWR_FLAG_PVDO) || ((FLAG) == PWR_FLAG_BRR) || \+ W5 T, m% X8 l* T$ Q2 b5 T2 X/ q# U
  18.                                ((FLAG) == PWR_FLAG_VOSRDY) || ((FLAG) == PWR_FLAG_ODRDY) || \
    % t$ Y4 g: J* m+ }. Q
  19.                                ((FLAG) == PWR_FLAG_ODSWRDY) || ((FLAG) == PWR_FLAG_UDRDY))! q" I; p- [9 x7 Q$ ?0 C( ?# _& c
  20. ) `0 s0 }2 X" ~4 w& Q! M1 Z  C
  21. ; T) Z& s" k5 i* i! Y0 {7 d; ^
  22. #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \" e2 i9 e. G' X' r) i9 d9 A
  23.                                  ((FLAG) == PWR_FLAG_UDRDY))
复制代码

$ i" D) E2 R- k0 y03. 相关函数& ?$ v+ z/ @+ P. ^) n2 {7 T

+ ?7 u4 H# t6 C2 w
  1. /* Function used to set the PWR configuration to the default reset state ******/
    ' E8 S( Y  [9 O" R
  2. void PWR_DeInit(void);
    9 W0 ^6 ]1 a* X/ {, L

  3. $ ^4 X1 U% A: g! {( A
  4. /* Backup Domain Access function **********************************************/ ) ]. ]/ t3 L+ q8 M; _
  5. void PWR_BackupAccessCmd(FunctionalState NewState);
    # d- K8 [8 }) q
  6. 0 a7 e# h8 b" ~4 v; ?
  7. /* PVD configuration functions ************************************************/
    , T) o6 O2 S8 J
  8. void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel);1 \: l* T5 p6 k
  9. void PWR_PVDCmd(FunctionalState NewState);
    $ e* u% F4 _# p
  10. % H+ ?2 c$ Y0 ]) l' o* \. l
  11. void PWR_WakeUpPinCmd(FunctionalState NewState);7 x: \1 z% S: h( d

  12. ' k9 T4 {- C# i" O, U
  13. /* Main and Backup Regulators configuration functions *************************/
    $ s5 G2 b! z- r! M8 Q8 u
  14. void PWR_BackupRegulatorCmd(FunctionalState NewState);
    ; t( {, Z* `6 r
  15. void PWR_MainRegulatorModeConfig(uint32_t PWR_Regulator_Voltage);
    ; o% }, \; ]* i0 F' P  T( u
  16. void PWR_OverDriveCmd(FunctionalState NewState);
    8 |; V5 w% w0 p+ U) X) t( v
  17. void PWR_OverDriveSWCmd(FunctionalState NewState);# }' g: i6 T" x& [2 w, G$ g7 x
  18. void PWR_UnderDriveCmd(FunctionalState NewState);
    $ H( w8 a! z, i2 v

  19. , |4 t2 Y4 s- ~( U" j1 ^# I+ a
  20. /* FLASH Power Down configuration functions ***********************************/ 2 X* Q9 @- W/ f# {
  21. void PWR_FlashPowerDownCmd(FunctionalState NewState);% P+ b$ d$ a9 E. G  K4 I
  22. 4 l2 b, d! L4 j  w- L8 n6 k
  23. /* Low Power modes configuration functions ************************************/ ! l: }" G  a! {* N# K) n" J
  24. void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry);4 ]4 E8 L' O7 p; a% r
  25. void PWR_EnterUnderDriveSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry);
    6 i/ j% @1 |& q* b7 U3 @) U/ n9 `
  26. void PWR_EnterSTANDBYMode(void);& V+ T. ?; M* d! L# _; |7 ]" j

  27. % {% F4 X( \8 e- N# ~
  28. /* Flags management functions *************************************************/ ( r- A. E# c; ?) j
  29. FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG);4 n6 D; q1 Y3 c3 e7 g; `8 Q
  30. void PWR_ClearFlag(uint32_t PWR_FLAG);
复制代码

* s; [0 b. y: k9 o; p" s04. 结构体封装6 t7 F" x* ~! r
  1. /**
    2 }+ h# H- [9 ^( i8 c) B
  2.   * @brief Power Control
    7 G" b! ?3 G5 f# h& \8 l- u
  3.   */
    6 {# m0 H$ }* n) u* f

  4. , L: Z; d/ }; f, R# Z/ K
  5. typedef struct
    9 g; z' p9 z" F; j) W
  6. {) l6 E+ j6 Y$ T8 _3 \% x: E6 {
  7.   __IO uint32_t CR;   /*!< PWR power control register,        Address offset: 0x00 */
    - |7 l1 S8 b) m1 V4 _+ K
  8.   __IO uint32_t CSR;  /*!< PWR power control/status register, Address offset: 0x04 */+ k5 W) b/ L9 y( y0 t: Z
  9. } PWR_TypeDef;
复制代码

) q% H& n9 Y$ W8 G1 a% p! F7 d3 L# _8 |0 i; ?& y

/ r* o4 q" U3 [, E
赞 收藏 评论0 发布时间:2022-6-14 14:39

举报

0个回答

所属标签

相似技术帖

官网相关资源

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