3

我正在编写一个 nrf51822 评估板(这个)。我一直在看这个网站来对其进行编程,并让闪烁的程序开始工作。

我想修改前面提到的网站上提供的makefile,这样当我继续进行时,我几乎只需要添加到要编译的文件列表中。以下是我一直在努力工作的内容,但我对 makefile 不太擅长。

CC            := /opt/arm-2012.09/bin/arm-none-eabi-gcc
OBJCOPY       := /opt/arm-2012.09/bin/arm-none-eabi-objcopy

NRF51_SDK     := /opt/nrf51sdk
NRF51_INCLUDE := $(NRF51_SDK)/Nordic/nrf51822/Include
NRF51_SRC     := $(NRF51_SDK)/Nordic/nrf51822/Source

CPU           := cortex-m0
BOARD         := BOARD_PCA10001

OBJDIR  = .
OBJDIR += $(SRC)/templates/

INCLUDEDIRS = $(NRF51_INCLUDE)
INCLUDEDIRS += $(NRF51_INCLUDE)/gcc

DEFINE  = BOARD_PCA10001
DEFINE += NRF51

CFLAGS  = -mcpu=$(CPU) 
CFLAGS +=-mthumb
CFLAGS += $(patsubst %,-D%, $(DEFINE))
CFLAGS += $(patsubst %,-I%, $(INCLUDEDIRS))
CFLAGS += -c

SRC  = main.c
SRC += $(NRF51_SRC)/templates/system_nrf51.c
SRC += $(NRF51_SRC)/nrf_delay/nrf_delay.c

ASSEMBLY_SRC += $(NRF51_SRC)/templates/gcc/gcc_startup_nrf51.s


all: main.bin main.hex

%.o : %.c 
@echo "Compiling: " $<
  $(CC) $(CFLAGS) $<

%.o : %.s 
  @echo "Compiling: " $<
  $(CC) $(CFLAGS) $<

main.out: $(SRC) $(ASSEMBLY_SRC)
  $(CC) -L"/opt/arm-2012.09/arm-none-eabi/lib/armv6-m" -L"/opt/arm-2012.09/lib/gcc/arm-none-eabi/4.7.2/armv6-m" -Xlinker -Map=main.map -mcpu=$(CPU) -mthumb -mabi=aapcs -T$(NRF51_SDK)/Nordic/nrf51822/Source/templates/gcc/gcc_linker_script_nrf51.ld main.o system_nrf51.o nrf_delay.o gcc_startup_nrf51.o -o main.out

main.bin: main.out
  $(OBJCOPY) -O binary main.out main.bin

main.hex: main.out
  $(OBJCOPY) -O ihex main.out main.hex

install: main.bin
  sed  's#\[\[--filename--\]\]#$(PWD)/main.bin#' segger/burn-template.seg > burn.seg
  ./segger/segger.sh $(PWD)/burn.seg

clean:
  rm *.o *.out *.hex *.seg *.map *.bin *.hex

当它运行时,它只输出以下内容:

/opt/arm-2012.09/bin/arm-none-eabi-gcc -L"/opt/arm-2012.09/arm-none-eabi/lib/armv6-m" -L"/opt/arm-2012.09/lib/gcc/arm-none-eabi/4.7.2/armv6-m" -Xlinker -Map=main.map -mcpu=cortex-m0 -mthumb -mabi=aapcs -T/opt/nrf51sdk/Nordic/nrf51822/Source/templates/gcc/gcc_linker_script_nrf51.ld main.o system_nrf51.o nrf_delay.o gcc_startup_nrf51.o -o main.out
arm-none-eabi-gcc: error: main.o: No such file or directory
arm-none-eabi-gcc: error: system_nrf51.o: No such file or directory 
arm-none-eabi-gcc: error: nrf_delay.o: No such file or directory
arm-none-eabi-gcc: error: gcc_startup_nrf51.o: No such file or directory
make: *** [main.out] Error 1

这里有没有人可以帮助我解决这个问题?

4

1 回答 1

1

(从 OP Edit 复制到解决方案的答案)

OP写道:

我只是想通了,如果有人想知道我是怎么做到的,我会分享它。另外,如果有人想评论如何使它“更好”

CC            := /opt/arm-2012.09/bin/arm-none-eabi-gcc
OBJCOPY       := /opt/arm-2012.09/bin/arm-none-eabi-objcopy

NRF51_SDK     := /opt/nrf51sdk
NRF51_INCLUDE := $(NRF51_SDK)/Nordic/nrf51822/Include
NRF51_SRC     := $(NRF51_SDK)/Nordic/nrf51822/Source

CPU           := cortex-m0
BOARD         := BOARD_PCA10001

INCLUDEDIRS = $(NRF51_INCLUDE)
INCLUDEDIRS += $(NRF51_INCLUDE)/gcc

DEFINE  = BOARD_PCA10001
DEFINE += NRF51

# For the compiler stage
CFLAGS  = -mcpu=$(CPU) 
CFLAGS += -mthumb
CFLAGS += $(patsubst %,-D%, $(DEFINE))
CFLAGS += $(patsubst %,-I%, $(INCLUDEDIRS))
CFLAGS += -Wall

# For the Linker stage
LDIRS  = /opt/arm-2012.09/arm-none-eabi/lib/armv6-m
LDIRS += /opt/arm-2012.09/lib/gcc/arm-none-eabi/4.7.2/armv6-m
TDIRS  = $(NRF51_SRC)/templates/gcc/gcc_linker_script_nrf51.ld

LFLAGS  = -mcpu=$(CPU)
LFLAGS += -mthumb
LFLAGS += -mabi=aapcs
LFLAGS += -Wall
LFLAGS += $(patsubst %, -L%, $(LDIRS))
LFLAGS += $(patsubst %, -T%, $(TDIRS))

# Source files to compile
SRC  = main.c
SRC += $(NRF51_SRC)/templates/system_nrf51.c
SRC += $(NRF51_SRC)/nrf_delay/nrf_delay.c

ASSEMBLY_SRC += $(NRF51_SRC)/templates/gcc/gcc_startup_nrf51.s

OBJ  = $(SRC:.c=.o) $(ASSEMBLY_SRC:.s=.o)

# Default target
all: begin gcc_version build end 

build: main.bin main.hex

main.out: $(OBJ)
  @echo 
  @echo "Linking compiled file. Output will be saved to: " $@
  $(CC) $(LFLAGS) $(notdir $(OBJ)) -o $@

main.bin: main.out
  @echo 
  @echo "Making binary file. Output will be saved to: " $@
  $(OBJCOPY) -O binary main.out main.bin

main.hex: main.out
  @echo 
  @echo "Making hex file. Output will be saved to: " $@
  $(OBJCOPY) -O ihex main.out main.hex

upload: all
  @echo 
  @echo "Uploading file to MCU: "
  sed  's#\[\[--filename--\]\]#$(PWD)/main.bin#' segger/burn-template.seg > burn.seg
  ./segger/segger.sh $(PWD)/burn.seg

clean:
  rm *.o *.out *.hex *.seg *.map *.bin *.hex

# Eye Candy
begin: 
  @echo
  @echo "---------- begin ----------"

end: 
  @echo
  @echo "----------- end -----------"

gcc_version: 
  @echo
  @$(CC) --version

# General Rule for compiling C source files
%.o : %.c
  @echo
  @echo "Compiling: " $(notdir $<)
  $(CC) $(CFLAGS) -c $< -o $(notdir $@)

# General Rule for compiling assembly source files
%.o : %.s
  @echo
  @echo "Compiling: " $(notdir $<)
  $(CC) $(CFLAGS) -c $< -o $(notdir $@)

这至少现在有效:)

于 2015-01-24T21:02:09.107 回答