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

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

[复制链接]
STMCU小助手 发布时间:2022-3-30 11:00
01. 概述& M1 {" }0 h3 ~( z+ }7 j
很多单片机都有低功耗模式,STM32F4 也不例外。在系统或电源复位以后,微控制器处于运行状态。运行状态下的 HCLK 为 CPU 提供时钟,内核执行程序代码。当 CPU 不需继续运行时,可以利用多个低功耗模式来节省功耗,例如等待某个外部事件时。用户需要根据最低电源消耗,最快速启动时间和可用的唤醒源等条件,选定一个最佳的低功耗模式。! a/ P) s. ]# y9 Y; G; ?9 Y$ [/ K
! B4 g, l. Y- M6 u0 a9 {1 Y
在stm32f4xx_pwr.c 和stm32f4xx_pwr.h 文件中。* e# Y$ A, {- a, r

1 ?; k3 A5 g: X$ R& ~( ~: f* n" W02. 相关类型: I+ B! I; a4 Q1 \, l9 _/ i/ E
PWR_PVD_detection_level
  u: d! f4 _9 L  Y' S5 ?" G
% [' q( Z- w4 _- O$ C, u# n+ D
  1. /** @defgroup PWR_PVD_detection_level
    * D$ z9 k/ H4 X& ^
  2.   * @{
    ' }! ^/ t0 s% X
  3.   */ , J1 w3 U/ m+ D+ @" y
  4. #define PWR_PVDLevel_0                  PWR_CR_PLS_LEV0
    $ ?$ E1 ]9 H  U
  5. #define PWR_PVDLevel_1                  PWR_CR_PLS_LEV1
    . j: a- M$ D, f: ?: Y: x7 {7 k0 D1 H$ j
  6. #define PWR_PVDLevel_2                  PWR_CR_PLS_LEV2# P8 z# v* T7 n9 R( M
  7. #define PWR_PVDLevel_3                  PWR_CR_PLS_LEV3
    ' P$ M: U8 X+ K( w' U8 d
  8. #define PWR_PVDLevel_4                  PWR_CR_PLS_LEV45 g3 |! K- h  I- ~
  9. #define PWR_PVDLevel_5                  PWR_CR_PLS_LEV5
    8 ~8 A& V+ G0 s* B) l
  10. #define PWR_PVDLevel_6                  PWR_CR_PLS_LEV61 A: q7 w! T  w
  11. #define PWR_PVDLevel_7                  PWR_CR_PLS_LEV7
    8 O% c; p" q, \: O# m) r

  12. , }8 M  h) P/ r! i1 g% {: v
  13. #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_0) || ((LEVEL) == PWR_PVDLevel_1)|| \
    * l* l6 A2 w  q1 }! g
  14.                                  ((LEVEL) == PWR_PVDLevel_2) || ((LEVEL) == PWR_PVDLevel_3)|| \1 M# m1 D% H" H0 {! f6 P
  15.                                  ((LEVEL) == PWR_PVDLevel_4) || ((LEVEL) == PWR_PVDLevel_5)|| \. P% n" E: ~7 @: ~0 ~
  16.                                  ((LEVEL) == PWR_PVDLevel_6) || ((LEVEL) == PWR_PVDLevel_7))
复制代码
0 ^3 H8 g+ B' q) l3 v) {9 E5 ^
PWR_Regulator_state_in_STOP_mode
- ^8 T: Q2 ]7 i8 C* h, p1 T, P0 A) y* v) Y
  1. /** @defgroup PWR_Regulator_state_in_STOP_mode
    2 E+ H' W8 k+ Z* v9 i# v) Q
  2.   * @{5 m# u% D9 n, S; H
  3.   */
    8 A7 y( [: d+ H
  4. #define PWR_MainRegulator_ON                        ((uint32_t)0x00000000)
      C! R6 h8 {" F
  5. #define PWR_LowPowerRegulator_ON                    PWR_CR_LPDS% ?2 H6 C5 v+ ^/ E5 \4 w7 }
  6. 5 ^0 U: |: N# R) [& D/ x
  7. /* --- PWR_Legacy ---*/
    8 |) n0 J: ]' ~9 E
  8. #define PWR_Regulator_ON                            PWR_MainRegulator_ON
    9 z' C6 l/ o/ J0 J6 v
  9. #define PWR_Regulator_LowPower                      PWR_LowPowerRegulator_ON
    , n3 u8 f# S0 _; q) T- l; i
  10. + U, v$ e- s0 D: s- J
  11. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MainRegulator_ON) || \+ u5 F6 r. g  p8 R" Z2 y
  12.                                      ((REGULATOR) == PWR_LowPowerRegulator_ON))
复制代码

2 x8 |  B# Z  e( F  o; ~  _, t) UPWR_Regulator_state_in_UnderDrive_mode
3 {7 |2 s5 _# x  w3 V1 ]1 `" L8 Y8 |) D: j9 |9 T
  1. /** @defgroup PWR_Regulator_state_in_UnderDrive_mode
    % D" Q% i! |5 ~, e0 R! I
  2.   * @{! |4 ~% X& T" b7 p  _
  3.   */
    ! M' U% s: d+ C& O; q
  4. #define PWR_MainRegulator_UnderDrive_ON               PWR_CR_MRUDS
    0 \- W: `9 D7 A
  5. #define PWR_LowPowerRegulator_UnderDrive_ON           ((uint32_t)(PWR_CR_LPDS | PWR_CR_LPUDS))
    5 a" _' r, n3 i7 q
  6. & K( ^0 p$ h: |. a# p# y5 f7 j
  7. #define IS_PWR_REGULATOR_UNDERDRIVE(REGULATOR) (((REGULATOR) == PWR_MainRegulator_UnderDrive_ON) || \/ U6 D6 y- Q% J6 Y' q
  8.                                                 ((REGULATOR) == PWR_LowPowerRegulator_UnderDrive_ON))
复制代码

% n; B* z6 w- N3 \. OPWR_STOP_mode_entry3 n  t2 P- X6 k7 W

' w5 z" z: L6 ?) {% e$ C
  1. /** @defgroup PWR_STOP_mode_entry 8 v0 Z' l# {0 v2 k' e" c( @
  2.   * @{* D  H8 o0 R' p2 ]4 ^2 s
  3.   */+ X( i* K0 B6 C8 G: Z) A5 k
  4. #define PWR_STOPEntry_WFI               ((uint8_t)0x01)  t. h& Q) v& k7 `6 {! P  N
  5. #define PWR_STOPEntry_WFE               ((uint8_t)0x02)$ H; I& r: T  v
  6. #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE))
复制代码
1 E6 }1 i, p- S$ c; G
PWR_Regulator_Voltage_Scale( l3 @1 m+ b1 q+ F: Z, x
( h# g( C# U  f, x1 e' L
  1. /** @defgroup PWR_Regulator_Voltage_Scale
    ! k7 o- \% E$ f+ f# q
  2.   * @{
    3 E6 C8 ^' e; A  Z% I/ H! }. \; A1 u
  3.   */. k( _6 l  F% N; D8 o0 G, R- v1 {4 f) g
  4. #define PWR_Regulator_Voltage_Scale1    ((uint32_t)0x0000C000)& T$ t- y  y7 a" r
  5. #define PWR_Regulator_Voltage_Scale2    ((uint32_t)0x00008000); e4 H+ e1 j7 \1 E3 Y. q. g( J% J
  6. #define PWR_Regulator_Voltage_Scale3    ((uint32_t)0x00004000). @) c8 L9 D+ |, x0 f: O( L, E
  7. #define IS_PWR_REGULATOR_VOLTAGE(VOLTAGE) (((VOLTAGE) == PWR_Regulator_Voltage_Scale1) || \  Z9 h+ z1 e2 |. \& K* P8 Z+ N
  8.                                            ((VOLTAGE) == PWR_Regulator_Voltage_Scale2) || \
    6 i, O9 W) l% l
  9.                                            ((VOLTAGE) == PWR_Regulator_Voltage_Scale3))
复制代码
: r5 \2 K5 E& |: }
PWR_Flag

4 @7 q& M/ _; c9 a" n$ B% P! N8 o! r5 L3 n  u- Y
  1. /** @defgroup PWR_Flag ) j* }, u! H9 Y: B1 {6 K0 y$ X  u
  2.   * @{
    ' N2 W! ]+ W  o: v6 u. o
  3.   */
    ( a/ x* Q8 @: L. W
  4. #define PWR_FLAG_WU                     PWR_CSR_WUF
    ) M1 j2 g5 B  O, V
  5. #define PWR_FLAG_SB                     PWR_CSR_SBF
    - W, I. }0 ?$ k0 H' \  x
  6. #define PWR_FLAG_PVDO                   PWR_CSR_PVDO
    3 ]* L$ ^8 @2 c: c( E) t/ z
  7. #define PWR_FLAG_BRR                    PWR_CSR_BRR! M3 E( s6 y7 E' ^
  8. #define PWR_FLAG_VOSRDY                 PWR_CSR_VOSRDY
    7 a; z" [1 s0 I+ M6 ?6 A5 F
  9. #define PWR_FLAG_ODRDY                  PWR_CSR_ODRDY- V" L. r' M) L; S0 J
  10. #define PWR_FLAG_ODSWRDY                PWR_CSR_ODSWRDY
    , m( _5 i: o2 @; R
  11. #define PWR_FLAG_UDRDY                  PWR_CSR_UDSWRDY) C5 R9 [. H+ A
  12. + g) l. A- [. N2 L, _% Y. N( h# l. u* v; i
  13. /* --- FLAG Legacy ---*/" E9 t. q. g. G( \# g  ~
  14. #define PWR_FLAG_REGRDY                  PWR_FLAG_VOSRDY               
    3 m1 _2 i, [! J# t4 o" W
  15. " R( D7 u3 h5 h) d3 I7 K: [
  16. #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \
    3 }; d& A) r& N# t
  17.                                ((FLAG) == PWR_FLAG_PVDO) || ((FLAG) == PWR_FLAG_BRR) || \# q  c$ [6 p$ l! B4 b
  18.                                ((FLAG) == PWR_FLAG_VOSRDY) || ((FLAG) == PWR_FLAG_ODRDY) || \
    4 |7 G; R" Q# L* e1 P9 ?
  19.                                ((FLAG) == PWR_FLAG_ODSWRDY) || ((FLAG) == PWR_FLAG_UDRDY))1 f8 F1 u3 w" p# _$ y( r$ O

  20.   E8 {7 O' g- p

  21. 6 [# |( b* Y3 ]* [3 n- G/ t4 f8 B
  22. #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \: W1 W* Z) z5 Q0 {% W6 d$ G$ v; V$ i
  23.                                  ((FLAG) == PWR_FLAG_UDRDY))
复制代码

, @/ G2 F8 T0 W1 j03. 相关函数
/ l+ S, {! N" D! k+ O* y" ^
: j, L  G! n6 H, e; k1 U
  1. /* Function used to set the PWR configuration to the default reset state ******/
    : E5 {% e; [9 h- V. f0 e& {
  2. void PWR_DeInit(void);
    , @+ ]7 O8 p( Z, B( m
  3. 7 d: W. w2 `' u' W' F9 A
  4. /* Backup Domain Access function **********************************************/ $ P. R8 B' l7 p! K) H$ d
  5. void PWR_BackupAccessCmd(FunctionalState NewState);: v: U8 m0 S0 b9 ?  d, C
  6. * L2 H) h  j% N( |! |9 b  t" i, [) F
  7. /* PVD configuration functions ************************************************/
    ; U% y5 p- q' I
  8. void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel);
    # g. K5 X+ l3 ?6 J7 r: F
  9. void PWR_PVDCmd(FunctionalState NewState);$ E2 }! M+ Q5 p8 S; V" H0 J1 X+ a- }
  10. 9 c- A* A7 }7 |- l$ K
  11. void PWR_WakeUpPinCmd(FunctionalState NewState);& S, p4 ^; g; {% z6 b3 X$ y+ |# h: @
  12. " }# t  x" i4 a  p$ H9 M/ x. t
  13. /* Main and Backup Regulators configuration functions *************************/
    0 c' x+ r) e) O$ |% A
  14. void PWR_BackupRegulatorCmd(FunctionalState NewState);
    , ]+ y1 s0 d" K' ?- D+ f
  15. void PWR_MainRegulatorModeConfig(uint32_t PWR_Regulator_Voltage);, ~. f* A# Q9 n
  16. void PWR_OverDriveCmd(FunctionalState NewState);
    0 O/ z1 s1 N9 t6 v' \
  17. void PWR_OverDriveSWCmd(FunctionalState NewState);
    ' O2 d: }8 R' e! _" i- E
  18. void PWR_UnderDriveCmd(FunctionalState NewState);
    & x& b% E8 l" Q, e6 }( Q: h: R( D: R

  19. # t- U$ C1 H) [
  20. /* FLASH Power Down configuration functions ***********************************/ * I8 m2 v5 W9 b* w& U# p
  21. void PWR_FlashPowerDownCmd(FunctionalState NewState);) S3 u7 J: u& l

  22. 7 }; I$ o8 b: M) \) x+ J
  23. /* Low Power modes configuration functions ************************************/ ! R& v1 r2 O' u+ j
  24. void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry);# k2 F* u! F  }" n# x' A/ ~* ~
  25. void PWR_EnterUnderDriveSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry);
    " D0 q$ O0 x4 x- W& `; g
  26. void PWR_EnterSTANDBYMode(void);
    ' p5 h- Q6 O" N" g

  27. * ~1 h  m4 A/ m
  28. /* Flags management functions *************************************************/ " r3 x' g+ E9 p
  29. FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG);# @- H* h% L, q! z3 y/ M
  30. void PWR_ClearFlag(uint32_t PWR_FLAG);0 T. X2 J8 T0 {2 R- M# w1 s

  31.   X9 l. m/ K+ z% a3 z' ?
复制代码
+ i: E: l) C0 n! F: ~+ P7 Z; W' n
04. 结构体封装
( E8 t: D% ^7 ]  {5 j3 k9 ^( Y
  1. /** 4 p8 V" N( \, y$ s5 U9 ?2 A4 B
  2.   * @brief Power Control
    4 M# _! x# U$ r
  3.   */" g* e: W6 b' T# Y; m

  4. , I' P% y7 W/ z9 M* l( m
  5. typedef struct
    . T  e' \! C7 ~% _& V: k
  6. {
    # q2 m9 a. _  C7 I$ f
  7.   __IO uint32_t CR;   /*!< PWR power control register,        Address offset: 0x00 */: R, V: q. D0 |4 d7 s3 N! m1 y
  8.   __IO uint32_t CSR;  /*!< PWR power control/status register, Address offset: 0x04 */
    , J3 E0 y: E  h
  9. } PWR_TypeDef;
复制代码

3 `2 Q5 w# d+ z5 A
赞 收藏 评论0 发布时间:2022-3-30 11:00

举报

0个回答

所属标签

相似技术帖

官网相关资源

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