This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Unable to Compile nrf51 SDK example from directory other than SDK

I'm devloping application on nRf51 for that i'm using... SDK : nRF51_SDK_7.2.0_cf547b5 Tool chain : GNU tools arm Embedded [arm-none-eabi version 4.9.3] Dev Board : PCA10028(nRF51 DK)

I'm using following example. C:\nRF51_SDK_7.2.0_cf547b5\examples\peripheral\blinky When i compile this example using makefile at location C:\nRF51_SDK_7.2.0_cf547b5\examples\peripheral\blinky\pca10028\blank\armgcc it compiles well and also generate binary/hex.

I want to move this blinky example to D Drive. So now my example is at location D:\blinky. I'm compiling this example using makefile at location D:\blinky\pca10028\blank\armgcc I have Modified SDK PATH in makefile as per this

PROJECT_NAME := blinky_blank_pca10028

export OUTPUT_FILENAME
#MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
MAKEFILE_NAME := $(MAKEFILE_LIST)
MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) ) 

TOOLCHAIN_PATH = C:/nRF51_SDK_7.2.0_cf547b5
TEMPLATE_PATH = $(TOOLCHAIN_PATH)/components/toolchain/gcc
ifeq ($(OS),Windows_NT)
include $(TEMPLATE_PATH)/Makefile.windows
else
include $(TEMPLATE_PATH)/Makefile.posix
endif

MK := mkdir
RM := rm -rf

#echo suspend
ifeq ("$(VERBOSE)","1")
NO_ECHO := 
else
NO_ECHO := @
endif

# Toolchain commands
CC              := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc"
AS              := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-as"
AR              := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ar" -r
LD              := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld"
NM              := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-nm"
OBJDUMP         := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objdump"
OBJCOPY         := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objcopy"
SIZE            := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-size"

#function for removing duplicates in a list
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))

#source common to all targets
C_SOURCE_FILES += \
$(TOOLCHAIN_PATH)/components/toolchain/system_nrf51.c \
../../../Main.c \
$(TOOLCHAIN_PATH)/components/drivers_nrf/hal/nrf_delay.c \

#assembly files common to all targets
ASM_SOURCE_FILES  = $(TOOLCHAIN_PATH)/components/toolchain/gcc/gcc_startup_nrf51.s

#includes common to all targets
INC_PATHS  = -I../../../
INC_PATHS += -I$(TOOLCHAIN_PATH)/components/toolchain/gcc
INC_PATHS += -I$(TOOLCHAIN_PATH)/components/toolchain
INC_PATHS += -I$(TOOLCHAIN_PATH)/components/drivers_nrf/hal
INC_PATHS += -I$(TOOLCHAIN_PATH)/examples/peripheral/bsp
INC_PATHS += -I$(TOOLCHAIN_PATH)/examples/bsp

OBJECT_DIRECTORY = _build
LISTING_DIRECTORY = $(OBJECT_DIRECTORY)
OUTPUT_BINARY_DIRECTORY = $(OBJECT_DIRECTORY)

# Sorting removes duplicates
BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY) )

#flags common to all targets
CFLAGS  = -DNRF51
CFLAGS += -DBSP_DEFINES_ONLY
CFLAGS += -DBOARD_PCA10028
CFLAGS += -mcpu=cortex-m0
CFLAGS += -mthumb -mabi=aapcs --std=gnu99
CFLAGS += -Wall -Werror -O3
CFLAGS += -mfloat-abi=soft
# keep every function in separate section. This will allow linker to dump unused functions
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -flto -fno-builtin

# keep every function in separate section. This will allow linker to dump unused functions
LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_FILENAME).map
LDFLAGS += -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m0
# let linker to dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs -lc -lnosys

# Assembler flags
ASMFLAGS += -x assembler-with-cpp
ASMFLAGS += -DNRF51
ASMFLAGS += -DBSP_DEFINES_ONLY
ASMFLAGS += -DBOARD_PCA10028
#default target - first one defined
default: clean nrf51422_xxac

#building all targets
all: clean
    $(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e cleanobj
    $(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e nrf51422_xxac 

#target for printing all targets
help:
    @echo following targets are available:
    @echo   nrf51422_xxac


C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) )
C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILE_NAMES:.c=.o) )

ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCE_FILES))
ASM_PATHS = $(call remduplicates, $(dir $(ASM_SOURCE_FILES) ))
ASM_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(ASM_SOURCE_FILE_NAMES:.s=.o) )

vpath %.c $(C_PATHS)
vpath %.s $(ASM_PATHS)

OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)

nrf51422_xxac: OUTPUT_FILENAME := nrf51422_xxac
nrf51422_xxac: LINKER_SCRIPT=$(TOOLCHAIN_PATH)/components/toolchain/gcc/gcc_nrf51_blank_xxac.ld
nrf51422_xxac: $(BUILD_DIRECTORIES) $(OBJECTS)
    @echo Linking target: $(OUTPUT_FILENAME).out
    $(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
    $(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize

## Create build directories
$(BUILD_DIRECTORIES):
    @echo $(MAKEFILE_NAME)
    $(MK) $@

# Create objects from C SRC files
$(OBJECTS):
$(OBJECT_DIRECTORY)/%.o: %.c
    @echo Compiling file: $(notdir $<)
    $(NO_ECHO)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $<

# Assemble files
$(OBJECT_DIRECTORY)/%.o: %.s
    @echo Compiling file: $(notdir $<)
    $(NO_ECHO)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $<


# Link
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out: $(BUILD_DIRECTORIES) $(OBJECTS)
    @echo Linking target: $(OUTPUT_FILENAME).out
    $(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out


## Create binary .bin file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
    @echo Preparing: $(OUTPUT_FILENAME).bin
    $(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin

## Create binary .hex file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
    @echo Preparing: $(OUTPUT_FILENAME).hex
    $(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex

finalize: genbin genhex echosize

genbin:
    @echo Preparing: $(OUTPUT_FILENAME).bin
    $(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin

## Create binary .hex file from the .out file
genhex: 
    @echo Preparing: $(OUTPUT_FILENAME).hex
    $(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex

echosize:
    -@echo ""
    $(NO_ECHO)$(SIZE) $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
    -@echo ""

clean:
    $(RM) $(BUILD_DIRECTORIES)

cleanobj:
    $(RM) $(BUILD_DIRECTORIES)/*.o

flash: $(MAKECMDGOALS)
    @echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$<.hex
    nrfjprog --reset --program $(OUTPUT_BINARY_DIRECTORY)/$<.hex

When i'm compiling this using "make" in cmd.exe then i get

D:\blinky\pca10028\blank\armgcc>make
rm -rf _build
makefile
mkdir _build
Compiling file: Main.c
Linking target: nrf51422_xxac.out
arm-none-eabi-gcc.exe: error: _build/system_nrf51.o: No such file or directory
arm-none-eabi-gcc.exe: error: _build/nrf_delay.o: No such file or directory
arm-none-eabi-gcc.exe: error: _build/gcc_startup_nrf51.o: No such file or directory
make: *** [nrf51422_xxac] Error 1

Any solution on this? Thank you.

  • I don't see what's wrong with that. I just tried doing the same thing myself, on OSX because I don't have a windows box, but did the same thing, set up a tools directory etc.

    Clearly what's happened here is that you have the .o files properly listed but it's failed to rebuild them. I wonder if the paths given to vpath make sense and I wonder if the C: at the start messes it up.

    I added a target to mine to do this

    show:
        @echo C Objects: $(C_OBJECTS) 
        @echo C_PATHS: $(C_PATHS) 
        @echo ASM Objects: $(ASM_OBJECTS) 
        @echo ASM_PATHS: $(C_PATHS) 
    

    which at least shows what was passed-in, in my case I get

    Rols-MacBook-Pro-Retina:armgcc rols$ make show
    C Objects: _build/system_nrf51.o _build/main.o _build/nrf_delay.o
    C_PATHS: /Users/rols/Code/Nordic/nrf51/nRF51_SDK_8.1.0/components/toolchain/ ../../../ /Users/rols/Code/Nordic/nrf51/nRF51_SDK_8.1.0/components/drivers_nrf/hal/
    ASM Objects: _build/gcc_startup_nrf51.o
    ASM_PATHS: /Users/rols/Code/Nordic/nrf51/nRF51_SDK_8.1.0/components/toolchain/ ../../../ /Users/rols/Code/Nordic/nrf51/nRF51_SDK_8.1.0/components/drivers_nrf/hal/
    

    which all make sense, try something like that and see if your paths make sense too.

  • yes, i have tried it. all the paths are make sense. getting right paths at where files exists.

  • hmm - I have no ideas then - mine compiles with no problems. I haven't made exactly the same changes as you because as I said I'm on OSX, but they are very similar indeed so yours ought to work as well.

    What's a bit odd is I would have expected make to complain it had no rule to make those three .o files if they don't exist. It knows it needs them.

    I've tried editing the makefile and removing bits here and there to try and get the same error as you and I can't make it happen. I can get other errors to happen but not that one.

    oh one thing to try, just copy the original makefile again and start editing it from scratch. It's always possible you have one silly character in there which is messing it up. I think it only took me about 5 minutes to modify the makefile to use the fixed paths.

Related