昨日更新了keil5软件的版本,从5.17更新到了5.37版本,然后编译STM32项目文件时,软件提示编译报错。报错问题如下:
Build started: Project: QKsoftware
*** Using Compiler 'V6.18', folder: 'E:MDK-ARMARMARMARMCLANGBin'
Build target 'QKsoftware'
compiling stm32f4xx_it.c...
../User/sys/sys.c(93): error: expected '(' after 'asm'
__asm void WFI_SET(void)
^
../User/sys/sys.c(93): error: expected ';' after top-level asm block
__asm void WFI_SET(void)
^
;
../User/sys/sys.c(95): error: use of undeclared identifier 'WFI'
WFI;
^
../User/sys/sys.c(98): error: expected '(' after 'asm'
__asm void INTX_DISABLE(void)
^
../User/sys/sys.c(98): error: expected ';' after top-level asm block
__asm void INTX_DISABLE(void)
^
;
../User/sys/sys.c(100): error: use of undeclared identifier 'CPSID'
CPSID I
^
../User/sys/sys.c(104): error: expected '(' after 'asm'
__asm void INTX_ENABLE(void)
^
../User/sys/sys.c(104): error: expected ';' after top-level asm block
__asm void INTX_ENABLE(void)
^
;
../User/sys/sys.c(106): error: use of undeclared identifier 'CPSIE'
CPSIE I
^
../User/sys/sys.c(111): error: expected '(' after 'asm'
__asm void MSR_MSP(u32 addr)
^
../User/sys/sys.c(111): error: expected ';' after top-level asm block
__asm void MSR_MSP(u32 addr)
^
;
../User/sys/sys.c(113): error: use of undeclared identifier 'MSR'
MSR MSP, r0 //set Main Stack value
^
12 errors generated.
compiling sys.c...
compiling delay.c...
compiling usart.c...
compiling main.c...
compiling gpio.c...
compiling LED.c...
assembling startup_stm32f407xx.s...
compiling stm32f4xx_hal_msp.c...
compiling stm32f4xx_hal_tim.c...
compiling stm32f4xx_hal_tim_ex.c...
compiling stm32f4xx_hal_flash_ramfunc.c...
compiling stm32f4xx_hal_rcc_ex.c...
compiling stm32f4xx_hal_flash_ex.c...
compiling stm32f4xx_hal_flash.c...
compiling stm32f4xx_hal_rcc.c...
compiling stm32f4xx_hal_uart.c...
compiling stm32f4xx_hal_gpio.c...
compiling stm32f4xx_hal_pwr_ex.c...
compiling stm32f4xx_hal_pwr.c...
compiling stm32f4xx_hal_dma_ex.c...
compiling stm32f4xx_hal.c...
compiling stm32f4xx_hal_cortex.c...
compiling stm32f4xx_hal_dma.c...
compiling stm32f4xx_hal_exti.c...
compiling system_stm32f4xx.c...
"QKsoftwareQKsoftware.axf" - 12 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed: 00:00:12
编译器提示有问题的代码:
__asm void WFI_SET(void)
{
WFI;
}
__asm void INTX_DISABLE(void)
{
CPSID I
BX LR
}
__asm void INTX_ENABLE(void)
{
CPSIE I
BX LR
}
__asm void MSR_MSP(u32 addr)
{
MSR MSP, r0 //set Main Stack value
BX r14
}
令人感到奇怪的地方在于,升级之前,使用keil5.17版本时,是可以编译的,并且打开新文件以后,我也从没有修改过sys.c文件。前后改动的地方只有软件版本,因此猜想原因可能是升级了软件以后,编译器发生了改变,导致了编译出现问题。于是去检查魔法棒设置,查看target选项卡下的ARM compiler的版本,如下:
可以看到Code Generation一栏中,ARM 编译器的版本是版本6。而点开三角后,选项中并没有compiler v5这个选项,因此需要安装一个V5版本的编译器。前往
可以看到,编译器5支持_asm指令,而编译器6不支持_asm指令,而报错的代码看起来是新建了几个函数,函数类型前都加了_asm 这个词。因为编译器6不认识_asm这个词,因此才这里报错。
前往ARM开发者网站下载编译器,注意应下载5.05版本的编译器!
https://developer.arm.com/downloads
可以看到,编译器5支持_asm指令,而编译器6不支持_asm指令,而报错的代码看起来是新建了几个函数,函数类型前都加了_asm 这个词。因为编译器6不认识_asm这个词,因此才这里报错。
由于我不认识_asm个用法,特地查了一下,具体用法为:
_asm的用法
用法:__asm在函数定义上,放置在函数返回类型之前,然后说明函数体内部都是汇编代码。
因此该问题是由于ARMComplier6 的编译语法中__asm用法与ARMComplier5不一样所导致的。
参考此篇KEIL ARM 6.12 compiler 编译__ASM 错误的解决方法
两种办法:更换编译器,或者修改代码。
一、换编译器:
-
下载armV5版本的编译器
前往ARM开发者网站下载编译器,注意应下载5.05版本的编译器!
https://developer.arm.com/downloads* -
安装软件,注意将编译器安装到keil软件根目录下的ARM文件下,便于查找
-
配置编译器
二、修改代码
参考此篇KEIL ARM 6.12 compiler 编译__ASM 错误的解决方法
Rebuild started: Project: QKsoftware *** Using Compiler 'V5.05 (build 41)', folder: 'E:MDK-ARMARMARMARMCompiler5.05Bin' Rebuild target 'QKsoftware' assembling startup_stm32f407xx.s... compiling LED.c... compiling stm32f4xx_it.c... compiling sys.c... compiling delay.c... compiling gpio.c... compiling usart.c... compiling main.c... compiling stm32f4xx_hal_msp.c... compiling stm32f4xx_hal_tim.c... compiling stm32f4xx_hal_uart.c... compiling stm32f4xx_hal_tim_ex.c... compiling stm32f4xx_hal_rcc_ex.c... compiling stm32f4xx_hal_flash.c... compiling stm32f4xx_hal_flash_ramfunc.c... compiling stm32f4xx_hal_flash_ex.c... compiling stm32f4xx_hal_rcc.c... compiling stm32f4xx_hal_cortex.c... compiling stm32f4xx_hal_exti.c... compiling stm32f4xx_hal_gpio.c... compiling stm32f4xx_hal_pwr_ex.c... compiling stm32f4xx_hal_dma.c... compiling stm32f4xx_hal_dma_ex.c... compiling stm32f4xx_hal.c... compiling stm32f4xx_hal_pwr.c... compiling system_stm32f4xx.c... linking... Program Size: Code=5164 RO-data=448 RW-data=28 ZI-data=1092 FromELF: creating hex file... "QKsoftwareQKsoftware.axf" - 0 Error(s), 0 Warning(s). Build Time Elapsed: 00:00:22



