转载和补偿 keil5编译工程常见问题汇总

我们在编译keil工程的时候总是遇到很多问题,我把一些常见的问题和解决方案汇总下来,仅供大家参考。

问题汇总

问题1

问题描述

选择arm v6版本编译器,编译keil5工程,报错;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.A:

下载STM32cube_FW软件包,Drivers\CMSIS\Include目录下拷贝cmsis_armcc.h、core_cm3.h、cmsis_armclang.h这几个文件覆盖掉老的core_cm3.h文件,然后停用core_cm3.c,改用CMSIS标准接口(如下图所示);
12345

需要注意的是,CMSIS标准接口屏蔽了实现细节。

=======================================================================================

方案1.B

下载STM32cube_FW软件包,Drivers\CMSIS\Include目录下文件都拷过去,删除了core_cm3.h和core_cm3.c,重新编译。

方案1.c

注释掉naked

的四条语句

//uint32_t __get_PSP(void) attribute( ( naked ) );
//void __set_PSP(uint32_t topOfProcStack) attribute( ( naked ) );
//uint32_t __get_MSP(void) attribute( ( naked ) );
//void __set_MSP(uint32_t topOfMainStack) attribute( ( naked ) );
 

方案2:

降低编译器的版本,如下图:

123

方案3

 

问题2

问题描述

进行软件仿真,程序无法运行,卡在芯片系统初始化流程,如下图:

123

问题分析

软件仿真时,加载仿真所需的动态库失败。

解决方案

修改动态库,如下图所示:
2

指定动态库为DARMSTM.DLL,参数设置为你使用的芯片型号。

问题3

问题描述

移植了freertos内核,编译时报错,报错信息如下:

../freertos_code/include\FreeRTOS.h(65): warning: In file included from...
../freertos_code/include/portable.h(53): warning: In file included from...
../freertos_code/portable/RVDS/ARM_CM3\portmacro.h(176): error: unknown type name '__forceinline'
    static portFORCE_INLINE void vPortSetBASEPRI( uint32_t ulBASEPRI )
           ^
../freertos_code/portable/RVDS/ARM_CM3\portmacro.h(171): note: expanded from macro 'portFORCE_INLINE'
        #define portFORCE_INLINE    __forceinline
                                    ^
../freertos_code/portable/RVDS/ARM_CM3\portmacro.h(179): error: expected 'volatile', 'inline', 'goto', or '('
        {
        ^
../freertos_code/portable/RVDS/ARM_CM3\portmacro.h(189): error: unknown type name '__forceinline'
    static portFORCE_INLINE void vPortRaiseBASEPRI( void )
           ^
../freertos_code/portable/RVDS/ARM_CM3\portmacro.h(171): note: expanded from macro 'portFORCE_INLINE'
        #define portFORCE_INLINE    __forceinline
                                    ^
../freertos_code/portable/RVDS/ARM_CM3\portmacro.h(194): error: expected 'volatile', 'inline', 'goto', or '('
        {

问题分析

内联汇编语法不对造成错误。

解决方案

方案1:

按照如下格式修改内联汇编:

__asm volatile (
        "	ldr	r3, pxCurrentTCBConst2		\n"/* Restore the context. */
        "	ldr r1, [r3]					\n"/* Use pxCurrentTCBConst to get the pxCurrentTCB address. */
        "	ldr r0, [r1]					\n"/* The first item in pxCurrentTCB is the task top of stack. */
        "	ldmia r0!, {r4-r11}				\n"/* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */
        "	msr psp, r0						\n"/* Restore the task stack pointer. */
        "	isb								\n"
        "	mov r0, #0 						\n"
        "	msr	basepri, r0					\n"
        "	orr r14, #0xd					\n"
        "	bx r14							\n"
        "									\n"
        "	.align 4						\n"
        "pxCurrentTCBConst2: .word pxCurrentTCB				\n"
        );

方案2:

把freertos源文件中的RVDS文件夹里的ARM_CM3文件夹替换为GCC里的ARM_CM3文件夹。

总结

本篇文章汇总记录了使用stm32工程常见的问题和解决方案,后续有时间会继续更新。

 

标签:__,core,常见问题,freertos,CMSIS,编译,keil5,cm3,ARM
来源: https://www.cnblogs.com/lxyjrx/p/16244629.html

posted @ 2022-07-28 15:15  xiaoheikkkk  阅读(555)  评论(0编辑  收藏  举报