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

nrf52840 C and C++ Combined

Hi

Im struggling to use the ble_app_template_cpp within SDKv16. I am using the nrf52840 DK (PCA10056) and want to us the S140 SoftDevice. The example isn't built for either.

I've converted over the Makefile and can compile the code successfully but my code isn't running. When compiling I get the following error and I assume this is the reason my code won't run:

Compiling file: main.cpp
Linking target: nrf52840_xxaa.out
/Users/home/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: warning: cannot find entry symbol Reset_Handler; defaulting to 0000000000027000
Preparing: nrf52840_xxaa.bin
Preparing: nrf52840_xxaa.hex

My IDE is VSC with arm_ggc and the SDK is v16.

PROJECT_NAME := ble_app_template_pca10056_s140

SDK_ROOT := ../../../nRF5SDK160098a08e2
PRJ_ROOT := ../../..

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

TEMPLATE_PATH = $(SDK_ROOT)/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)$(GNU_PREFIX)-gcc'
CXX             := "$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-c++"
AS              := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-as'
AR              := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-ar' -r
LD              := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-ld'
NM              := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-nm'
OBJDUMP         := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-objdump'
OBJCOPY         := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-objcopy'
SIZE            := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-size'

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

#C files common to all targets
C_SOURCE_FILES += \
$(abspath $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_rtt.c) \
$(abspath $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c) \
$(abspath $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_uart.c) \
$(abspath $(SDK_ROOT)/components/libraries/log/src/nrf_log_default_backends.c) \
$(abspath $(SDK_ROOT)/components/libraries/log/src/nrf_log_frontend.c) \
$(abspath $(SDK_ROOT)/components/libraries/log/src/nrf_log_str_formatter.c) \
$(abspath $(SDK_ROOT)/components/libraries/button/app_button.c) \
$(abspath $(SDK_ROOT)/components/libraries/util/app_error.c) \
$(abspath $(SDK_ROOT)/components/libraries/util/app_error_handler_gcc.c) \
$(abspath $(SDK_ROOT)/components/libraries/util/app_error_weak.c) \
$(abspath $(SDK_ROOT)/components/libraries/scheduler/app_scheduler.c) \
$(abspath $(SDK_ROOT)/components/libraries/timer/app_timer2.c) \
$(abspath $(SDK_ROOT)/components/libraries/util/app_util_platform.c) \
$(abspath $(SDK_ROOT)/components/libraries/crc16/crc16.c) \
$(abspath $(SDK_ROOT)/components/libraries/timer/drv_rtc.c) \
$(abspath $(SDK_ROOT)/components/libraries/fds/fds.c) \
$(abspath $(SDK_ROOT)/components/libraries/hardfault/hardfault_implementation.c) \
$(abspath $(SDK_ROOT)/components/libraries/util/nrf_assert.c) \
$(abspath $(SDK_ROOT)/components/libraries/atomic_fifo/nrf_atfifo.c) \
$(abspath $(SDK_ROOT)/components/libraries/atomic_flags/nrf_atflags.c) \
$(abspath $(SDK_ROOT)/components/libraries/atomic/nrf_atomic.c) \
$(abspath $(SDK_ROOT)/components/libraries/balloc/nrf_balloc.c) \
$(abspath $(SDK_ROOT)/external/fprintf/nrf_fprintf.c) \
$(abspath $(SDK_ROOT)/external/fprintf/nrf_fprintf_format.c) \
$(abspath $(SDK_ROOT)/components/libraries/fstorage/nrf_fstorage.c) \
$(abspath $(SDK_ROOT)/components/libraries/fstorage/nrf_fstorage_sd.c) \
$(abspath $(SDK_ROOT)/components/libraries/memobj/nrf_memobj.c) \
$(abspath $(SDK_ROOT)/components/libraries/pwr_mgmt/nrf_pwr_mgmt.c) \
$(abspath $(SDK_ROOT)/components/libraries/ringbuf/nrf_ringbuf.c) \
$(abspath $(SDK_ROOT)/components/libraries/experimental_section_vars/nrf_section_iter.c) \
$(abspath $(SDK_ROOT)/components/libraries/sortlist/nrf_sortlist.c) \
$(abspath $(SDK_ROOT)/components/libraries/strerror/nrf_strerror.c) \
$(abspath $(SDK_ROOT)/components/libraries/sensorsim/sensorsim.c) \
$(abspath $(SDK_ROOT)/modules/nrfx/mdk/system_nrf52840.c) \
$(abspath $(SDK_ROOT)/components/boards/boards.c) \
$(abspath $(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_clock.c) \
$(abspath $(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_uart.c) \
$(abspath $(SDK_ROOT)/modules/nrfx/soc/nrfx_atomic.c) \
$(abspath $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_clock.c) \
$(abspath $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_gpiote.c) \
$(abspath $(SDK_ROOT)/modules/nrfx/drivers/src/prs/nrfx_prs.c) \
$(abspath $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uart.c) \
$(abspath $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uarte.c) \
$(abspath $(SDK_ROOT)/components/libraries/bsp/bsp.c) \
$(abspath $(SDK_ROOT)/components/libraries/bsp/bsp_btn_ble.c) \
$(abspath $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c) \
$(abspath $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_Syscalls_GCC.c) \
$(abspath $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c) \
$(abspath $(SDK_ROOT)/components/ble/peer_manager/auth_status_tracker.c) \
$(abspath $(SDK_ROOT)/components/ble/common/ble_advdata.c) \
$(abspath $(SDK_ROOT)/components/ble/ble_advertising/ble_advertising.c) \
$(abspath $(SDK_ROOT)/components/ble/common/ble_conn_params.c) \
$(abspath $(SDK_ROOT)/components/ble/common/ble_conn_state.c) \
$(abspath $(SDK_ROOT)/components/ble/common/ble_srv_common.c) \
$(abspath $(SDK_ROOT)/components/ble/peer_manager/gatt_cache_manager.c) \
$(abspath $(SDK_ROOT)/components/ble/peer_manager/gatts_cache_manager.c) \
$(abspath $(SDK_ROOT)/components/ble/peer_manager/id_manager.c) \
$(abspath $(SDK_ROOT)/components/ble/nrf_ble_gatt/nrf_ble_gatt.c) \
$(abspath $(SDK_ROOT)/components/ble/nrf_ble_qwr/nrf_ble_qwr.c) \
$(abspath $(SDK_ROOT)/components/ble/peer_manager/peer_data_storage.c) \
$(abspath $(SDK_ROOT)/components/ble/peer_manager/peer_database.c) \
$(abspath $(SDK_ROOT)/components/ble/peer_manager/peer_id.c) \
$(abspath $(SDK_ROOT)/components/ble/peer_manager/peer_manager.c) \
$(abspath $(SDK_ROOT)/components/ble/peer_manager/peer_manager_handler.c) \
$(abspath $(SDK_ROOT)/components/ble/peer_manager/pm_buffer.c) \
$(abspath $(SDK_ROOT)/components/ble/peer_manager/security_dispatcher.c) \
$(abspath $(SDK_ROOT)/components/ble/peer_manager/security_manager.c) \
$(abspath $(SDK_ROOT)/external/utf_converter/utf.c) \
$(abspath $(SDK_ROOT)/components/softdevice/common/nrf_sdh.c) \
$(abspath $(SDK_ROOT)/components/softdevice/common/nrf_sdh_ble.c) \
$(abspath $(SDK_ROOT)/components/softdevice/common/nrf_sdh_soc.c) \
$(abspath $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_nfct.c) \
$(abspath $(SDK_ROOT)/components/nfc/ndef/launchapp/nfc_launchapp_msg.c) \
$(abspath $(SDK_ROOT)/components/nfc/ndef/launchapp/nfc_launchapp_rec.c) \
$(abspath $(SDK_ROOT)/components/nfc/ndef/generic/message/nfc_ndef_msg.c) \
$(abspath $(SDK_ROOT)/components/nfc/ndef/generic/record/nfc_ndef_record.c) \
$(abspath $(SDK_ROOT)/components/nfc/ndef/uri/nfc_uri_msg.c) \
$(abspath $(SDK_ROOT)/components/nfc/ndef/uri/nfc_uri_rec.c) \
$(abspath $(SDK_ROOT)/components/nfc/platform/nfc_platform.c) \
$(abspath $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_timer.c) \
$(abspath $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_twi.c) \
$(abspath $(PRJ_ROOT)/srm_service.c) \
$(abspath $(PRJ_ROOT)/twi_layer.c) \

CPP_SOURCE_FILES += \
$(abspath $(PRJ_ROOT)/cpptest.cpp) \
$(abspath $(PRJ_ROOT)/max30105.cpp) \
$(abspath $(PRJ_ROOT)/bno080_lib.cpp) \
$(abspath $(PRJ_ROOT)/main.cpp) \

#assembly files common to all targets
ASM_SOURCE_FILES  = $(abspath$(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52840.S)

#includes common to all targets
INC_PATHS = -I$(abspath ../config)
INC_PATHS += -I$(abspath $(PRJ_ROOT)/)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/generic/message)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/t2t_lib)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/t4t_parser/hl_detection_procedure)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_ancs_c)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_ias_c)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/pwm)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/usbd/class/cdc/acm)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/usbd/class/hid/generic)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/usbd/class/msc)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/usbd/class/hid)
INC_PATHS += -I$(abspath $(SDK_ROOT)/modules/nrfx/hal)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/conn_hand_parser/le_oob_rec_parser)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/log)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_gls)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/fstorage)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/text)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/mutex)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/gpiote)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/bootloader/ble_dfu)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/connection_handover/common)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/boards)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/generic/record)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/t4t_parser/cc_file)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_advertising)
INC_PATHS += -I$(abspath $(SDK_ROOT)/external/utf_converter)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_bas_c)
INC_PATHS += -I$(abspath $(SDK_ROOT)/modules/nrfx/drivers/include)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/experimental_task_manager)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_hrs_c)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/softdevice/s140/headers/nrf52)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/connection_handover/le_oob_rec)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/queue)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/pwr_mgmt)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_dtm)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/toolchain/cmsis/include)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_rscs_c)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/common)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_lls)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/platform)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/bsp)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/connection_handover/ac_rec)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_bas)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/mpu)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/experimental_section_vars)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_ans_c)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/slip)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/delay)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/csense_drv)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/memobj)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_nus_c)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/softdevice/common)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_ias)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/usbd/class/hid/mouse)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/low_power_pwm)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/conn_hand_parser/ble_oob_advdata_parser)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_dfu)
INC_PATHS += -I$(abspath $(SDK_ROOT)/external/fprintf)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/svc)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/atomic)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/scheduler)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/cli)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_lbs)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_hts)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/crc16)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/t4t_parser/apdu)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/util)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/usbd/class/cdc)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/csense)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/balloc)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/ecc)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/hardfault)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_cscs)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/hci)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/timer)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/softdevice/s140/headers)
INC_PATHS += -I$(abspath $(SDK_ROOT)/integration/nrfx)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/t4t_parser/tlv)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/sortlist)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/spi_mngr)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/led_softblink)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/conn_hand_parser)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/sdcard)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/parser/record)
INC_PATHS += -I$(abspath $(SDK_ROOT)/modules/nrfx/mdk)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_cts_c)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_nus)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/twi_mngr)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_hids)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/strerror)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/crc32)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/connection_handover/ble_oob_advdata)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/t2t_parser)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/connection_handover/ble_pair_msg)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/usbd/class/audio)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/sensorsim)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/t4t_lib)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/peer_manager)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/mem_manager)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/ringbuf)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_tps)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/parser/message)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_dis)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/uri)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/nrf_ble_gatt)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/nrf_ble_qwr)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/gfx)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/button)
INC_PATHS += -I$(abspath $(SDK_ROOT)/modules/nrfx)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/twi_sensor)
INC_PATHS += -I$(abspath $(SDK_ROOT)/integration/nrfx/legacy)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/usbd/class/hid/kbd)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/connection_handover/ep_oob_rec)
INC_PATHS += -I$(abspath $(SDK_ROOT)/external/segger_rtt)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/atomic_fifo)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_lbs_c)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/connection_handover/ble_pair_lib)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/crypto)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_racp)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/fds)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/launchapp)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/atomic_flags)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_hrs)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/ble/ble_services/ble_rscs)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/connection_handover/hs_rec)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/usbd)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/nfc/ndef/conn_hand_parser/ac_rec_parser)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/stack_guard)
INC_PATHS += -I$(abspath $(SDK_ROOT)/components/libraries/log/src)

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) )

# Optimization flags
OPT = -O3 -g3
# Uncomment the line below to enable link time optimization
#OPT += -flto

# C flags to all targets
CFLAGS = $(OPT)
CFLAGS += -DNRF_LOG_USES_UART=1
CFLAGS += -DBOARD_PCA10056
CFLAGS += -DSOFTDEVICE_PRESENT
CFLAGS += -DNRF52840_XXAA
CFLAGS += -DS140
CFLAGS += -DBLE_STACK_SUPPORT_REQD
CFLAGS += -DNRF_SD_BLE_API_VERSION=7
CFLAGS += -DSWI_DISABLE0
CFLAGS += -DAPP_TIMER_V2
CFLAGS += -DAPP_TIMER_V2_RTC1_ENABLED
CFLAGS += -mcpu=cortex-m4
CFLAGS += -mthumb -mabi=aapcs
CFLAGS += -Wall -O3 -g3
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 += -fno-builtin --short-enums
#CFLAGS += -DCONFIG_GPIO_AS_PINRESET
#CFLAGS += -Wall -Werror

# CXX Flags

# 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-m4
# let linker to dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs -lc -lnosys

# Assembler flags
ASMFLAGS += $(OPT)
ASMFLAGS += -x assembler-with-cpp
ASMFLAGS += -DBOARD_PCA10056
ASMFLAGS += -DSOFTDEVICE_PRESENT
ASMFLAGS += -DNRF52840_XXAA
ASMFLAGS += -DS140
ASMFLAGS += -DBLE_STACK_SUPPORT_REQD
ASMFLAGS += -DAPP_TIMER_V2
ASMFLAGS += -DAPP_TIMER_V2_RTC1_ENABLED
ASMFLAGS += -DNRF52840_XXAA
ASMFLAGS += -DNRF_SD_BLE_API_VERSION=7
ASMFLAGS += -DSWI_DISABLE0
#ASMFLAGS += -DDEBUG

#default target - first one defined
default: clean nrf52840_xxaa

#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 nrf52840_xxaa

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

C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
CPP_SOURCE_FILE_NAMES = $(notdir $(CPP_SOURCE_FILES))
ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCE_FILES))

C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) )
CPP_PATHS = $(call remduplicates, $(dir $(CPP_SOURCE_FILES) ) )
ASM_PATHS = $(call remduplicates, $(dir $(ASM_SOURCE_FILES) ))

C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILE_NAMES:.c=.o) )
CPP_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(CPP_SOURCE_FILE_NAMES:.cpp=.o) )
ASM_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(ASM_SOURCE_FILE_NAMES:.s=.o) )	

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

OBJECTS = $(C_OBJECTS) $(CPP_OBJECTS) $(ASM_OBJECTS)

nrf52840_xxaa: OUTPUT_FILENAME := nrf52840_xxaa
nrf52840_xxaa: LINKER_SCRIPT=ble_app_template_gcc_nrf52.ld
nrf52840_xxaa: $(BUILD_DIRECTORIES) $(OBJECTS)
	@echo Linking target: $(OUTPUT_FILENAME).out

	$(NO_ECHO)$(CC) -std=gnu99 $(LDFLAGS) $(OBJECTS) $(LIBS) -lm -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
$(OBJECT_DIRECTORY)/%.o: %.c
	@echo Compiling file: $(notdir $<)
	$(NO_ECHO)$(CC) -std=gnu99 $(CFLAGS) $(INC_PATHS) -c -o $@ $<

# Create objects from Cpp SRC files
$(OBJECT_DIRECTORY)/%.o: %.cpp
	@echo Compiling file: $(notdir $<)
	$(NO_ECHO)$(CXX) $(CFLAGS) $(CXXFLAGS) $(INC_PATHS) -c -o $@ $<

# Assemble files
$(OBJECT_DIRECTORY)/%.o: %.s
	@echo Compiling file: $(notdir $<)
	$(NO_ECHO)$(CC) -std=c99 $(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 --program $(OUTPUT_BINARY_DIRECTORY)/$<.hex -f nrf52  --sectorerase
	nrfjprog --reset

## Flash softdevice
flash_softdevice:
	@echo Flashing: s140_nrf52_7.0.1_softdevice.hex
	nrfjprog --program $(SDK_ROOT)/components/softdevice/s140/hex/s140_nrf52_7.0.1_softdevice.hex -f nrf52 --chiperase
	nrfjprog --reset

Any ideas as I've been stuck on this for hours.

Related