ST意法半导体
直播中

世态薄凉

9年用户 1243经验值
私信 关注
[问答]

cubemx生成的freertos代码在keil ac6下不能编译,怎么解决?

../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(167): error: unknown type name '__forceinline'
167 | static portFORCE_INLINE void vPortSetBASEPRI( uint32_t ulBASEPRI )
|        ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(162): note: expanded from macro 'portFORCE_INLINE'
162 |         #define portFORCE_INLINE __forceinline
|                                  ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(170): error: expected 'volatile', 'inline', 'goto', or '('
170 |         {
|         ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(178): error: unknown type name '__forceinline'
178 | static portFORCE_INLINE void vPortRaiseBASEPRI( void )
|        ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(162): note: expanded from macro 'portFORCE_INLINE'
162 |         #define portFORCE_INLINE __forceinline
|                                  ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(183): error: expected 'volatile', 'inline', 'goto', or '('
183 |         {
|         ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(193): error: unknown type name '__forceinline'
193 | static portFORCE_INLINE void vPortClearBASEPRIFromISR( void )
|        ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(162): note: expanded from macro 'portFORCE_INLINE'
162 |         #define portFORCE_INLINE __forceinline
|                                  ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(196): error: expected 'volatile', 'inline', 'goto', or '('
196 |         {
|         ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(205): error: unknown type name '__forceinline'
205 | static portFORCE_INLINE uint32_t ulPortRaiseBASEPRI( void )
|        ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(162): note: expanded from macro 'portFORCE_INLINE'
162 |         #define portFORCE_INLINE __forceinline
|                                  ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(205): error: expected ';' after top level declarator
205 | static portFORCE_INLINE uint32_t ulPortRaiseBASEPRI( void )
|                                 ^
|                                 ;
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(223): error: unknown type name '__forceinline'
223 | static portFORCE_INLINE BaseType_t xPortIsInsideInterrupt( void )
|        ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(162): note: expanded from macro 'portFORCE_INLINE'
162 |         #define portFORCE_INLINE __forceinline
|                                  ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(223): error: expected ';' after top level declarator
223 | static portFORCE_INLINE BaseType_t xPortIsInsideInterrupt( void )
|                                   ^
|                                   ;
10 errors generated.
compiling freertos.c...
../Core/Src/main.c(21): warning: In file included from...
../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2cmsis_os.h(126): warning: In file included from...
../Middlewares/Third_Party/FreeRTOS/Source/includeFreeRTOS.h(62): warning: In file included from...
../Middlewares/Third_Party/FreeRTOS/Source/include/portable.h(52): warning: In file included from...
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(167): error: unknown type name '__forceinline'
167 | static portFORCE_INLINE void vPortSetBASEPRI( uint32_t ulBASEPRI )
|        ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(162): note: expanded from macro 'portFORCE_INLINE'
162 |         #define portFORCE_INLINE __forceinline
|                                  ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(170): error: expected 'volatile', 'inline', 'goto', or '('
170 |         {
|         ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(178): error: unknown type name '__forceinline'
178 | static portFORCE_INLINE void vPortRaiseBASEPRI( void )
|        ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(162): note: expanded from macro 'portFORCE_INLINE'
162 |         #define portFORCE_INLINE __forceinline
|                                  ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(183): error: expected 'volatile', 'inline', 'goto', or '('
183 |         {
|         ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(193): error: unknown type name '__forceinline'
193 | static portFORCE_INLINE void vPortClearBASEPRIFromISR( void )
|        ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(162): note: expanded from macro 'portFORCE_INLINE'
162 |         #define portFORCE_INLINE __forceinline
|                                  ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(196): error: expected 'volatile', 'inline', 'goto', or '('
196 |         {
|         ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(205): error: unknown type name '__forceinline'
205 | static portFORCE_INLINE uint32_t ulPortRaiseBASEPRI( void )
|        ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(162): note: expanded from macro 'portFORCE_INLINE'
162 |         #define portFORCE_INLINE __forceinline
|                                  ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(205): error: expected ';' after top level declarator
205 | static portFORCE_INLINE uint32_t ulPortRaiseBASEPRI( void )
|                                 ^
|                                 ;
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(223): error: unknown type name '__forceinline'
223 | static portFORCE_INLINE BaseType_t xPortIsInsideInterrupt( void )
|        ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(162): note: expanded from macro 'portFORCE_INLINE'
162 |         #define portFORCE_INLINE __forceinline
|                                  ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(223): error: expected ';' after top level declarator
223 | static portFORCE_INLINE BaseType_t xPortIsInsideInterrupt( void )
|                                   ^
|                                   ;
10 errors generated.
compiling main.c...
compiling STM32f1xx_hal.c...
compiling stm32f1xx_hal_dma.c...
compiling stm32f1xx_hal_rcc.c...
assembling startup_stm32f103xb.s...
compiling stm32f1xx_hal_gpio.c...
compiling stm32f1xx_hal_flash.c...
compiling system_stm32f1xx.c...
compiling stm32f1xx_hal_flash_ex.c...
compiling stm32f1xx_hal_exti.c...
compiling stm32f1xx_hal_pwr.c...
compiling stm32f1xx_hal_tim_ex.c...
../Middlewares/Third_Party/FreeRTOS/Source/croutine.c(28): warning: In file included from...
../Middlewares/Third_Party/FreeRTOS/Source/includeFreeRTOS.h(62): warning: In file included from...
../Middlewares/Third_Party/FreeRTOS/Source/include/portable.h(52): warning: In file included from...
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(167): error: unknown type name '__forceinline'
167 | static portFORCE_INLINE void vPortSetBASEPRI( uint32_t ulBASEPRI )
|        ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(162): note: expanded from macro 'portFORCE_INLINE'
162 |         #define portFORCE_INLINE __forceinline
|                                  ^
../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3portmacro.h(170): error: expected 'volatile', 'inline', 'goto', or '('
170 |         {
|         ^

回帖(1)

石玉兰

2025-3-13 18:25:10

这个错误是由于 Keil AC6 编译器不支持 __forceinline 这个关键字导致的。__forceinline 是 ARM Compiler 5 (AC5) 的关键字,但在 ARM Compiler 6 (AC6) 中,这个关键字被替换为 __attribute__((always_inline))


要解决这个问题,你可以按照以下步骤修改代码:




  1. 找到 portmacro.h 文件
    这个文件通常位于 Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3/ 目录下。




  2. 修改 portFORCE_INLINE 宏定义
    portmacro.h 文件中找到 portFORCE_INLINE 宏定义,并将其修改为适用于 AC6 的语法。


    修改前:


    #define portFORCE_INLINE __forceinline

    修改后:


    #define portFORCE_INLINE __attribute__((always_inline))



  3. 保存文件并重新编译
    保存修改后的文件,然后在 Keil 中重新编译项目。




其他可能的解决方案




  • 使用 AC5 编译器
    如果你不需要使用 AC6 的特性,可以考虑切换回 AC5 编译器。在 Keil 中,你可以通过项目设置将编译器从 AC6 切换回 AC5。




  • 更新 FreeRTOS 版本
    如果你使用的是较旧版本的 FreeRTOS,考虑更新到最新版本。新版本的 FreeRTOS 可能已经修复了与 AC6 的兼容性问题。




  • 检查其他文件
    如果问题不仅仅出现在 portmacro.h 文件中,你可能需要检查其他文件,确保所有 __forceinline 都被替换为 __attribute__((always_inline))




通过以上步骤,你应该能够解决 Keil AC6 下编译 FreeRTOS 代码时遇到的 __forceinline 错误。

举报

更多回帖

发帖
×
20
完善资料,
赚取积分