CROSS_COMPILE ?= /opt/gcc-arm-none-eabi-7-2018-q2-update/bin/arm-none-eabi- TARGET_FILE ?= nrf.elf CC = $(CROSS_COMPILE)gcc CPP = $(CROSS_COMPILE)cpp OBJCOPY = $(CROSS_COMPILE)objcopy SRC_DIR = src OBJ_DIR = obj BIN_DIR = bin NRF_PATH := nrf5sdk/ INCLUDES += include/ INCLUDES += $(NRF_PATH)components/ INCLUDES += $(NRF_PATH)modules/nrfx/mdk/ INCLUDES += $(NRF_PATH)components/libraries/strerror/ INCLUDES += $(NRF_PATH)components/softdevice/s132/headers/nrf52/ INCLUDES += $(NRF_PATH)components/toolchain/cmsis/include/ INCLUDES += $(NRF_PATH)components/libraries/util/ INCLUDES += $(NRF_PATH)components/libraries/balloc/ INCLUDES += $(NRF_PATH)components/libraries/ringbuf/ INCLUDES += $(NRF_PATH)modules/nrfx/hal/ INCLUDES += $(NRF_PATH)components/libraries/bsp/ INCLUDES += $(NRF_PATH)components/libraries/log/ INCLUDES += $(NRF_PATH)modules/nrfx/ INCLUDES += $(NRF_PATH)components/libraries/experimental_section_vars/ INCLUDES += $(NRF_PATH)components/softdevice/s132/headers/ INCLUDES += $(NRF_PATH)components/libraries/delay/ INCLUDES += $(NRF_PATH)integration/nrfx/ INCLUDES += $(NRF_PATH)components/libraries/atomic/ INCLUDES += $(NRF_PATH)components/boards/ INCLUDES += $(NRF_PATH)components/libraries/memobj/ INCLUDES += $(NRF_PATH)components/softdevice/common/ INCLUDES += $(NRF_PATH)external/fprintf/ INCLUDES += $(NRF_PATH)components/libraries/log/src/ CPP_FLAGS += $(addprefix -I, $(INCLUDES)) C_SRCS = $(wildcard $(SRC_DIR)/*.c) C_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.o,$(C_SRCS))) NRF_C_SRCS += $(NRF_PATH)components/libraries/log/src/nrf_log_frontend.c NRF_C_SRCS += $(NRF_PATH)components/libraries/log/src/nrf_log_str_formatter.c NRF_C_SRCS += $(NRF_PATH)components/boards/boards.c NRF_C_SRCS += $(NRF_PATH)components/libraries/util/app_error.c NRF_C_SRCS += $(NRF_PATH)components/libraries/util/app_error_handler_gcc.c NRF_C_SRCS += $(NRF_PATH)components/libraries/util/app_error_weak.c NRF_C_SRCS += $(NRF_PATH)components/libraries/util/app_util_platform.c NRF_C_SRCS += $(NRF_PATH)components/libraries/util/nrf_assert.c NRF_C_SRCS += $(NRF_PATH)components/libraries/atomic/nrf_atomic.c NRF_C_SRCS += $(NRF_PATH)components/libraries/balloc/nrf_balloc.c NRF_C_SRCS += $(NRF_PATH)external/fprintf/nrf_fprintf.c NRF_C_SRCS += $(NRF_PATH)external/fprintf/nrf_fprintf_format.c NRF_C_SRCS += $(NRF_PATH)components/libraries/memobj/nrf_memobj.c NRF_C_SRCS += $(NRF_PATH)components/libraries/ringbuf/nrf_ringbuf.c NRF_C_SRCS += $(NRF_PATH)components/libraries/experimental_section_vars/nrf_section_iter.c NRF_C_SRCS += $(NRF_PATH)components/libraries/strerror/nrf_strerror.c NRF_C_SRCS += $(NRF_PATH)modules/nrfx/soc/nrfx_atomic.c NRF_C_SRCS += $(NRF_PATH)modules/nrfx/mdk/system_nrf52.c NRF_C_SRCS += $(NRF_PATH)components/softdevice/common/nrf_sdh.c NRF_C_SRCS += $(NRF_PATH)components/softdevice/common/nrf_sdh_soc.c NRF_C_OBJS = $(patsubst $(NRF_PATH)%,$(OBJ_DIR)/%,$(patsubst %.c,%.o,$(NRF_C_SRCS))) NRF_A_SRCS = $(NRF_PATH)modules/nrfx/mdk/gcc_startup_nrf52.S NRF_A_OBJS = $(patsubst $(NRF_PATH)%,$(OBJ_DIR)/%,$(patsubst %.S,%.o,$(NRF_A_SRCS))) OBJS = $(NRF_A_OBJS) $(NRF_C_OBJS) $(C_OBJS) TARGET = $(BIN_DIR)/$(TARGET_FILE) TARGET_HEX = $(patsubst %.elf,%.hex,$(TARGET)) TARGET_PACKAGE = $(patsubst %.hex,%.zip,$(TARGET_HEX)) THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST)) ################################################### OPT = 3 # C flags common to all targets C_FLAGS += -O$(OPT) -g$(OPT) C_FLAGS += -DBOARD_PCA10040 C_FLAGS += -DBSP_DEFINES_ONLY C_FLAGS += -DCONFIG_GPIO_AS_PINRESET C_FLAGS += -DFLOAT_ABI_HARD C_FLAGS += -DNRF52 C_FLAGS += -DNRF52832_XXAA C_FLAGS += -DNRF52_PAN_74 C_FLAGS += -DNRF_SD_BLE_API_VERSION=7 C_FLAGS += -DS132 C_FLAGS += -DSOFTDEVICE_PRESENT C_FLAGS += -mcpu=cortex-m4 C_FLAGS += -mthumb -mabi=aapcs C_FLAGS += -Wall -Werror C_FLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 # keep every function in a separate section, this allows linker to discard unused ones C_FLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing C_FLAGS += -fno-builtin -fshort-enums # Assembler flags common to all targets A_FLAGS += -g$(OPT) A_FLAGS += -mcpu=cortex-m4 A_FLAGS += -mthumb -mabi=aapcs A_FLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 A_FLAGS += -DBOARD_PCA10040 A_FLAGS += -DBSP_DEFINES_ONLY A_FLAGS += -DCONFIG_GPIO_AS_PINRESET A_FLAGS += -DFLOAT_ABI_HARD A_FLAGS += -DNRF52 A_FLAGS += -DNRF52832_XXAA A_FLAGS += -DNRF52_PAN_74 A_FLAGS += -DNRF_SD_BLE_API_VERSION=7 A_FLAGS += -DS132 A_FLAGS += -DSOFTDEVICE_PRESENT LINKER_SCRIPT = blinky_gcc_nrf52.ld # Linker flags LD_FLAGS += -O$(OPT) -g$(OPT) LD_FLAGS += -mthumb -mabi=aapcs -L$(NRF_PATH)modules/nrfx/mdk -T$(LINKER_SCRIPT) LD_FLAGS += -mcpu=cortex-m4 LD_FLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 # let linker dump unused sections LD_FLAGS += -Wl,--gc-sections # use newlib in nano version LD_FLAGS += --specs=nano.specs C_FLAGS += -D__HEAP_SIZE=8192 C_FLAGS += -D__HEAP_SIZE=8192 A_FLAGS += -D__HEAP_SIZE=8192 A_FLAGS += -D__HEAP_SIZE=8192 # Add standard libraries at the very end of the linker input, after all objects # that may need symbols provided by these libraries. LIBS += c nosys m ################################################### .PHONY: all install uninstall clean distclean debug package flash all: $(TARGET) debug: @echo $(TARGET_HEX) clean: rm -f $(TARGET) $(TARGET_HEX) $(TARGET_PACKAGE) rm -f $(OBJS) $(patsubst %.o,%.d,$(OBJS)) distclean: rm -rf $(OBJ_DIR) $(BIN_DIR) package: $(TARGET_HEX) $(THIS_MAKEFILE) nrfutil pkg generate --hw-version 52 --application-version 1 --application $(TARGET_HEX) --sd-req 0xCB --sd-id 0xCB --key-file keys/private.key $(TARGET_PACKAGE) flash: $(TARGET_HEX) $(THIS_MAKEFILE) @echo Flashing: $(TARGET_HEX) nrfjprog -f nrf52 --program $(TARGET_HEX) --sectorerase nrfjprog -f nrf52 --reset flash_softdevice: @echo Flashing: $(NRF_PATH)/components/softdevice/s132/hex/s132_nrf52_7.0.1_softdevice.hex nrfjprog -f nrf52 --program $(NRF_PATH)/components/softdevice/s132/hex/s132_nrf52_7.0.1_softdevice.hex --sectorerase nrfjprog -f nrf52 --reset erase: nrfjprog -f nrf52 --eraseall $(TARGET): $(OBJS) $(THIS_MAKEFILE) @mkdir -p $(BIN_DIR) $(CC) $(CC_FLAGS) $(LD_FLAGS) $(OBJS) $(addprefix -l,$(LIBS)) -o $@ $(TARGET_HEX): $(TARGET) $(THIS_MAKEFILE) $(OBJCOPY) -O ihex $(TARGET) $(TARGET_HEX) $(OBJ_DIR)/%.d: $(SRC_DIR)/%.c @mkdir -p $(OBJ_DIR)/ $(CPP) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(C_FLAGS) $(CPP_FLAGS) $(patsubst $(OBJ_DIR)/%.d,$(SRC_DIR)/%.c,$@) $(OBJ_DIR)/%.d: $(NRF_PATH)/%.S @mkdir -p $(OBJ_DIR)/ $(CPP) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(C_FLAGS) $(CPP_FLAGS) $(patsubst $(OBJ_DIR)/%.d,$(NRF_PATH)/%.S,$@) $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c @mkdir -p $(OBJ_DIR)/ $(CC) -c $(CPP_FLAGS) $(C_FLAGS) $< -o $@ $(OBJ_DIR)/%.o: $(NRF_PATH)/%.c @mkdir -p $(dir $@) $(CC) -std=c99 -MP -MD -c -o $@ $< $(C_FLAGS) $(CPP_FLAGS) $(OBJ_DIR)/%.o: $(NRF_PATH)/%.S @mkdir -p $(dir $@) $(CC) -c $(ASMFLAGS) $< -o $@ ifneq ($(MAKECMDGOALS),clean) -include $(patsubst %.o,%.d,$(OBJS)) endif