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

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

[复制链接]
STMCU小助手 发布时间:2022-5-23 21:00
前言
/ A. I+ e5 m$ J3 k本篇文章带大家了解FreeRTOS里面的FreeRTOSConfig.h文件,此文基于正点原子FreeRTOS手册讲解。; ~8 v: G- z! H, K. s. {
7 |5 v- n& V, ~
一、文件讲解  n& E7 s' ?$ ^* H/ [3 Q
源码:
: Q  O0 |" Y; N  r& u  H7 V# B! X# ?& v/ j
  1. /* USER CODE BEGIN Header */
    : B" T7 w8 _2 b* V, n' E
  2. /*
    , b, ]" @  M) N) ^5 K
  3. * FreeRTOS Kernel V10.0.14 B( ^) Z" R6 [. g* S0 n* Z- E4 l
  4. * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.' U. [/ m/ b6 P5 F; H
  5. *
    ! e: Y: k1 b3 a8 N  ]. f8 i, Q
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy of2 P; t' F; Z& B- s: H3 y2 V
  7. * this software and associated documentation files (the "Software"), to deal in( |1 U4 h% u4 T' Y( B8 m( ?
  8. * the Software without restriction, including without limitation the rights to! U8 _' X0 Y3 J/ R
  9. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
      B9 q8 \# b8 g3 E# ~
  10. * the Software, and to permit persons to whom the Software is furnished to do so,/ [$ `- U0 R( g& k, f6 r
  11. * subject to the following conditions:6 D& N3 l2 H+ q/ `, W
  12. *+ w4 S$ E8 A& w) [0 L1 Z' B
  13. * The above copyright notice and this permission notice shall be included in all
    " U) O3 V! \( W$ j- N
  14. * copies or substantial portions of the Software.
    + e8 T& u- O* ~( X/ n5 g2 e
  15. *
    : @/ I) f' f: C4 ^
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR$ U8 c8 C9 V0 M- e  {3 E7 N
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS" {! }; ^" j% x* R9 D1 I* u0 |
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR# N. ^; i$ g& O9 i
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
    " I+ @6 S, l; p0 S0 _, ~# a
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN! K9 a* y- W% P' r
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.6 F" ~- J6 P( m2 {
  22. *) v$ }7 O. C2 A1 d/ w

  23. ! ?* p1 f! W# e* c1 m; a- O
  24. *
    ! P( z# s, l4 o
  25. * 1 tab == 4 spaces!5 Q) Q5 m0 k+ f5 T* L" Z) f
  26. */; `& |4 r) b- w  G* q
  27. /* USER CODE END Header */
    ( g: W" H! c; a/ k, T8 m
  28. 5 d% Z# a* Y4 {, c1 w5 @  p
  29. #ifndef FREERTOS_CONFIG_H
    + j6 ^: }0 m" i" ^; V8 N% }
  30. #define FREERTOS_CONFIG_H8 R8 G" l& l5 z3 c  P/ j3 ?
  31. 0 H5 Z- D# R+ o9 S4 k6 r: k7 [3 V
  32. /*-----------------------------------------------------------( L* k8 q* l: q+ h2 c4 v
  33. * Application specific definitions./ e, n# h2 E$ f& S
  34. *$ i- H" I+ B" E/ a  y
  35. * These definitions should be adjusted for your particular hardware and' v  i( E: [7 P: B' @
  36. * application requirements.
    6 H5 `' N# E9 A" A" S
  37. *( y& y/ C7 ~+ N
  38. * These parameters and more are described within the 'configuration' section of the; {0 M! H, U! h* d+ d  u& v, b
  39. * FreeRTOS API documentation available on the FreeRTOS.org web site.2 K+ h; d7 C; h! l% a' K
  40. *
    # p: J+ \# l6 v9 C

  41. 3 b; V: D* y. R6 F! q5 W4 B
  42. *----------------------------------------------------------*/
    : s% A( a% O; m- o8 \$ H
  43. 5 x; U$ D4 _! g) N9 R
  44. /* USER CODE BEGIN Includes */$ S: r' d* W3 {  f/ v
  45. /* Section where include file can be added */0 Z  b$ H( W. K2 Z9 U9 H4 h
  46. /* USER CODE END Includes */
    0 [2 h3 e( t$ F' q
  47. 6 z! d- M* m1 E; o" ~0 `# v1 ]8 o8 q
  48. /* Ensure definitions are only used by the compiler, and not by the assembler. */
    / d; k) Z$ [% |6 S* F: {  f2 M
  49. #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)6 @( c& F$ Q  J! {1 M) ?+ W
  50.   #include <stdint.h>9 j3 @! \/ e9 J
  51.   extern uint32_t SystemCoreClock;
    - U2 m) T! x" r. ]6 u2 h
  52. #endif1 {7 F- Z7 y1 Q) Q8 j
  53. #define configUSE_PREEMPTION                     1
      _& I( P) @* x0 ?
  54. #define configSUPPORT_STATIC_ALLOCATION          1% v/ P. K% p+ }! ?& ~
  55. #define configSUPPORT_DYNAMIC_ALLOCATION         16 Q9 q" `0 Q5 T# Z, G+ a* P
  56. #define configUSE_IDLE_HOOK                      0
    : S- ~& F% t1 G: m3 ^
  57. #define configUSE_TICK_HOOK                      0
    ! ]  G6 u+ u/ \: [  a/ Q; l
  58. #define configCPU_CLOCK_HZ                       ( SystemCoreClock )3 l* X! Q/ X) a9 l$ \9 l$ d
  59. #define configTICK_RATE_HZ                       ((TickType_t)1000)
    + O. B% E8 O& p3 Z
  60. #define configMAX_PRIORITIES                     ( 7 )
    5 r$ w) |+ [: Z+ T4 [) F$ |
  61. #define configMINIMAL_STACK_SIZE                 ((uint16_t)128)6 u& ~1 c7 ?, T4 [1 ~0 ^( M3 s
  62. #define configTOTAL_HEAP_SIZE                    ((size_t)3072)
    2 v! O$ K) g9 L0 b) }. ?6 `
  63. #define configMAX_TASK_NAME_LEN                  ( 16 )
    + l( g0 I) P! w, T
  64. #define configUSE_16_BIT_TICKS                   0
    ( h, K* G  H% y" c# ?( b5 l
  65. #define configUSE_MUTEXES                        1( _* R  }' N/ D+ s2 u6 |8 A; {
  66. #define configQUEUE_REGISTRY_SIZE                8
    3 e3 c8 \; x/ Y2 V% W. a
  67. #define configUSE_PORT_OPTIMISED_TASK_SELECTION  18 S! Z& V. d. g
  68. 6 i$ J% x+ u& x4 ]/ ^
  69. /* Co-routine definitions. */4 l3 M6 h+ _0 M; ?/ n" G/ a- Z
  70. #define configUSE_CO_ROUTINES                    0, D1 K( h7 r$ L. L/ D$ w" {3 F/ g3 o3 P$ v
  71. #define configMAX_CO_ROUTINE_PRIORITIES          ( 2 )% h% A. P: v7 z, G* W& n( z- ^
  72. ! j: }) H1 u6 F. @5 k/ G& T$ P; W7 H
  73. /* Set the following definitions to 1 to include the API function, or zero
    - f, O3 {0 G1 g; x" F/ J! {9 E
  74. to exclude the API function. */7 f4 Y2 s% O2 k2 \. ~9 i
  75. #define INCLUDE_vTaskPrioritySet            1; @1 S% A. L- ]# Q4 P
  76. #define INCLUDE_uxTaskPriorityGet           1
    9 w$ l2 J6 g( X3 i. \. t5 s7 B
  77. #define INCLUDE_vTaskDelete                 13 {, f2 ?$ B/ I/ @$ @2 ]9 d% q
  78. #define INCLUDE_vTaskCleanUpResources       0% J5 a$ a* {: [; l% Z7 o$ B- H
  79. #define INCLUDE_vTaskSuspend                1# P# ]# q8 r4 `; E% K2 L! M
  80. #define INCLUDE_vTaskDelayUntil             0
    6 K1 i; K! m- @" c& r. N
  81. #define INCLUDE_vTaskDelay                  1
    7 I# Q* \$ g0 _6 V9 o+ v. {4 J
  82. #define INCLUDE_xTaskGetSchedulerState      1: j2 @1 x! B  v- s9 I8 I8 N

  83. / P* B( x& h$ ?
  84. 3 W( [+ \" j  q1 q$ `2 a
  85. //Tickless5 _% r2 I  K* [/ m5 n0 K5 N- g
  86. #define configUSE_TICKLESS_IDLE             1//启用tickless低功耗' Y, y; t2 F# m3 D9 a& K
  87. #define configEXPECTED_IDLE_TIME_BEFORE_SLEEP       3- \1 j+ g* C/ I( _' {
  88. 0 B% v! E+ N0 Y! n; }2 @  W
  89. /* Cortex-M specific definitions. */
    2 ?, n. j6 P: _9 \7 ~" I5 W
  90. #ifdef __NVIC_PRIO_BITS) s# T) G" ^% o7 q* B7 O/ O
  91. /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
    + y; v8 Y0 z- L
  92. #define configPRIO_BITS         __NVIC_PRIO_BITS( z4 _* F& [) E' @) M' i! A- l
  93. #else
    / `, {$ ^5 O% h' T4 b+ O
  94. #define configPRIO_BITS         4
    * K$ G, y# Q' B9 M" @9 p
  95. #endif( f# v  I) p9 d  x9 D- Z5 `

  96. , g- j+ ~" z+ M: |: }: z  C  I
  97. /* The lowest interrupt priority that can be used in a call to a "set priority"; ?1 F/ M& u0 Z5 j8 A
  98. function. */
    ) B* p. m/ u# h& D
  99. #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY   155 A, R2 v/ v; I0 J- ^2 Z
  100. 7 r1 K4 X9 G6 t: |) z' ]
  101. /* The highest interrupt priority that can be used by any interrupt service
    7 R- F- y, A; {4 P+ C
  102. routine that makes calls to interrupt safe FreeRTOS API functions.  DO NOT CALL" |0 p/ ^' a& x8 ?: p! j* D
  103. INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER' D  l" a3 |: a1 Q: j; g' Q
  104. PRIORITY THAN THIS! (higher priorities are lower numeric values. */
    ' y( U: c5 e9 P3 Y8 [) q. r
  105. #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
    7 {! z& \+ {0 P# b  A/ u& j

  106. 3 f: B$ u7 d8 u- c  f' Y
  107. /* Interrupt priorities used by the kernel port layer itself.  These are generic- l# _" ?' t- J- ~( K
  108. to all Cortex-M ports, and do not rely on any particular library functions. */$ g% P. C$ Y4 d7 R6 n# y
  109. #define configKERNEL_INTERRUPT_PRIORITY                 ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )/ e! [; X# \. G" t. h) N# \
  110. /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
    0 P/ n2 J+ o5 d3 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> */
    ' R1 a# T9 i! {% G& x+ O0 f
  112. #define configMAX_SYSCALL_INTERRUPT_PRIORITY         ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )0 O9 [7 b1 F/ u) v- R3 J( ^3 K: C
  113. + j' \0 S# N. c
  114. /* Normal assert() semantics without relying on the provision of an assert.h! S. d9 m# D0 D5 z4 c
  115. header file. */" {( I" _# t  }! s5 t
  116. /* USER CODE BEGIN 1 */
    . R$ D1 @3 ]+ C, q4 ]0 i! ?  |
  117. #define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}3 K9 E% X5 j. x6 ^+ d$ G' G2 q
  118. /* USER CODE END 1 */# q6 e3 K, L' v( o5 Y- a( s6 C- ^

  119. ' a0 ^4 x1 b) J" ~+ U- @
  120. /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS9 L" [+ l1 `' ]/ N
  121. standard names. */
    " x7 h9 w$ w+ F1 Q( n( b: B
  122. #define vPortSVCHandler    SVC_Handler# F( k% l+ Q) C" U$ M
  123. #define xPortPendSVHandler PendSV_Handler; ?( G: Y8 F1 n0 n

  124. 7 f& Y5 v( a& `) b+ p. }/ S
  125. /* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick,( p& C$ q7 a- G0 S
  126.               to prevent overwriting SysTick_Handler defined within STM32Cube HAL */; b7 i! X( v! B) r& K- ]' T

  127. ' `" S$ {/ L! i) D, t% G
  128. #define xPortSysTickHandler SysTick_Handler9 A2 ]! F, a! H

  129. 9 L5 S$ }( H1 i( [- k6 U2 @% K9 o
  130. /* USER CODE BEGIN Defines */; j5 b/ [2 M( d$ G( w- z
  131. /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */9 m% S0 c6 v0 Z
  132. /* USER CODE END Defines */
    9 v  ~' [2 H. m; j1 A) Q) R1 |
  133. ( H5 e- m2 t3 K- _+ e
  134. #endif /* FREERTOS_CONFIG_H */
    8 @: O# J# i$ M$ ^
复制代码
5 f, ?8 |2 d/ Z/ K
FreeRTOS 的配置基本是通过在 FreeRTOSConfig.h 中使用“#define”这样的语句来定义宏定义实现的。
" v* q5 ?9 f2 V; Q4 M) k2 }这些宏定义都有特殊的含义,我们就调其中一个讲解。
  1. #define configGENERATE_RUN_TIME_STATS                1
    5 d" `) F# O( P  r* r. O5 e
复制代码

2 ]) s% \6 V' b3 Q7 m; g: e+ b将此宏设置为1开启时间统计功能,相应的 API 函数会被编译,为 0 时关闭时间统计功能。
) ~' @* {' k" y! Z其他的宏作用也和这个差不多,当设置为1时就可以使能某些函数,设置为0函数就不可用。6 C# J1 i$ h- ~. W+ M% a4 Y& |6 p. n
其他宏大家可以自己看看,一般cubeMX生成代码后都会自动配置一些宏。
, L5 D" c  |# N/ L8 Z& }; Z+ n) s/ J" W. u' n- }7 r$ j
总结, _' `5 _- b+ a$ y
FreeRTOSConfig.h文件简单解析就到这里。
! T# j' c% A4 b
4 ?0 S, u3 @6 d) Y! [8 O  @4 E% X  B( c. A5 L$ W2 J
赞 收藏 评论0 发布时间:2022-5-23 21:00

举报

0个回答

所属标签

相似技术帖

官网相关资源

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