项目场景:
在我们学习STM32F10X(或者基于CM3内核的MCU)开发的时候,建立Keil工程的时候,第一步就是建立一个最基本的Project模板,只有最基本的模板编译通过后,后面的工程才有可能编译通过
问题描述
STM32F103X开发-01:工程模板建立-keil编译工程后,core_cm3.c出现4处报错;具体内容如下:
Build started: Project: stm32f10x_Project_Template
*** Using Compiler ‘V6.14’, folder: ‘E:\Keil\ARM\ARMCLANG\Bin’
Build target ‘Template’
CMSIS/core_cm3.c(445): error: non-ASM statement in naked function is not supported
uint32_t result=0;
^
CMSIS/core_cm3.c(442): note: attribute is here
uint32_t __get_PSP(void) attribute( ( naked ) );
^
CMSIS/core_cm3.c(465): error: parameter references not allowed in naked functions
“BX lr \n\t” : : “r” (topOfProcStack) );
^
CMSIS/core_cm3.c(461): note: attribute is here
void __set_PSP(uint32_t topOfProcStack) attribute( ( naked ) );
^
CMSIS/core_cm3.c(479): error: non-ASM statement in naked function is not supported
uint32_t result=0;
^
CMSIS/core_cm3.c(476): note: attribute is here
uint32_t __get_MSP(void) attribute( ( naked ) );
^
CMSIS/core_cm3.c(499): error: parameter references not allowed in naked functions
“BX lr \n\t” : : “r” (topOfMainStack) );
^
CMSIS/core_cm3.c(495): note: attribute is here
void __set_MSP(uint32_t topOfMainStack) attribute( ( naked ) );
^
4 errors generated.
compiling core_cm3.c…
“.\Objects\stm32f10x_Project_Template.axf” - 4 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed: 00:00:00
原因分析:
因为core_cm3.c和core_cm3.h文件太老导致的,这个文件还是2009年的版本,ST已经停止维护。
解决办法1:下载STM32cube_FW软件包,Drivers\CMSIS\Include目录下拷贝cmsis_armcc_V6.h、core_cm3.h、core_cmFunc.h、core_cmInstr.h这几个文件覆盖掉老的core_cm3.h文件,然后停用core_cm3.c,改用CMSIS标准接口。
方法如下图:
这是ARM的官方标准接口,坏处是CMSIS标准接口屏蔽了实现细节,但这是趋势。
解决方法2**,就是将编译版本调低