我正在使用 Keil uVision v5.14 为 nrf51xx cpu 编译一些代码。我一直使用一个名为 nrf_delay.h 的头文件,它有一些用汇编程序编码的延迟例程。突然,在编译过程中,在所有“NOP”行上都收到上述错误:
#if defined ( __CC_ARM )
static __ASM void __INLINE nrf_delay_us(uint32_t volatile number_of_us)
{
loop
SUBS R0, R0, #1
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BNE loop
BX LR
}
#elif defined ( __ICCARM__ )
...
错误文本:
..\..\..\Include\nrf_delay.h(12): error: A1137E: Unexpected characters at end of line
..\..\..\Include\nrf_delay.h(13): error: A1137E: Unexpected characters at end of line
..\..\..\Include\nrf_delay.h(14): error: A1137E: Unexpected characters at end of line
..\..\..\Include\nrf_delay.h(15): error: A1137E: Unexpected characters at end of line
..\..\..\Include\nrf_delay.h(16): error: A1137E: Unexpected characters at end of line
..\..\..\Include\nrf_delay.h(17): error: A1137E: Unexpected characters at end of line
..\..\..\Include\nrf_delay.h(18): error: A1137E: Unexpected characters at end of line
..\..\..\Include\nrf_delay.h(19): error: A1137E: Unexpected characters at end of line
..\..\..\Include\nrf_delay.h(20): error: A1137E: Unexpected characters at end of line
..\..\..\Include\nrf_delay.h(21): error: A1137E: Unexpected characters at end of line
..\..\..\Include\nrf_delay.h(22): error: A1137E: Unexpected characters at end of line
..\..\..\Include\nrf_delay.h(23): error: A1137E: Unexpected characters at end of line
奇怪的是,NOP 之后绝对没有多余的字符。我也尝试过用旧版本替换 nrf_delay.h,或者更改项目设置以匹配工作设置,但没有运气。
整个东西都被包围在
#if defined ( __CC_ARM )
但我不确定是否定义了“_CC_ARM”或“ ICCARM ”。C 编译器是 Armcc V5.05。
更新
我是从一个工作项目开始的,我已经逐步添加了我上次疯狂的更改。似乎只是在项目的新 .c 文件中包含 nrf_delay.h 会触发问题。
但是,nrf_delay.h 包含在许多其他 .c 文件中,并且 nrf_delay_us() 被多次使用,没有这样的问题。
更新 2 - 已解决,但仍然是个谜 所以,我的 .c 文件顶部有一些#defines。如果我这样说:
#include <stdio.h>
#include <stdint.h>
#include "fw_update.h"
#include "registers.h"
#include "nrf51.h"
#include "boarddef.h"
#include "hal.h"
#include "nrf_delay.h" <-- this is giving the error
如果我这样说:
#include <stdio.h>
#include <stdint.h>
#include "nrf_delay.h" <-- this works!
#include "fw_update.h"
#include "registers.h"
#include "nrf51.h"
#include "boarddef.h"
#include "hal.h"
知道为什么吗?