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

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

[复制链接]
STMCU小助手 发布时间:2022-5-23 21:00
前言
! T; ?# T) |( N3 e$ b6 p# k4 `$ \本篇文章带大家了解FreeRTOS里面的FreeRTOSConfig.h文件,此文基于正点原子FreeRTOS手册讲解。; k% m- u& z! W. h0 r  e5 i$ N
0 H$ V0 B/ }$ O4 n9 D7 U. \! Q
一、文件讲解$ l' L$ L) c& T6 I& a
源码:
6 K6 @' ^: _( z# F6 f
3 C2 y% }3 x+ M5 u$ N
  1. /* USER CODE BEGIN Header */
    6 h0 j& {2 q  Q# A- s* @) N
  2. /*$ a0 m/ Z% R& u7 Z  m! g9 l
  3. * FreeRTOS Kernel V10.0.1
    " Y+ T9 _+ j& W8 Z* }* C3 i
  4. * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
    ' G* O. z- c5 z8 w
  5. *
    0 Q% U* A& A+ T$ N* J! X
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy of" G  _. @7 v  X! O; |1 X( x
  7. * this software and associated documentation files (the "Software"), to deal in$ s& n' D. I* {$ ]
  8. * the Software without restriction, including without limitation the rights to
    # v% M+ {) Q; O% X  q9 [' @# d, i
  9. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of1 g* K9 n) i6 ?% l" V5 k
  10. * the Software, and to permit persons to whom the Software is furnished to do so,
    5 K! U# w8 _* X/ B8 g
  11. * subject to the following conditions:
    5 d% g* N: k" O+ `7 N- N9 H, j
  12. *" M; U3 B2 `: o8 _1 {9 i
  13. * The above copyright notice and this permission notice shall be included in all1 T  N6 C% J# Y6 G  v
  14. * copies or substantial portions of the Software.8 T0 s. H4 ^5 ^( z7 m" P+ D8 j
  15. *
    ; p8 S7 C- a1 t) x% S+ |! a
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    " y5 ~% W) V/ c# s. H+ N
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS7 p8 w8 P% D/ \$ `7 s0 L
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR3 Z8 a, V. U- M) V+ x
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER  _& q- h, W+ a
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN6 ^& @" m  [$ b" H9 ~0 C
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    9 ~# i  h' U5 X) b3 V
  22. *
    1 g4 h% s  h/ m9 X  L# R1 @

  23. * U  b6 e$ F6 A
  24. *( I  V, ~0 s$ V3 J, M
  25. * 1 tab == 4 spaces!
    " \, H1 B: \! e# J  j
  26. */- v6 u! U, R! b: W  ^, Q
  27. /* USER CODE END Header */
    " \' Z( T# ]+ N$ q3 m2 W# F( A6 s
  28. 6 {  t! S8 U. N- k
  29. #ifndef FREERTOS_CONFIG_H
    ' P- A4 l$ ^5 Y* b
  30. #define FREERTOS_CONFIG_H" N5 G/ B2 [: K6 z+ K3 }
  31. ! k6 c$ Y# H& z2 x6 ?
  32. /*-----------------------------------------------------------; g( B# P! K( D5 x9 ~
  33. * Application specific definitions.
    7 Y9 }% `/ r0 Y1 ]8 Q6 X# W7 g
  34. *: B! q5 Q" B" m5 i! o+ d) d+ K7 A
  35. * These definitions should be adjusted for your particular hardware and
    $ A6 Y  K4 W4 z  u
  36. * application requirements.) O4 q) C$ z9 n% i; e9 O- T
  37. *- }0 \/ q5 c) m2 I  F* E( n8 t5 j
  38. * These parameters and more are described within the 'configuration' section of the
    ' X1 D8 y& @( _* @
  39. * FreeRTOS API documentation available on the FreeRTOS.org web site.( ~. F' Z: \& l8 s# C1 o# @
  40. *
    % X4 s- x. _6 U7 Y2 R

  41. 4 Z# [. Y% u& g0 b) `  o5 j1 }
  42. *----------------------------------------------------------*/. n- ^0 H5 a0 q8 e
  43. / K/ c# ^/ v3 ]$ B9 G- q- E
  44. /* USER CODE BEGIN Includes */( X6 K, J3 _3 H/ w( X( n1 v" a
  45. /* Section where include file can be added */2 q/ X$ u; f" ^3 D3 m, V
  46. /* USER CODE END Includes */+ X3 f% Z/ F( N0 G6 K; F

  47. # b- ^/ l4 H/ D' l. L, H4 J6 |0 Y
  48. /* Ensure definitions are only used by the compiler, and not by the assembler. */3 z; K) D# B* {8 ^
  49. #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
    # \: L$ q+ m: c  c& E/ A9 k
  50.   #include <stdint.h>  w8 P, D$ ?: {/ W
  51.   extern uint32_t SystemCoreClock;
    5 O" S" l0 s/ p
  52. #endif
    ) }. u& j6 y1 @, z0 k
  53. #define configUSE_PREEMPTION                     13 e* A4 p' H$ |2 D7 O$ o
  54. #define configSUPPORT_STATIC_ALLOCATION          1
    0 }% P6 Y1 _% X( ]; S: F0 m9 m8 @% B
  55. #define configSUPPORT_DYNAMIC_ALLOCATION         1  u; E8 j" v7 h; R2 \" r4 y# b
  56. #define configUSE_IDLE_HOOK                      0
    # C; E( U% Q9 A* f# k: G
  57. #define configUSE_TICK_HOOK                      0
    / A0 Q. y9 ], Z( C; X
  58. #define configCPU_CLOCK_HZ                       ( SystemCoreClock )9 J- o6 z& U1 Y" I
  59. #define configTICK_RATE_HZ                       ((TickType_t)1000)4 K+ {  E1 c: w9 o
  60. #define configMAX_PRIORITIES                     ( 7 )( N9 T3 t0 t1 Z6 n# d. P
  61. #define configMINIMAL_STACK_SIZE                 ((uint16_t)128)! |7 z# Z8 f3 l( h
  62. #define configTOTAL_HEAP_SIZE                    ((size_t)3072)/ X8 y7 i% F& P& U  ]" |9 Q  h
  63. #define configMAX_TASK_NAME_LEN                  ( 16 )
    ! C. Q" ^! o  n# n3 A5 H& d
  64. #define configUSE_16_BIT_TICKS                   0
    7 H$ \  _$ c; U- ]
  65. #define configUSE_MUTEXES                        1
    % ]% X! U# A4 S3 E9 W
  66. #define configQUEUE_REGISTRY_SIZE                8/ y5 b# N$ ^+ q' M! V: D1 N
  67. #define configUSE_PORT_OPTIMISED_TASK_SELECTION  1
    , v* D4 j& i: l0 _; Y
  68. ) t3 G' L0 l3 \( k$ Z( J
  69. /* Co-routine definitions. *// S, V. h/ [5 {8 m
  70. #define configUSE_CO_ROUTINES                    0# w& c" ?4 j" z  H% `  f
  71. #define configMAX_CO_ROUTINE_PRIORITIES          ( 2 )7 c( M) k  l! U$ u5 `" r) m

  72. 3 a& {' B- t9 H. q  o
  73. /* Set the following definitions to 1 to include the API function, or zero, `4 e* d$ U$ U3 ]
  74. to exclude the API function. */
    ) X& d3 y! p5 W' f4 o
  75. #define INCLUDE_vTaskPrioritySet            1
    . ~( [, _5 n0 ^, ?  k
  76. #define INCLUDE_uxTaskPriorityGet           1! E( f* r' ]: A" _. K, E( x+ f
  77. #define INCLUDE_vTaskDelete                 1* B; `6 z4 ]' ~/ f! W! S
  78. #define INCLUDE_vTaskCleanUpResources       03 W# F3 c  I  T* r; a1 @6 u
  79. #define INCLUDE_vTaskSuspend                1
    ) t, u8 e  X% W
  80. #define INCLUDE_vTaskDelayUntil             0
    0 ?& O5 O2 k, t9 M4 q
  81. #define INCLUDE_vTaskDelay                  1
    / x5 }. G8 |8 u; |2 e
  82. #define INCLUDE_xTaskGetSchedulerState      1
    3 g; S8 O9 M2 y$ k$ L
  83. # `; n+ f& ]; D4 Q
  84. 1 B1 y+ W' a% u) n: c
  85. //Tickless  o% }# D4 P; S; P3 v
  86. #define configUSE_TICKLESS_IDLE             1//启用tickless低功耗# x2 y. Z6 B, _  D3 J6 E/ G8 q, {3 V
  87. #define configEXPECTED_IDLE_TIME_BEFORE_SLEEP       3
    , c; m2 Z9 v" _( S2 a7 A/ G1 B
  88. 5 t  t6 Y+ p6 |0 f
  89. /* Cortex-M specific definitions. */
    , g: S' W" N. @& B: Q6 p
  90. #ifdef __NVIC_PRIO_BITS* M* `$ U" g" F  Z6 v7 D5 v+ O
  91. /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */! g- k% g, ^, ~6 k
  92. #define configPRIO_BITS         __NVIC_PRIO_BITS
    2 U! U0 y& F, \# ]6 B6 ~( X
  93. #else) g, z6 T; I0 E8 C( y
  94. #define configPRIO_BITS         4- _& Q) \  l" d
  95. #endif
    ( e7 c3 ~( n# J
  96. ; y* i1 X- i4 B( f. S+ C
  97. /* The lowest interrupt priority that can be used in a call to a "set priority"
      f% C  A% l1 _2 H2 E, H9 O* B
  98. function. */
    4 C9 [0 M) e2 s$ Y
  99. #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY   15
    * u3 L, s6 N& p1 j! {+ G. K. ~

  100. 9 _7 c/ R& u( u+ Q. b7 N
  101. /* The highest interrupt priority that can be used by any interrupt service
    9 x" ^: K5 U+ `- ^. p' J
  102. routine that makes calls to interrupt safe FreeRTOS API functions.  DO NOT CALL
    " C0 t3 J" {! h, v' m$ N* o
  103. INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER; {! `4 `, p2 V% a( ?, G% P6 G6 `
  104. PRIORITY THAN THIS! (higher priorities are lower numeric values. */
    ; R0 C& K, `! [8 w3 S9 `# v  Z5 G
  105. #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 56 j& V" @% i0 z# I& ~. n% w- T: s
  106. % [0 s" T9 U7 w! p! s# q3 q7 ?1 H
  107. /* Interrupt priorities used by the kernel port layer itself.  These are generic
    ( Q! D: b$ A* X' `# b2 C
  108. to all Cortex-M ports, and do not rely on any particular library functions. */! D! o6 l* }% [7 J4 t
  109. #define configKERNEL_INTERRUPT_PRIORITY                 ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
    & D0 Y) D) I9 p5 k$ ?" t
  110. /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
    3 p! f  H( A7 R; V: l
  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> */
    6 w6 P& A' v+ I$ M
  112. #define configMAX_SYSCALL_INTERRUPT_PRIORITY         ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )) R! |5 V% k. S* o

  113. $ G, d* F& p( r8 R" y
  114. /* Normal assert() semantics without relying on the provision of an assert.h7 P! M5 a& k2 ]7 g5 n3 `
  115. header file. */% t& _( m& z( Y! W5 x, ?
  116. /* USER CODE BEGIN 1 */
    6 W& P9 v& \  t( G, v+ Q  w
  117. #define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}1 }# j: [! }8 y; q2 Q
  118. /* USER CODE END 1 */* v7 ~# C3 {" I( ?; A( f6 X5 A. |% L

  119. , v+ F5 W) l. R  Q
  120. /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
    6 O* R' I- o, S5 w; @2 E% G/ T
  121. standard names. */3 ^* h4 l% x7 t/ N
  122. #define vPortSVCHandler    SVC_Handler
    . y. D( A, I6 u. ~. d6 G7 }
  123. #define xPortPendSVHandler PendSV_Handler
    3 t! g' B. N9 W) p- _
  124. 5 i4 c8 I) K- l3 O
  125. /* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick,
    $ b( Z) U& a4 `1 w9 N4 n+ t+ b
  126.               to prevent overwriting SysTick_Handler defined within STM32Cube HAL */
    3 z$ p' R  |# n7 x1 V

  127. 3 P9 q1 E% k5 d- n
  128. #define xPortSysTickHandler SysTick_Handler% e3 `6 D) ~6 X& s
  129. 7 ^6 O" L7 h( M* b4 \2 V/ u
  130. /* USER CODE BEGIN Defines */
    8 J6 W; v$ s$ T6 V1 C  f
  131. /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */: B# s% {5 R9 X" M5 ?5 \; z! B
  132. /* USER CODE END Defines */0 a- ]" z. `% q! Q) G# I

  133. 4 g- K8 C/ [9 U5 H2 |
  134. #endif /* FREERTOS_CONFIG_H */9 ?) q  ?8 l1 a8 r. f; T6 Z, j3 @; c5 T; I
复制代码
# b9 d# g* ^" J' h# _! [
FreeRTOS 的配置基本是通过在 FreeRTOSConfig.h 中使用“#define”这样的语句来定义宏定义实现的。& R8 \3 P" P, Q7 n4 t6 y! P* k
这些宏定义都有特殊的含义,我们就调其中一个讲解。
  1. #define configGENERATE_RUN_TIME_STATS                1
    8 T% ]) Y/ i. T+ O+ M, |
复制代码

" e+ W* J  q& o, m. Y3 s将此宏设置为1开启时间统计功能,相应的 API 函数会被编译,为 0 时关闭时间统计功能。
9 G5 L/ X1 Q; ?; H& {其他的宏作用也和这个差不多,当设置为1时就可以使能某些函数,设置为0函数就不可用。' M: o- s3 ?% @
其他宏大家可以自己看看,一般cubeMX生成代码后都会自动配置一些宏。
; B4 b& W  o: j$ y3 R. ?0 S
! C( K; f0 ^' Z( W总结
$ D5 p6 H. r6 Q2 ~FreeRTOSConfig.h文件简单解析就到这里。! L- m8 i  j  ^# \
( G3 y/ [/ j5 l# B
( w! A. K9 ^' S  j6 V
收藏 评论0 发布时间:2022-5-23 21:00

举报

0个回答

所属标签

相似技术帖

官网相关资源

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