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

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

[复制链接]
STMCU小助手 发布时间:2022-5-23 21:00
前言# @" O$ g9 d- J! e- q6 E  ~! z4 h
本篇文章带大家了解FreeRTOS里面的FreeRTOSConfig.h文件,此文基于正点原子FreeRTOS手册讲解。; D9 v* N7 F* Z: v

( g( p! L% `2 {一、文件讲解
' K+ N7 j3 m* q; c/ e" B# i9 a  W源码:
: \) c) J# y1 A) E7 N0 T" r$ v6 H. Y& W4 r# D
  1. /* USER CODE BEGIN Header */
    ' U6 S1 j. B- @( K6 h4 o! q
  2. /*! K" P+ M1 p, J1 t: O7 u
  3. * FreeRTOS Kernel V10.0.1+ ?/ K% |; O* v: j- {  t& A' w
  4. * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
    ; W* L  Z, o$ N$ j& ~) `% p
  5. *3 R9 r+ L0 U( u  M
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy of
    2 i( O& b! t% T$ Z" m2 c
  7. * this software and associated documentation files (the "Software"), to deal in$ Z" v3 d- {2 F+ u6 |& Y2 _. L6 M
  8. * the Software without restriction, including without limitation the rights to* Q) B; n4 |) G& A
  9. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
    5 \/ @6 J4 ]# T' z
  10. * the Software, and to permit persons to whom the Software is furnished to do so,
    ' @9 w1 y  p  _6 z
  11. * subject to the following conditions:' L/ o4 g; f: ?7 @9 ~. ?) O
  12. *. ?. r8 m+ v- r* {' [
  13. * The above copyright notice and this permission notice shall be included in all
    , c  {9 z8 X) O1 R
  14. * copies or substantial portions of the Software.. y+ V$ F9 q: m
  15. *
    0 d6 \! m6 V0 _7 E( g/ d
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR9 h+ T, X' n9 U; I4 n: O4 k4 `" `. Q
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
    4 G  w% z# A7 P5 Q0 C3 _& I& [
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR0 ^2 }5 S6 g; L/ ?+ n5 I
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
    7 H' L: W, s  y% G; a5 k
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    ' P  x7 H/ _0 }% e
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.+ y0 T2 u2 [) q+ M# X- y
  22. *9 U! K. A, g- J1 i8 a& L5 ^5 W% G
  23. % R) z" }8 ?5 M; G' `5 j7 ]8 p
  24. *
    / S8 l+ g4 r7 b' J4 f5 T
  25. * 1 tab == 4 spaces!
    + Q% g* b* g0 u5 I5 o
  26. */  [* q% E* X0 E! U7 H8 f% o
  27. /* USER CODE END Header */; G3 p! B( a& z1 r' X

  28. 1 ]  b0 I/ C2 \$ k# s/ m' }/ h
  29. #ifndef FREERTOS_CONFIG_H
    4 U- w. V" x* E' m
  30. #define FREERTOS_CONFIG_H* m! v, B) G7 k
  31. ; _- E1 s& @) Y  X6 F
  32. /*-----------------------------------------------------------$ e( w, Y  J9 C
  33. * Application specific definitions.
    ; X% w* }6 n  `+ l; H  ^* c
  34. *
    % n3 K  \: C0 l5 S3 b, X4 L7 k, y
  35. * These definitions should be adjusted for your particular hardware and. c& ?3 x7 C* S
  36. * application requirements./ d( a( |9 X8 F
  37. *! y+ R9 r1 p4 f) p/ q4 B
  38. * These parameters and more are described within the 'configuration' section of the
    % o9 v3 j& _/ x( |# @: p1 l
  39. * FreeRTOS API documentation available on the FreeRTOS.org web site.( w  ~9 |5 `! A, `7 C. ~
  40. *
    ; h6 L; y, s! Z' e4 ]0 d+ l

  41. / O) Q# E' D, ^6 `
  42. *----------------------------------------------------------*/& n& J7 F0 F4 N; G0 `& Z7 g0 {
  43. ; x* m  p3 n" M
  44. /* USER CODE BEGIN Includes */
    ; @5 ?; S5 W! I
  45. /* Section where include file can be added */
    & h& M9 G. d5 d  B
  46. /* USER CODE END Includes */
    & o2 v; I, J9 E/ G6 y
  47. % A5 H$ u6 q5 k7 E" ^* d/ o5 R
  48. /* Ensure definitions are only used by the compiler, and not by the assembler. */
    3 [  f& K' U3 ^! a
  49. #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)8 {; `- M2 G8 g; k
  50.   #include <stdint.h>
    ' b* R8 ?# h& H1 ?& j( W) B
  51.   extern uint32_t SystemCoreClock;
    . ]" V6 y( l+ j4 o) J7 }
  52. #endif
    ; P( Y1 X3 E& o# s" @# [
  53. #define configUSE_PREEMPTION                     1
      P7 h/ J3 N2 E5 K1 u
  54. #define configSUPPORT_STATIC_ALLOCATION          16 u2 d; h8 U: S+ n# U4 T
  55. #define configSUPPORT_DYNAMIC_ALLOCATION         1
    # D( J: C0 \9 s
  56. #define configUSE_IDLE_HOOK                      06 L3 _. Z# u0 ~) L" `9 l
  57. #define configUSE_TICK_HOOK                      0
    2 T( A) M( h0 ~% B( `- m% M
  58. #define configCPU_CLOCK_HZ                       ( SystemCoreClock )
    , j+ R# Q1 V7 o* a7 f2 G: r
  59. #define configTICK_RATE_HZ                       ((TickType_t)1000)
    4 |+ P2 C" Q1 t9 Y' a0 O
  60. #define configMAX_PRIORITIES                     ( 7 )
    2 H1 B# \0 S5 ]- d4 W! q
  61. #define configMINIMAL_STACK_SIZE                 ((uint16_t)128)4 ?4 }: [6 x8 t: Z* D% C
  62. #define configTOTAL_HEAP_SIZE                    ((size_t)3072)
    0 j% v1 @0 |: F8 k9 @, C  Y6 C
  63. #define configMAX_TASK_NAME_LEN                  ( 16 )7 e5 C! ?- q9 }  B
  64. #define configUSE_16_BIT_TICKS                   0
      n3 p, e- ?+ j! [% }# w0 h
  65. #define configUSE_MUTEXES                        1
    / U, J# z! Z/ s  E
  66. #define configQUEUE_REGISTRY_SIZE                8) B' X  X0 R5 q) A
  67. #define configUSE_PORT_OPTIMISED_TASK_SELECTION  1
    ; ]/ x3 z. Y, _4 @3 M9 h
  68. ' L9 E8 O# M' o
  69. /* Co-routine definitions. */
    + a+ f6 d* u2 Z' f* t# ]' H) h: D
  70. #define configUSE_CO_ROUTINES                    0
    $ e% Z! R) ^( h
  71. #define configMAX_CO_ROUTINE_PRIORITIES          ( 2 )
    " z( E; U3 F+ Q: G6 l

  72. - A5 z- e$ O6 E8 R& ^( w
  73. /* Set the following definitions to 1 to include the API function, or zero, g; z* Y+ J6 l6 p7 w' q
  74. to exclude the API function. */
    - b) `2 b. a, P' x7 E, ~6 M& x
  75. #define INCLUDE_vTaskPrioritySet            1. z7 r, F. j& V+ @$ X9 Y3 W4 m0 Q
  76. #define INCLUDE_uxTaskPriorityGet           1
    , d; Q7 n2 q: o$ X
  77. #define INCLUDE_vTaskDelete                 1
    . n% w$ w* [" C& ?0 g  y. S$ e
  78. #define INCLUDE_vTaskCleanUpResources       0
    / T( z3 H( w( G' K  h. u
  79. #define INCLUDE_vTaskSuspend                1
    ( T1 E" K0 q/ D& {' Z" Q7 b
  80. #define INCLUDE_vTaskDelayUntil             0; V+ C: J. n( }2 w$ P* Q3 K
  81. #define INCLUDE_vTaskDelay                  1
    5 {1 s% ?+ U- X- }- c$ @
  82. #define INCLUDE_xTaskGetSchedulerState      1+ V/ k. L3 {% r4 n' Y
  83. , G9 C$ e2 o$ d1 o
  84. . ^9 _, K6 z8 G
  85. //Tickless
    * n5 e" Q% r, u& ]
  86. #define configUSE_TICKLESS_IDLE             1//启用tickless低功耗/ I1 J$ @$ Q: R5 P( f1 I' h" j: e9 C0 ~
  87. #define configEXPECTED_IDLE_TIME_BEFORE_SLEEP       35 _/ S. @! G6 L- t$ f* i
  88. : C7 F9 M9 w* b" F( B4 j
  89. /* Cortex-M specific definitions. */
    $ K( s6 L. [4 Z/ R
  90. #ifdef __NVIC_PRIO_BITS
    % w8 j6 Y4 g8 p: m6 [. ~
  91. /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */0 l2 }2 v2 _, B2 i$ n  T
  92. #define configPRIO_BITS         __NVIC_PRIO_BITS
    & g+ o! z2 G1 e+ b, R' c
  93. #else; p  L& _3 T6 }: J
  94. #define configPRIO_BITS         4
    % m; |+ D* q& Z% E
  95. #endif8 y. P' a; v, p, ^

  96. " p8 x& M! h/ I; v
  97. /* The lowest interrupt priority that can be used in a call to a "set priority"' p: I  @2 n+ b0 I0 J
  98. function. */
      b2 X  s- Y4 @9 D. r$ D
  99. #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY   15
    5 z) L. O5 G. v
  100. 7 K/ A  S! X. Q! M
  101. /* The highest interrupt priority that can be used by any interrupt service
    ) G  z4 B. e' j; y8 N0 {
  102. routine that makes calls to interrupt safe FreeRTOS API functions.  DO NOT CALL
    9 T: I8 w( ]7 _% y
  103. INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
    0 I8 }- _" y7 i) b) e' J  p
  104. PRIORITY THAN THIS! (higher priorities are lower numeric values. */+ b( \  U3 @0 y$ w1 s. h+ B5 O
  105. #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
    / Q7 N9 e- `. v# u+ E1 v: N0 E! R3 g

  106. 0 \3 b( w0 M  J4 `8 k& y6 R- O4 o7 b
  107. /* Interrupt priorities used by the kernel port layer itself.  These are generic* R) B4 u5 q4 R4 e9 Z. `1 l- T, F9 ?
  108. to all Cortex-M ports, and do not rely on any particular library functions. */
    5 P4 W4 K; o$ P: s
  109. #define configKERNEL_INTERRUPT_PRIORITY                 ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )% F6 q% l. n' Z# d5 _" I
  110. /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
    ( n# d8 p% W% G4 R" s# p2 Z1 _
  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> */% R2 Y! c. U2 r6 p
  112. #define configMAX_SYSCALL_INTERRUPT_PRIORITY         ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
    ' o) `' f4 q6 k( m" e6 D
  113. " M5 k. \. ^& `8 ?9 z" J' [
  114. /* Normal assert() semantics without relying on the provision of an assert.h+ T- g4 p/ V5 ]0 b1 W% `
  115. header file. */% U  ^! P0 D+ D2 B
  116. /* USER CODE BEGIN 1 */" ^5 N: Z2 l( D2 H& s
  117. #define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}
    / {. N# z# h. W$ d( y* U' z/ o% @
  118. /* USER CODE END 1 */1 `0 y4 R" t3 B! Q
  119. 0 ?0 k* i2 w* V! @+ \5 m2 A
  120. /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS4 ^: }" C6 y5 S% N" D; A
  121. standard names. */. C) Q+ K# Q5 P( M* d- \: L
  122. #define vPortSVCHandler    SVC_Handler
    6 E% _8 e: G* d
  123. #define xPortPendSVHandler PendSV_Handler0 a5 m* R, C. z  j: h+ X% i
  124. 2 t0 K7 B2 X  E# s' i2 Q" v- e8 w6 G$ }
  125. /* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick,2 c) b/ \0 K4 E. P$ q& e
  126.               to prevent overwriting SysTick_Handler defined within STM32Cube HAL */3 M+ V: b* s7 z- K4 R3 o

  127. 8 Y! E7 A5 J# s6 d" E% Y& }/ R$ X
  128. #define xPortSysTickHandler SysTick_Handler
    " c1 {; E) B, x- ]6 S4 Z
  129. * ]6 V. I; U% O( B" q
  130. /* USER CODE BEGIN Defines */
    9 u/ _1 \+ m9 i; P' `
  131. /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
    . m2 R, z. j, q/ ~- y/ h. g
  132. /* USER CODE END Defines */
      x+ B) l. `+ ]

  133. $ C% r5 `; T6 H
  134. #endif /* FREERTOS_CONFIG_H */
    $ j, _* [; k- i  I0 W
复制代码

3 i1 F+ B: q) C( I. M% B1 l; wFreeRTOS 的配置基本是通过在 FreeRTOSConfig.h 中使用“#define”这样的语句来定义宏定义实现的。: L1 N3 F6 ^0 P4 u7 E; e' U
这些宏定义都有特殊的含义,我们就调其中一个讲解。
  1. #define configGENERATE_RUN_TIME_STATS                1
    ' M" ]: t! X, k) r7 n' Z1 H3 e
复制代码

0 j+ S$ _1 i% n7 F$ T$ y将此宏设置为1开启时间统计功能,相应的 API 函数会被编译,为 0 时关闭时间统计功能。
4 r  h6 x) X3 l, L其他的宏作用也和这个差不多,当设置为1时就可以使能某些函数,设置为0函数就不可用。
  |5 m" Y6 @0 x5 W* N其他宏大家可以自己看看,一般cubeMX生成代码后都会自动配置一些宏。6 l) l$ F$ z4 k
( \: o6 h( j* X5 G. C' T+ |7 E
总结; X9 j) z4 u: [' H, I
FreeRTOSConfig.h文件简单解析就到这里。: g0 P4 X( ~( l" o
' C3 W& P7 b* K: D
) `) ]1 I  ^/ f# z: i& x0 Y
收藏 评论0 发布时间:2022-5-23 21:00

举报

0个回答

所属标签

相似分享

官网相关资源

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