• 在使用 Keil MDK 开发项目,编译时,报如下错误
*** Using Compiler 'V5.06 update 1 (build 61)', folder: 'D:\Keil_v5\ARM\ARMCC\Bin'
Build target 'redirect_printf'
compiling core_cm3.c...
start\core_cm3.c(58): error:  #667: "asm" function is nonstandard
  __ASM uint32_t __get_PSP(void)
start\core_cm3.c(72): error:  #667: "asm" function is nonstandard
  __ASM void __set_PSP(uint32_t topOfProcStack)
start\core_cm3.c(86): error:  #667: "asm" function is nonstandard
  __ASM uint32_t __get_MSP(void)
start\core_cm3.c(100): error:  #667: "asm" function is nonstandard
  __ASM void __set_MSP(uint32_t mainStackPointer)
start\core_cm3.c(114): error:  #667: "asm" function is nonstandard
  __ASM uint32_t __REV16(uint16_t value)
start\core_cm3.c(128): error:  #667: "asm" function is nonstandard
  __ASM int32_t __REVSH(int16_t value)
start\core_cm3.c: 0 warnings, 6 errors
".\Objects\redirect_printf.axf" - 6 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed:  00:00:00
问题原因
  • Keil MDK 的编译器在 Strict ANSI C 模式下会严格检查语法,而 CMSIS 中的 内联汇编函数不符合 ANSI C 标准,导致编译报错
处理策略
  • 在 Keil MDK 中 取消勾选 【Strict ANSI C】
  1. 点击 【Options for Target】
  1. 点击 【C/C++】 -> 取消勾选 【Strict ANSI C】
Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐