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

【经验分享】STM32 FreeRTOS FreeRTOSConfig.h文件解析

[复制链接]
STMCU小助手 发布时间:2022-5-23 21:00
前言
" X% Q  Q) P3 [, k- O- i- F8 D本篇文章带大家了解FreeRTOS里面的FreeRTOSConfig.h文件,此文基于正点原子FreeRTOS手册讲解。* t" }; \/ H+ \" J

, A0 ~- n# l5 k9 M# @一、文件讲解
* Y2 {7 n8 j: L源码:
7 @) M$ {# Z6 O% s7 _. I
- m8 I8 k3 C/ d0 U8 ?) ^
  1. /* USER CODE BEGIN Header */. K* K2 X; f2 ]2 D; Y9 p: U; B
  2. /*
    ! k2 |4 G* @# `8 n' ~% a; e
  3. * FreeRTOS Kernel V10.0.1
    , o& d* J% T) H! I6 l! z4 E/ r  x
  4. * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.1 B( T7 w; p( R1 \; K" g
  5. *
    : ]; i# Z- x! W! u4 O4 R4 p1 h$ N
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy of
    7 s+ v; O% V2 f3 ?9 _. a( L
  7. * this software and associated documentation files (the "Software"), to deal in
    5 T2 Z3 q6 h" t: y8 [. ~
  8. * the Software without restriction, including without limitation the rights to, I& c5 X9 e2 e/ N
  9. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
    4 I" G! t  K/ b! B& w1 R' _
  10. * the Software, and to permit persons to whom the Software is furnished to do so,8 a! j* q4 U3 i' x1 O1 Q, n
  11. * subject to the following conditions:
    . ~7 C$ L  c0 n8 h) G  P
  12. *
    " j5 B" E3 M* V5 z2 ]% x8 R- K( C
  13. * The above copyright notice and this permission notice shall be included in all7 i1 N; V0 {& O4 T
  14. * copies or substantial portions of the Software.6 T/ ^: o4 U7 U
  15. *
    1 S0 s& O4 l  M1 s6 L
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR$ d, I- v$ C# w. G" Z; a
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
    # o8 S* z" @. f; i) V( T
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR7 t0 g6 c0 h7 E: s1 `
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER- M! k& K1 R; Y# H$ }" V/ o
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    9 B( ~% c, `4 E& ^
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.! W" `0 U1 `6 |0 R: w  @
  22. *2 F: F: O9 ?1 o! ^) K2 U* f! D
  23.   p! i: [' s+ \4 K3 g
  24. *
    1 [1 O. t! Z& R
  25. * 1 tab == 4 spaces!. |1 B  `! z3 u2 H
  26. */
    0 x) r9 t- [$ K4 Q. `; F
  27. /* USER CODE END Header */
    ( ?& T6 c, ~: }& k
  28. 9 H+ m2 P  x% b6 g
  29. #ifndef FREERTOS_CONFIG_H
    5 F( Q" r. r6 Y
  30. #define FREERTOS_CONFIG_H( f5 c: o6 F7 {
  31. " e! U- a3 F, K  B% e) v5 c
  32. /*-----------------------------------------------------------, c" d# |# G% U& @
  33. * Application specific definitions.* y  V: s8 G- p/ C# V
  34. *. L. S' a1 r* l5 b
  35. * These definitions should be adjusted for your particular hardware and
    , Z/ O: C. {; T# M3 E2 u- N% l
  36. * application requirements.
    6 e) V' u' o/ x) G3 Z% F
  37. *
    % X# t2 F, v2 _
  38. * These parameters and more are described within the 'configuration' section of the
    6 s; T" }& P' {2 N$ }6 K
  39. * FreeRTOS API documentation available on the FreeRTOS.org web site.
    9 y+ s) k$ }0 G
  40. *& h' v- n& R$ t+ J' w
  41. , e. A2 `) d, g  q) c: v
  42. *----------------------------------------------------------*/5 _4 [) C* ^3 _$ u# C/ S% G; G

  43. # y1 e2 @6 |$ j. \1 O2 l0 ], b, T: u# u
  44. /* USER CODE BEGIN Includes */
      f8 q/ w$ J% v$ u, t
  45. /* Section where include file can be added */
    3 ~( D* q; V7 f4 a  R, h
  46. /* USER CODE END Includes */5 Q+ A* |9 M% B; c, ?5 b
  47. # W8 A' ~  l$ b
  48. /* Ensure definitions are only used by the compiler, and not by the assembler. */$ U- N% U8 v: a* j$ T
  49. #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__): G  U% y7 G2 B' L& W& {
  50.   #include <stdint.h>7 i$ u, D) d4 U. {& F2 Z) b
  51.   extern uint32_t SystemCoreClock;
    " w5 v! E( I7 f( b
  52. #endif; V8 r( N/ V1 ]% A) m2 q
  53. #define configUSE_PREEMPTION                     17 G8 H( i) s& T7 D9 l1 G6 x: L
  54. #define configSUPPORT_STATIC_ALLOCATION          1
    5 d7 V; @+ F$ L! j% k, s; ]
  55. #define configSUPPORT_DYNAMIC_ALLOCATION         13 e+ d7 d9 a4 T. l9 S
  56. #define configUSE_IDLE_HOOK                      0
    4 I0 Y. j) G. Q3 x. x
  57. #define configUSE_TICK_HOOK                      09 ^4 H4 z0 @$ Y$ ^( z9 y8 J* S& r
  58. #define configCPU_CLOCK_HZ                       ( SystemCoreClock )
    7 q5 R: D- w1 ~8 m
  59. #define configTICK_RATE_HZ                       ((TickType_t)1000)
    3 a. H+ _' q. V# T6 o+ e3 Q
  60. #define configMAX_PRIORITIES                     ( 7 )
    " P5 h* }7 D+ {2 J5 x! R# g$ k
  61. #define configMINIMAL_STACK_SIZE                 ((uint16_t)128): K9 J" @/ V- T# Z
  62. #define configTOTAL_HEAP_SIZE                    ((size_t)3072)! _+ d1 {& F' z2 u- f( R
  63. #define configMAX_TASK_NAME_LEN                  ( 16 )5 I6 a& r) K# g  c% g$ s( G
  64. #define configUSE_16_BIT_TICKS                   05 `& K# H+ H3 m
  65. #define configUSE_MUTEXES                        1
    / K! r+ U1 h- L/ ~, \  E
  66. #define configQUEUE_REGISTRY_SIZE                8* x: u" F& A) M& b: Y- f# n5 H$ }
  67. #define configUSE_PORT_OPTIMISED_TASK_SELECTION  14 ]- u2 S7 Q7 L+ o6 }: Y

  68. * C' E. b  d( @8 l  x$ s3 V/ f$ z
  69. /* Co-routine definitions. */
    7 N' {) U6 z( c% K6 {% n" |( z4 D  s
  70. #define configUSE_CO_ROUTINES                    0% P% X' x8 `+ i2 p' ]! K( ?9 I9 q2 }
  71. #define configMAX_CO_ROUTINE_PRIORITIES          ( 2 )
    ; i- ~% l7 g4 q( z9 `8 {' X% l; S: S
  72. + L; j8 _+ ?" X
  73. /* Set the following definitions to 1 to include the API function, or zero1 ]  K  H1 O& O0 S
  74. to exclude the API function. */
    ; X$ I- ^( b0 }- Q" |; Y
  75. #define INCLUDE_vTaskPrioritySet            1
    # Q- |$ v' A, V1 I/ D
  76. #define INCLUDE_uxTaskPriorityGet           1
    " f( q; b2 A. {( L' f- S; h! a6 Q
  77. #define INCLUDE_vTaskDelete                 1
    3 V+ i; `/ P6 z
  78. #define INCLUDE_vTaskCleanUpResources       0
    . [" I, w7 D' }9 c4 u7 G
  79. #define INCLUDE_vTaskSuspend                13 b  `* r& e+ g/ D7 Q# |' O( K
  80. #define INCLUDE_vTaskDelayUntil             0' J/ W% F  W# \; F0 Z2 M
  81. #define INCLUDE_vTaskDelay                  1
    7 d5 t6 V7 n; X7 r4 [; I; R: R
  82. #define INCLUDE_xTaskGetSchedulerState      1* T0 ], M. `2 B

  83. 5 m: \- l$ Z8 s( m) V; d% u

  84. 5 z( T. j) w" y3 {
  85. //Tickless; H8 {$ Q0 A* \) d8 o
  86. #define configUSE_TICKLESS_IDLE             1//启用tickless低功耗& ~, j  E; r! Q1 _8 j9 a
  87. #define configEXPECTED_IDLE_TIME_BEFORE_SLEEP       39 p7 i2 [7 N0 \+ ]6 W

  88. " C* i( d! m1 S: k
  89. /* Cortex-M specific definitions. */9 _) u, z9 h: g: Y6 P
  90. #ifdef __NVIC_PRIO_BITS4 ~0 f* z8 \! D9 d
  91. /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
    ) z  X+ |" P; Y7 ^0 X
  92. #define configPRIO_BITS         __NVIC_PRIO_BITS
    & q' z! P0 v2 n- ?
  93. #else
    ; o: u; D) @) K- t3 K( S
  94. #define configPRIO_BITS         4
    / W3 [2 d! e  N1 Q
  95. #endif2 ]- e1 u, W7 m1 R& n: p
  96. 5 Z3 t8 y& Q7 {: o: ^8 p
  97. /* The lowest interrupt priority that can be used in a call to a "set priority"
    1 F2 K& G/ b& c, O. N$ q# U
  98. function. */+ Q0 A: [# V# R) G- h2 p
  99. #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY   15
      K7 D7 e4 ]2 J1 p

  100. * Y$ c' k% k) E% P
  101. /* The highest interrupt priority that can be used by any interrupt service2 {" ?& ?& v' ?" C7 m3 T8 j# S
  102. routine that makes calls to interrupt safe FreeRTOS API functions.  DO NOT CALL
    - y( ^; b$ v+ d$ S: ~) U6 V
  103. INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
    . y: v3 m  j( W3 U1 z
  104. PRIORITY THAN THIS! (higher priorities are lower numeric values. */4 j) H, A  W* Z1 \  m
  105. #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 54 u) U8 f% ^7 c0 h+ _5 K
  106. $ N5 @; |. v+ |* h
  107. /* Interrupt priorities used by the kernel port layer itself.  These are generic' R5 R; i) ~5 _4 O
  108. to all Cortex-M ports, and do not rely on any particular library functions. */
    # L+ k5 b% E; M% G0 J6 {- R" I9 W
  109. #define configKERNEL_INTERRUPT_PRIORITY                 ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )* P) M  c) o" v7 V" ~
  110. /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
    - d& u- h/ o% G3 j; m
  111. See <a href="http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html." target="_blank">http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html.</a> */9 n) ?. l' B6 F. Z4 Y. v* t1 [
  112. #define configMAX_SYSCALL_INTERRUPT_PRIORITY         ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )" m9 y$ ~* L* d& L; v8 e; O

  113. 8 B% H/ p6 m! v" W; l6 }
  114. /* Normal assert() semantics without relying on the provision of an assert.h
    ' P- s% {  ?& `" F& z; V" I
  115. header file. */
    + l' ^+ P% c" A# J+ u0 R& g
  116. /* USER CODE BEGIN 1 */
    - f" F* f) N# E: }
  117. #define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}1 j# W0 w: i9 i- X! b
  118. /* USER CODE END 1 */2 t, S; x' k$ u0 @( V; _8 C

  119.   z" f7 M3 l+ e
  120. /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS& ?8 t4 [1 d* w- i
  121. standard names. */
    6 O( m; _- m( P( W2 ]
  122. #define vPortSVCHandler    SVC_Handler5 d# n; b0 V7 g, R5 U- M
  123. #define xPortPendSVHandler PendSV_Handler
    ( O- v, B7 A: ]( ]3 m  o) \

  124. 1 Y1 F7 D1 i* X
  125. /* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick,
    ' }, o3 N0 v. T: a( `4 O  {
  126.               to prevent overwriting SysTick_Handler defined within STM32Cube HAL */) L, [" U% t( N. L+ w, U) i1 \9 a
  127. 0 }" h% I4 q" X, |8 O1 a$ N
  128. #define xPortSysTickHandler SysTick_Handler0 |9 k* e5 a  j; b% W/ ~9 d) y

  129. 9 [! V6 E/ V! F+ ^
  130. /* USER CODE BEGIN Defines */; Z7 k" E: d" s( l6 x
  131. /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */- s; n0 Y& m5 j" U# t' k
  132. /* USER CODE END Defines */1 {3 U" L1 K. i; n4 z3 r- f$ G
  133. , ?% d, Q* Y; F2 y
  134. #endif /* FREERTOS_CONFIG_H */& _% B4 f% M9 c! N2 k, @! R
复制代码
/ g+ |- D+ G% m9 g+ U
FreeRTOS 的配置基本是通过在 FreeRTOSConfig.h 中使用“#define”这样的语句来定义宏定义实现的。- u# D1 d9 R# z/ E" k0 s& b
这些宏定义都有特殊的含义,我们就调其中一个讲解。
  1. #define configGENERATE_RUN_TIME_STATS                1- `! w$ ^" I1 T6 w; v# k# E5 `# x
复制代码

: a$ N; U& x: Z' M4 A$ A将此宏设置为1开启时间统计功能,相应的 API 函数会被编译,为 0 时关闭时间统计功能。9 l7 K5 f8 K+ F+ I" J* k$ G; c
其他的宏作用也和这个差不多,当设置为1时就可以使能某些函数,设置为0函数就不可用。
4 g' m# f/ ]$ h+ v其他宏大家可以自己看看,一般cubeMX生成代码后都会自动配置一些宏。
  r5 G. X6 |) D* m- v7 P  L) V8 Z! p2 [$ ?7 i
总结
% H" q, Q# T" t, |0 x3 OFreeRTOSConfig.h文件简单解析就到这里。; X* Q  \# g4 {7 Y# }- m: a8 [& X
% ?: l7 X& o: N, J/ W

4 v! U! Y% s! x; r* \1 Y9 p) F
赞 收藏 评论0 发布时间:2022-5-23 21:00

举报

0个回答

所属标签

相似技术帖

官网相关资源

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