From fb8c743d3b8516bdd9ff7c21f8fb752279f2cb29 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 12 Mar 2020 15:53:24 +0700 Subject: [PATCH 01/26] sort before uploading assets --- tools/upload_release_files.py | 41 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/tools/upload_release_files.py b/tools/upload_release_files.py index 35abd50..b7ee02c 100755 --- a/tools/upload_release_files.py +++ b/tools/upload_release_files.py @@ -4,32 +4,31 @@ import os import os.path import sys import uritemplate +import glob sys.path.append("adabot") import github_requests as github exit_status = 0 -for dirpath, dirnames, filenames in os.walk("../bin"): - if not filenames: - continue - for filename in filenames: - full_filename = os.path.join(dirpath, filename) - label = filename.replace("adafruit-circuitpython-", "") - url_vars = {} - url_vars["name"] = filename - url_vars["label"] = label - url = uritemplate.expand(os.environ["UPLOAD_URL"], url_vars) - headers = {"content-type": "application/octet-stream"} - print(url) - with open(full_filename, "rb") as f: - response = github.post(url, data=f, headers=headers) - if not response.ok: - if response.status_code == 422 and response.json().get("errors", [{"code":""}])[0]["code"] == "already_exists": - print("File already uploaded. Skipping.") - continue - print("Upload of {} failed with {}.".format(filename, response.status_code)) - print(response.text) - sys.exit(response.status_code) +filepaths = list(glob.iglob('../bin/*/*', recursive=True)) +filepaths.sort() + +for full_filename in filepaths: + filename = os.path.basename(full_filename) + url_vars = {} + url_vars["name"] = filename + url = uritemplate.expand(os.environ["UPLOAD_URL"], url_vars) + headers = {"content-type": "application/octet-stream"} + print(url) + with open(full_filename, "rb") as f: + response = github.post(url, data=f, headers=headers) + if not response.ok: + if response.status_code == 422 and response.json().get("errors", [{"code":""}])[0]["code"] == "already_exists": + print("File already uploaded. Skipping.") + continue + print("Upload of {} failed with {}.".format(filename, response.status_code)) + print(response.text) + sys.exit(response.status_code) sys.exit(exit_status) From bfa269c55f84e5710e6e09f56f769c5331f9f0ed Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 24 Mar 2020 16:04:21 +0700 Subject: [PATCH 02/26] makefile and build clean up --- Makefile | 149 +++++++++++++++++++++------------------------ tools/build_all.py | 24 ++++---- 2 files changed, 82 insertions(+), 91 deletions(-) diff --git a/Makefile b/Makefile index 9d52f73..7552462 100644 --- a/Makefile +++ b/Makefile @@ -33,54 +33,41 @@ OUTPUT_FILENAME = $(BOARD)_bootloader-$(GIT_VERSION) #****************************************************************************** # Tool configure #****************************************************************************** + +# Toolchain commands +# Should be added to your PATH +CROSS_COMPILE = arm-none-eabi- +CC := $(CROSS_COMPILE)gcc +AS := $(CROSS_COMPILE)as +AR := $(CROSS_COMPILE)ar -r +LD := $(CROSS_COMPILE)ld +NM := $(CROSS_COMPILE)nm +OBJDUMP := $(CROSS_COMPILE)objdump +OBJCOPY := $(CROSS_COMPILE)objcopy +SIZE := $(CROSS_COMPILE)size +GDB := $(CROSS_COMPILE)gdb + NRFUTIL = adafruit-nrfutil - -ifneq ($(JLINK),) -NRFJPROG = nrfjprog -s $(JLINK) -else NRFJPROG = nrfjprog -endif - -# auto-detect BMP on macOS, otherwise have to specify -BMP_PORT ?= $(shell ls -1 /dev/cu.usbmodem????????1 | head -1) - -ifeq ($(OS),Windows_NT) -PROGFILES = C:/Program Files (x86) -GNU_INSTALL_ROOT = $(PROGFILES)/GNU Tools ARM Embedded/7 2018-q2-update/bin/ -endif MK := mkdir RM := rm -rf # Verbose mode (V=). 0: default, 1: print out CFLAG, LDFLAG 2: print all compile command ifeq ("$(V)","2") -QUIET = + QUIET = else -QUIET = @ + QUIET = @ endif -GNU_PREFIX = arm-none-eabi - -# Toolchain commands -CC := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-gcc' -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' -GDB := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-gdb' - -GDB_BMP = arm-none-eabi-gdb -ex 'target extended-remote $(BMP_PORT)' -ex 'monitor swdp_scan' -ex 'attach 1' - -#function for removing duplicates in a list -remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1)))) +# auto-detect BMP on macOS, otherwise have to specify +BMP_PORT ?= $(shell ls -1 /dev/cu.usbmodem????????1 | head -1) +GDB_BMP = $(GDB) -ex 'target extended-remote $(BMP_PORT)' -ex 'monitor swdp_scan' -ex 'attach 1' #********************************* # Select the board to build #********************************* -BOARD_LIST = $(sort $(subst .h,,$(subst src/boards/,,$(wildcard src/boards/*)))) +BOARD_LIST = $(sort $(subst src/boards/,,$(wildcard src/boards/*))) ifeq ($(filter $(BOARD),$(BOARD_LIST)),) $(info You must provide a BOARD parameter with 'BOARD='. Supported boards are:) @@ -116,49 +103,49 @@ endif #****************************************************************************** # src -C_SOURCE_FILES += $(SRC_PATH)/main.c -C_SOURCE_FILES += $(SRC_PATH)/boards.c -C_SOURCE_FILES += $(SRC_PATH)/flash_nrf5x.c -C_SOURCE_FILES += $(SRC_PATH)/dfu_ble_svc.c -C_SOURCE_FILES += $(SRC_PATH)/dfu_init.c +C_SRC += $(SRC_PATH)/boards.c +C_SRC += $(SRC_PATH)/dfu_ble_svc.c +C_SRC += $(SRC_PATH)/dfu_init.c +C_SRC += $(SRC_PATH)/flash_nrf5x.c +C_SRC += $(SRC_PATH)/main.c # all sources files in specific board -C_SOURCE_FILES += $(wildcard $(SRC_PATH)/boards/$(BOARD)/*.c) +C_SRC += $(wildcard $(SRC_PATH)/boards/$(BOARD)/*.c) # nrfx -C_SOURCE_FILES += $(NRFX_PATH)/drivers/src/nrfx_power.c -C_SOURCE_FILES += $(NRFX_PATH)/drivers/src/nrfx_nvmc.c -C_SOURCE_FILES += $(NRFX_PATH)/mdk/system_$(MCU_SUB_VARIANT).c +C_SRC += $(NRFX_PATH)/drivers/src/nrfx_power.c +C_SRC += $(NRFX_PATH)/drivers/src/nrfx_nvmc.c +C_SRC += $(NRFX_PATH)/mdk/system_$(MCU_SUB_VARIANT).c # SDK 11 files -C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader.c -C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_settings.c -C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_util.c -C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_transport_serial.c -C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_transport_ble.c -C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_single_bank.c +C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader.c +C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_settings.c +C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_util.c +C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_transport_serial.c +C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_transport_ble.c +C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_single_bank.c -C_SOURCE_FILES += $(SDK11_PATH)/drivers_nrf/pstorage/pstorage_raw.c +C_SRC += $(SDK11_PATH)/drivers_nrf/pstorage/pstorage_raw.c -C_SOURCE_FILES += $(SDK11_PATH)/ble/ble_services/ble_dfu/ble_dfu.c -C_SOURCE_FILES += $(SDK11_PATH)/ble/ble_services/ble_dis/ble_dis.c +C_SRC += $(SDK11_PATH)/ble/ble_services/ble_dfu/ble_dfu.c +C_SRC += $(SDK11_PATH)/ble/ble_services/ble_dis/ble_dis.c # Latest SDK files -C_SOURCE_FILES += $(SDK_PATH)/libraries/timer/app_timer.c -C_SOURCE_FILES += $(SDK_PATH)/libraries/scheduler/app_scheduler.c -C_SOURCE_FILES += $(SDK_PATH)/libraries/util/app_error.c -C_SOURCE_FILES += $(SDK_PATH)/libraries/util/app_util_platform.c -C_SOURCE_FILES += $(SDK_PATH)/libraries/crc16/crc16.c -C_SOURCE_FILES += $(SDK_PATH)/libraries/hci/hci_mem_pool.c -C_SOURCE_FILES += $(SDK_PATH)/libraries/hci/hci_slip.c -C_SOURCE_FILES += $(SDK_PATH)/libraries/hci/hci_transport.c -C_SOURCE_FILES += $(SDK_PATH)/libraries/util/nrf_assert.c +C_SRC += $(SDK_PATH)/libraries/timer/app_timer.c +C_SRC += $(SDK_PATH)/libraries/scheduler/app_scheduler.c +C_SRC += $(SDK_PATH)/libraries/util/app_error.c +C_SRC += $(SDK_PATH)/libraries/util/app_util_platform.c +C_SRC += $(SDK_PATH)/libraries/crc16/crc16.c +C_SRC += $(SDK_PATH)/libraries/hci/hci_mem_pool.c +C_SRC += $(SDK_PATH)/libraries/hci/hci_slip.c +C_SRC += $(SDK_PATH)/libraries/hci/hci_transport.c +C_SRC += $(SDK_PATH)/libraries/util/nrf_assert.c # UART or USB Serial ifeq ($(MCU_SUB_VARIANT),nrf52) -C_SOURCE_FILES += $(SDK_PATH)/libraries/uart/app_uart.c -C_SOURCE_FILES += $(SDK_PATH)/drivers_nrf/uart/nrf_drv_uart.c -C_SOURCE_FILES += $(SDK_PATH)/drivers_nrf/common/nrf_drv_common.c +C_SRC += $(SDK_PATH)/libraries/uart/app_uart.c +C_SRC += $(SDK_PATH)/drivers_nrf/uart/nrf_drv_uart.c +C_SRC += $(SDK_PATH)/drivers_nrf/common/nrf_drv_common.c IPATH += $(SDK11_PATH)/libraries/util IPATH += $(SDK_PATH)/drivers_nrf/common @@ -166,19 +153,19 @@ IPATH += $(SDK_PATH)/drivers_nrf/uart else # src -C_SOURCE_FILES += $(SRC_PATH)/usb/usb_desc.c -C_SOURCE_FILES += $(SRC_PATH)/usb/usb.c -C_SOURCE_FILES += $(SRC_PATH)/usb/msc_uf2.c -C_SOURCE_FILES += $(SRC_PATH)/usb/uf2/ghostfat.c +C_SRC += $(SRC_PATH)/usb/usb_desc.c +C_SRC += $(SRC_PATH)/usb/usb.c +C_SRC += $(SRC_PATH)/usb/msc_uf2.c +C_SRC += $(SRC_PATH)/usb/uf2/ghostfat.c # TinyUSB stack -C_SOURCE_FILES += $(TUSB_PATH)/portable/nordic/nrf5x/dcd_nrf5x.c -C_SOURCE_FILES += $(TUSB_PATH)/common/tusb_fifo.c -C_SOURCE_FILES += $(TUSB_PATH)/device/usbd.c -C_SOURCE_FILES += $(TUSB_PATH)/device/usbd_control.c -C_SOURCE_FILES += $(TUSB_PATH)/class/cdc/cdc_device.c -C_SOURCE_FILES += $(TUSB_PATH)/class/msc/msc_device.c -C_SOURCE_FILES += $(TUSB_PATH)/tusb.c +C_SRC += $(TUSB_PATH)/portable/nordic/nrf5x/dcd_nrf5x.c +C_SRC += $(TUSB_PATH)/common/tusb_fifo.c +C_SRC += $(TUSB_PATH)/device/usbd.c +C_SRC += $(TUSB_PATH)/device/usbd_control.c +C_SRC += $(TUSB_PATH)/class/cdc/cdc_device.c +C_SRC += $(TUSB_PATH)/class/msc/msc_device.c +C_SRC += $(TUSB_PATH)/tusb.c endif @@ -186,7 +173,7 @@ endif #****************************************************************************** # Assembly Files #****************************************************************************** -ASM_SOURCE_FILES = $(NRFX_PATH)/mdk/gcc_startup_$(MCU_SUB_VARIANT).S +ASM_SRC = $(NRFX_PATH)/mdk/gcc_startup_$(MCU_SUB_VARIANT).S #****************************************************************************** # INCLUDE PATH @@ -292,12 +279,16 @@ ASMFLAGS += -DSOFTDEVICE_PRESENT ASMFLAGS += -DFLOAT_ABI_HARD ASMFLAGS += $(MCU_FLAGS) -C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES)) -C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) ) + +#function for removing duplicates in a list +remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1)))) + +C_SOURCE_FILE_NAMES = $(notdir $(C_SRC)) +C_PATHS = $(call remduplicates, $(dir $(C_SRC) ) ) C_OBJECTS = $(addprefix $(BUILD)/, $(C_SOURCE_FILE_NAMES:.c=.o) ) -ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCE_FILES)) -ASM_PATHS = $(call remduplicates, $(dir $(ASM_SOURCE_FILES) )) +ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SRC)) +ASM_PATHS = $(call remduplicates, $(dir $(ASM_SRC) )) ASM_OBJECTS = $(addprefix $(BUILD)/, $(ASM_SOURCE_FILE_NAMES:.S=.o) ) vpath %.c $(C_PATHS) diff --git a/tools/build_all.py b/tools/build_all.py index 8dd3680..bd3eeb2 100644 --- a/tools/build_all.py +++ b/tools/build_all.py @@ -1,5 +1,6 @@ import os import shutil +import glob import sys import subprocess import time @@ -7,27 +8,25 @@ import time subprocess.run("rm -rf _build*", shell=True) subprocess.run("rm -rf bin/*", shell=True) -travis = False -if "TRAVIS" in os.environ and os.environ["TRAVIS"] == "true": - travis = True - success_count = 0 fail_count = 0 exit_status = 0 -build_format = '| {:30} | {:9} ' -build_separator = '-' * 54 +build_format = '| {:32} | {:9} | {:5} | {:6} | {:6} |' +build_separator = '-' * 74 +# All supported boards all_boards = [] for entry in os.scandir("src/boards"): all_boards.append(entry.name) +all_boards.sort() #sha, version = build_info.get_version_info() total_time = time.monotonic() print(build_separator) -print((build_format + '| {:5} |').format('Board', 'Result', 'Time')) +print(build_format.format('Board', 'Result', 'Time', 'Flash', 'SRAM')) print(build_separator) for board in all_boards: @@ -51,15 +50,16 @@ for board in all_boards: if entry.name.endswith(extension) and "nosd" not in entry.name: shutil.copy(entry.path, bin_directory) - if travis: - print('travis_fold:start:build-{}\\r'.format(board)) + out_file = glob.glob('_build-{}/*.out'.format(board))[0] + size_output = subprocess.run('size {}'.format(out_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8") + size_list = size_output.split('\n')[1].split('\t') + flash_size = int(size_list[0]) + sram_size = int(size_list[1]) + int(size_list[2]) - print((build_format + '| {:.2f}s |').format(board, success, build_duration)) + print(build_format.format(board, success, "{:.2f}s".format(build_duration), flash_size, sram_size)) if make_result.returncode != 0: print(make_result.stdout.decode("utf-8")) - if travis: - print('travis_fold:end:build-{}\\r'.format(board)) # Build Summary total_time = time.monotonic() - total_time From cb735eaf8b0a7d678a77713379c94cd9d6db7134 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 24 Mar 2020 21:07:20 +0700 Subject: [PATCH 03/26] clean up makefile, move linker out of src folder --- Makefile | 40 +++++++++------------- {src/linker => linker}/nrf52833_s140_v6.ld | 0 {src/linker => linker}/nrf52840_s140_v6.ld | 0 {src/linker => linker}/nrf52_s132_v6.ld | 0 {src/linker => linker}/nrf_common.ld | 0 5 files changed, 17 insertions(+), 23 deletions(-) rename {src/linker => linker}/nrf52833_s140_v6.ld (100%) rename {src/linker => linker}/nrf52840_s140_v6.ld (100%) rename {src/linker => linker}/nrf52_s132_v6.ld (100%) rename {src/linker => linker}/nrf_common.ld (100%) diff --git a/Makefile b/Makefile index 7552462..448fc51 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,11 @@ #****************************************************************************** # CONFIGURE # - SDK_PATH : path to SDK directory -# - SRC_PATH : path to src folder # # - SD_NAME : e.g s132, s140 # - SD_VERSION : SoftDevice version e.g 6.0.0 # - SD_HEX : to bootloader hex binary #****************************************************************************** -SRC_PATH = src SDK_PATH = lib/sdk/components SDK11_PATH = lib/sdk11/components @@ -21,7 +19,8 @@ SD_FILENAME = $(SD_NAME)_nrf52_$(SD_VERSION) SD_API_PATH = $(SD_PATH)/$(SD_FILENAME)_API SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex -LD_FILE = $(SRC_PATH)/linker/$(MCU_SUB_VARIANT)_$(SD_NAME)_v$(word 1, $(subst ., ,$(SD_VERSION))).ld +# linker by MCU and SoftDevice eg. nrf52840_s140_v6.ld +LD_FILE = linker/$(MCU_SUB_VARIANT)_$(SD_NAME)_v$(word 1, $(subst ., ,$(SD_VERSION))).ld MERGED_FNAME = $(OUTPUT_FILENAME)_$(SD_NAME)_$(SD_VERSION) @@ -102,22 +101,18 @@ endif # SOURCE FILES #****************************************************************************** -# src -C_SRC += $(SRC_PATH)/boards.c -C_SRC += $(SRC_PATH)/dfu_ble_svc.c -C_SRC += $(SRC_PATH)/dfu_init.c -C_SRC += $(SRC_PATH)/flash_nrf5x.c -C_SRC += $(SRC_PATH)/main.c +# all files in src +C_SRC += $(wildcard src/*.c) # all sources files in specific board -C_SRC += $(wildcard $(SRC_PATH)/boards/$(BOARD)/*.c) +C_SRC += $(wildcard src/boards/$(BOARD)/*.c) # nrfx C_SRC += $(NRFX_PATH)/drivers/src/nrfx_power.c C_SRC += $(NRFX_PATH)/drivers/src/nrfx_nvmc.c C_SRC += $(NRFX_PATH)/mdk/system_$(MCU_SUB_VARIANT).c -# SDK 11 files +# SDK 11 files: serial + OTA DFU C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader.c C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_settings.c C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_util.c @@ -130,7 +125,7 @@ C_SRC += $(SDK11_PATH)/drivers_nrf/pstorage/pstorage_raw.c C_SRC += $(SDK11_PATH)/ble/ble_services/ble_dfu/ble_dfu.c C_SRC += $(SDK11_PATH)/ble/ble_services/ble_dis/ble_dis.c -# Latest SDK files +# Latest SDK files: peripheral drivers C_SRC += $(SDK_PATH)/libraries/timer/app_timer.c C_SRC += $(SDK_PATH)/libraries/scheduler/app_scheduler.c C_SRC += $(SDK_PATH)/libraries/util/app_error.c @@ -152,11 +147,10 @@ IPATH += $(SDK_PATH)/drivers_nrf/common IPATH += $(SDK_PATH)/drivers_nrf/uart else -# src -C_SRC += $(SRC_PATH)/usb/usb_desc.c -C_SRC += $(SRC_PATH)/usb/usb.c -C_SRC += $(SRC_PATH)/usb/msc_uf2.c -C_SRC += $(SRC_PATH)/usb/uf2/ghostfat.c + +# USB Application ( MSC + UF2 ) +C_SRC += $(wildcard src/usb/*.c) +C_SRC += $(wildcard src/usb/uf2/*.c) # TinyUSB stack C_SRC += $(TUSB_PATH)/portable/nordic/nrf5x/dcd_nrf5x.c @@ -180,12 +174,12 @@ ASM_SRC = $(NRFX_PATH)/mdk/gcc_startup_$(MCU_SUB_VARIANT).S #****************************************************************************** # src -IPATH += $(SRC_PATH) -IPATH += $(SRC_PATH)/boards/$(BOARD) +IPATH += src +IPATH += src/boards/$(BOARD) -IPATH += $(SRC_PATH)/cmsis/include -IPATH += $(SRC_PATH)/usb -IPATH += $(SRC_PATH)/boards +IPATH += src/cmsis/include +IPATH += src/usb +IPATH += src/boards IPATH += $(TUSB_PATH) # nrfx @@ -257,7 +251,7 @@ CFLAGS += -DMK_BOOTLOADER_VERSION='($(word 1,$(_VER)) << 16) + ($(word 2,$(_VER) # keep every function in separate section. This will allow linker to dump unused functions LDFLAGS += -Xlinker -Map=$(BUILD)/$(OUTPUT_FILENAME).map -LDFLAGS += -mthumb -mabi=aapcs -L$(SRC_PATH)/linker -T$(LD_FILE) +LDFLAGS += -mthumb -mabi=aapcs -Llinker -T$(LD_FILE) LDFLAGS += -mcpu=cortex-m4 LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 diff --git a/src/linker/nrf52833_s140_v6.ld b/linker/nrf52833_s140_v6.ld similarity index 100% rename from src/linker/nrf52833_s140_v6.ld rename to linker/nrf52833_s140_v6.ld diff --git a/src/linker/nrf52840_s140_v6.ld b/linker/nrf52840_s140_v6.ld similarity index 100% rename from src/linker/nrf52840_s140_v6.ld rename to linker/nrf52840_s140_v6.ld diff --git a/src/linker/nrf52_s132_v6.ld b/linker/nrf52_s132_v6.ld similarity index 100% rename from src/linker/nrf52_s132_v6.ld rename to linker/nrf52_s132_v6.ld diff --git a/src/linker/nrf_common.ld b/linker/nrf_common.ld similarity index 100% rename from src/linker/nrf_common.ld rename to linker/nrf_common.ld From 54f4fdab58cf55a6d6cd0d39d4a91e079641163e Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 24 Mar 2020 21:26:00 +0700 Subject: [PATCH 04/26] sync with tinyusb master --- lib/tinyusb | 2 +- src/usb/usb_desc.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/tinyusb b/lib/tinyusb index 23df777..f2b761f 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 23df777b301af128d3543e286cd865212214b44d +Subproject commit f2b761fee98cf9d09500e2475861e51c6ee58e61 diff --git a/src/usb/usb_desc.c b/src/usb/usb_desc.c index d54b2b8..5d7779b 100644 --- a/src/usb/usb_desc.c +++ b/src/usb/usb_desc.c @@ -150,8 +150,10 @@ static uint16_t _desc_str[64+1]; // Invoked when received GET STRING DESCRIPTOR request // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete -uint16_t const* tud_descriptor_string_cb(uint8_t index) +uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) { + (void) langid; + uint8_t chr_count; if ( index == 0) From 86809ca0432dcea5b4ffa3c3285130f5aba2b4f8 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 24 Mar 2020 21:46:54 +0700 Subject: [PATCH 05/26] fix #89 --- src/segger/Adafruit_nRF52_Bootloader.emProject | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/segger/Adafruit_nRF52_Bootloader.emProject b/src/segger/Adafruit_nRF52_Bootloader.emProject index 204a77e..4b33aae 100644 --- a/src/segger/Adafruit_nRF52_Bootloader.emProject +++ b/src/segger/Adafruit_nRF52_Bootloader.emProject @@ -20,7 +20,7 @@ arm_target_interface_type="SWD" build_treat_warnings_as_errors="Yes" c_preprocessor_definitions="__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;NO_VTOR_CONFIG;MK_BOOTLOADER_VERSION=0x00020A;CONFIG_GPIO_AS_PINRESET;CONFIG_NFCT_PINS_AS_GPIOS;BLE_STACK_SUPPORT_REQD;SWI_DISABLE0;SOFTDEVICE_PRESENT;FLOAT_ABI_HARD;CFG_TUSB_DEBUG=2;UF2_VERSION="Segger";BLEDIS_FW_VERSION="Segger"" - c_user_include_directories="../;../usb;../boards;../cmsis/include;$(tusbDir);$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include;$(sdDir)/include;$(sdDir)/include/nrf52;$(sdk11Dir)/drivers_nrf/pstorage;$(sdk11Dir)/ble/common/;$(sdk11Dir)/ble/ble_services/ble_dfu;$(sdk11Dir)/ble/ble_services/ble_dis;$(sdk11Dir)/libraries/bootloader_dfu;$(sdk11Dir)/libraries/bootloader_dfu/hci_transport;$(sdk11Dir)/libraries/util;$(sdkDir)/toolchain/cmsis/include;$(sdkDir)/device;$(sdkDir)/toolchain;$(sdkDir)/drivers_nrf/hal;$(sdkDir)/drivers_nrf/systick;$(sdkDir)/drivers_nrf/uart;$(sdkDir)/drivers_nrf/usbd;$(sdkDir)/drivers_nrf/common;$(sdkDir)/drivers_nrf/delay;$(sdkDir)/drivers_nrf/power;$(sdkDir)/drivers_nrf/clock;$(sdkDir)/libraries/util;$(sdkDir)/libraries/timer;$(sdkDir)/libraries/scheduler;$(sdkDir)/libraries/crc16;$(sdkDir)/libraries/util;$(sdkDir)/libraries/hci/config;$(sdkDir)/libraries/uart;$(sdkDir)/libraries/hci;$(sdkDir)/external/fprintf;$(sdkDir)/libraries/strerror;$(sdkDir)/libraries/atomic;$(sdkDir)/libraries/balloc;$(sdkDir)/libraries/experimental_log/src;$(sdkDir)/libraries/experimental_log;$(sdkDir)/libraries/experimental_section_vars;$(sdkDir)/libraries/experimental_memobj" + c_user_include_directories="../;../usb;../boards;../cmsis/include;$(tusbDir);$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include;$(nrfxDir)/drivers/src;$(sdDir)/include;$(sdDir)/include/nrf52;$(sdk11Dir)/drivers_nrf/pstorage;$(sdk11Dir)/ble/common/;$(sdk11Dir)/ble/ble_services/ble_dfu;$(sdk11Dir)/ble/ble_services/ble_dis;$(sdk11Dir)/libraries/bootloader_dfu;$(sdk11Dir)/libraries/bootloader_dfu/hci_transport;$(sdk11Dir)/libraries/util;$(sdkDir)/toolchain/cmsis/include;$(sdkDir)/device;$(sdkDir)/toolchain;$(sdkDir)/drivers_nrf/hal;$(sdkDir)/drivers_nrf/systick;$(sdkDir)/drivers_nrf/uart;$(sdkDir)/drivers_nrf/usbd;$(sdkDir)/drivers_nrf/common;$(sdkDir)/drivers_nrf/delay;$(sdkDir)/drivers_nrf/power;$(sdkDir)/drivers_nrf/clock;$(sdkDir)/libraries/util;$(sdkDir)/libraries/timer;$(sdkDir)/libraries/scheduler;$(sdkDir)/libraries/crc16;$(sdkDir)/libraries/util;$(sdkDir)/libraries/hci/config;$(sdkDir)/libraries/uart;$(sdkDir)/libraries/hci;$(sdkDir)/external/fprintf;$(sdkDir)/libraries/strerror;$(sdkDir)/libraries/atomic;$(sdkDir)/libraries/balloc;$(sdkDir)/libraries/experimental_log/src;$(sdkDir)/libraries/experimental_log;$(sdkDir)/libraries/experimental_section_vars;$(sdkDir)/libraries/experimental_memobj" debug_register_definition_file="$(ProjectDir)/nrf52840_Registers.xml" debug_target_connection="J-Link" gcc_enable_all_warnings="No" @@ -191,10 +191,6 @@ - - - - @@ -219,16 +215,13 @@ - - - @@ -273,6 +266,7 @@ + @@ -280,14 +274,12 @@ - - From 42734a1ab51fa00fa7c0e3319847a2f1aba007e0 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 24 Mar 2020 21:59:53 +0700 Subject: [PATCH 06/26] move segger out of src folder --- segger/Adafruit_nRF52_Bootloader.emProject | 390 ++++++++++++++++++ {src/segger => segger}/SEGGER_RTT.c | 0 {src/segger => segger}/SEGGER_RTT.h | 0 {src/segger => segger}/SEGGER_RTT_Conf.h | 0 {src/segger => segger}/SEGGER_RTT_SES.c | 0 {src/segger => segger}/flash_placement.xml | 0 .../nRF52832_xxAA_MemoryMap.xml | 0 .../nRF52840_xxAA_MemoryMap.xml | 0 {src/segger => segger}/nRF_Target.js | 0 {src/segger => segger}/nrf52840_Registers.xml | 0 {src/segger => segger}/thumb_crt0.s | 0 .../Adafruit_nRF52_Bootloader.emProject | 390 ------------------ 12 files changed, 390 insertions(+), 390 deletions(-) create mode 100644 segger/Adafruit_nRF52_Bootloader.emProject rename {src/segger => segger}/SEGGER_RTT.c (100%) rename {src/segger => segger}/SEGGER_RTT.h (100%) rename {src/segger => segger}/SEGGER_RTT_Conf.h (100%) rename {src/segger => segger}/SEGGER_RTT_SES.c (100%) rename {src/segger => segger}/flash_placement.xml (100%) rename {src/segger => segger}/nRF52832_xxAA_MemoryMap.xml (100%) rename {src/segger => segger}/nRF52840_xxAA_MemoryMap.xml (100%) rename {src/segger => segger}/nRF_Target.js (100%) rename {src/segger => segger}/nrf52840_Registers.xml (100%) rename {src/segger => segger}/thumb_crt0.s (100%) delete mode 100644 src/segger/Adafruit_nRF52_Bootloader.emProject diff --git a/segger/Adafruit_nRF52_Bootloader.emProject b/segger/Adafruit_nRF52_Bootloader.emProject new file mode 100644 index 0000000..1c7238c --- /dev/null +++ b/segger/Adafruit_nRF52_Bootloader.emProject @@ -0,0 +1,390 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/segger/SEGGER_RTT.c b/segger/SEGGER_RTT.c similarity index 100% rename from src/segger/SEGGER_RTT.c rename to segger/SEGGER_RTT.c diff --git a/src/segger/SEGGER_RTT.h b/segger/SEGGER_RTT.h similarity index 100% rename from src/segger/SEGGER_RTT.h rename to segger/SEGGER_RTT.h diff --git a/src/segger/SEGGER_RTT_Conf.h b/segger/SEGGER_RTT_Conf.h similarity index 100% rename from src/segger/SEGGER_RTT_Conf.h rename to segger/SEGGER_RTT_Conf.h diff --git a/src/segger/SEGGER_RTT_SES.c b/segger/SEGGER_RTT_SES.c similarity index 100% rename from src/segger/SEGGER_RTT_SES.c rename to segger/SEGGER_RTT_SES.c diff --git a/src/segger/flash_placement.xml b/segger/flash_placement.xml similarity index 100% rename from src/segger/flash_placement.xml rename to segger/flash_placement.xml diff --git a/src/segger/nRF52832_xxAA_MemoryMap.xml b/segger/nRF52832_xxAA_MemoryMap.xml similarity index 100% rename from src/segger/nRF52832_xxAA_MemoryMap.xml rename to segger/nRF52832_xxAA_MemoryMap.xml diff --git a/src/segger/nRF52840_xxAA_MemoryMap.xml b/segger/nRF52840_xxAA_MemoryMap.xml similarity index 100% rename from src/segger/nRF52840_xxAA_MemoryMap.xml rename to segger/nRF52840_xxAA_MemoryMap.xml diff --git a/src/segger/nRF_Target.js b/segger/nRF_Target.js similarity index 100% rename from src/segger/nRF_Target.js rename to segger/nRF_Target.js diff --git a/src/segger/nrf52840_Registers.xml b/segger/nrf52840_Registers.xml similarity index 100% rename from src/segger/nrf52840_Registers.xml rename to segger/nrf52840_Registers.xml diff --git a/src/segger/thumb_crt0.s b/segger/thumb_crt0.s similarity index 100% rename from src/segger/thumb_crt0.s rename to segger/thumb_crt0.s diff --git a/src/segger/Adafruit_nRF52_Bootloader.emProject b/src/segger/Adafruit_nRF52_Bootloader.emProject deleted file mode 100644 index 4b33aae..0000000 --- a/src/segger/Adafruit_nRF52_Bootloader.emProject +++ /dev/null @@ -1,390 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From f99645ede88693a9d7ea996c7001d0e62e8a31b6 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 24 Mar 2020 22:47:15 +0700 Subject: [PATCH 07/26] more clean up --- Makefile | 4 ++-- tools/build_all.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 448fc51..e0b0eb6 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,7 @@ GDB := $(CROSS_COMPILE)gdb NRFUTIL = adafruit-nrfutil NRFJPROG = nrfjprog -MK := mkdir +MK := mkdir -p RM := rm -rf # Verbose mode (V=). 0: default, 1: print out CFLAG, LDFLAG 2: print all compile command @@ -75,7 +75,7 @@ ifeq ($(filter $(BOARD),$(BOARD_LIST)),) endif # Build directory -BUILD = _build-$(BOARD) +BUILD = _build/build-$(BOARD) # Board specific -include src/boards/$(BOARD)/board.mk diff --git a/tools/build_all.py b/tools/build_all.py index bd3eeb2..09e1b15 100644 --- a/tools/build_all.py +++ b/tools/build_all.py @@ -5,8 +5,8 @@ import sys import subprocess import time -subprocess.run("rm -rf _build*", shell=True) -subprocess.run("rm -rf bin/*", shell=True) +subprocess.run("rm -rf _build/", shell=True) +subprocess.run("rm -rf bin/", shell=True) success_count = 0 fail_count = 0 @@ -45,12 +45,12 @@ for board in all_boards: success = "\033[31mfailed\033[0m " fail_count += 1 - for entry in os.scandir("_build-{}".format(board)): + for entry in os.scandir("_build/build-{}".format(board)): for extension in ["zip", "hex"]: if entry.name.endswith(extension) and "nosd" not in entry.name: shutil.copy(entry.path, bin_directory) - out_file = glob.glob('_build-{}/*.out'.format(board))[0] + out_file = glob.glob('_build/build-{}/*.out'.format(board))[0] size_output = subprocess.run('size {}'.format(out_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8") size_list = size_output.split('\n')[1].split('\t') flash_size = int(size_list[0]) From 5c5b9945bc86ce7a3ef6cc72f4375ba1ae4440f4 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 24 Mar 2020 23:08:23 +0700 Subject: [PATCH 08/26] rename clean up --- Makefile | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index e0b0eb6..19cfc44 100644 --- a/Makefile +++ b/Makefile @@ -22,12 +22,14 @@ SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex # linker by MCU and SoftDevice eg. nrf52840_s140_v6.ld LD_FILE = linker/$(MCU_SUB_VARIANT)_$(SD_NAME)_v$(word 1, $(subst ., ,$(SD_VERSION))).ld -MERGED_FNAME = $(OUTPUT_FILENAME)_$(SD_NAME)_$(SD_VERSION) - GIT_VERSION = $(shell git describe --dirty --always --tags) GIT_SUBMODULE_VERSIONS = $(shell git submodule status | cut -d' ' -f3,4 | paste -s -d" " -) -OUTPUT_FILENAME = $(BOARD)_bootloader-$(GIT_VERSION) +# compiled file name +OUT_FILE = $(BOARD)_bootloader-$(GIT_VERSION) + +# merged file = compiled + sd +MERGED_FILE = $(OUT_FILE)_$(SD_NAME)_$(SD_VERSION) #****************************************************************************** # Tool configure @@ -250,7 +252,7 @@ CFLAGS += -DMK_BOOTLOADER_VERSION='($(word 1,$(_VER)) << 16) + ($(word 2,$(_VER) #****************************************************************************** # keep every function in separate section. This will allow linker to dump unused functions -LDFLAGS += -Xlinker -Map=$(BUILD)/$(OUTPUT_FILENAME).map +LDFLAGS += -Xlinker -Map=$(BUILD)/$(OUT_FILE).map LDFLAGS += -mthumb -mabi=aapcs -Llinker -T$(LD_FILE) LDFLAGS += -mcpu=cortex-m4 LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 @@ -306,7 +308,7 @@ endif .phony: all clean size flash sd erase # default target to build -all: $(BUILD)/$(OUTPUT_FILENAME)-nosd.out size +all: $(BUILD)/$(OUT_FILE)-nosd.out size #******************* Flash target ******************* @@ -318,11 +320,11 @@ __check_defined = \ $(error Undefined make flag: $1$(if $2, ($2)))) # Flash the compiled -flash: $(BUILD)/$(OUTPUT_FILENAME)-nosd.hex +flash: $(BUILD)/$(OUT_FILE)-nosd.hex @echo Flashing: $< $(NRFJPROG) --program $< --sectoranduicrerase -f nrf52 --reset -dfu-flash: $(BUILD)/$(MERGED_FNAME).zip +dfu-flash: $(BUILD)/$(MERGED_FILE).zip @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0) $(NRFUTIL) --verbose dfu serial --package $< -p $(SERIAL) -b 115200 --singlebank --touch 1200 @@ -334,11 +336,11 @@ erase: @echo Erasing chip $(NRFJPROG) --eraseall -f nrf52 -gdbflash: $(BUILD)/$(MERGED_FNAME).hex +gdbflash: $(BUILD)/$(MERGED_FILE).hex @echo Flashing: $< @$(GDB_BMP) -nx --batch -ex 'load $<' -ex 'compare-sections' -ex 'kill' -gdb: $(BUILD)/$(OUTPUT_FILENAME)-nosd.out +gdb: $(BUILD)/$(OUT_FILE)-nosd.out $(GDB_BMP) $< #******************* Compile rules ******************* @@ -361,11 +363,11 @@ $(BUILD)/%.o: %.S $(QUIET)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $< # Link -$(BUILD)/$(OUTPUT_FILENAME)-nosd.out: $(BUILD) $(OBJECTS) - @echo LD $(OUTPUT_FILENAME)-nosd.out +$(BUILD)/$(OUT_FILE)-nosd.out: $(BUILD) $(OBJECTS) + @echo LD $(OUT_FILE)-nosd.out $(QUIET)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -lm -o $@ -size: $(BUILD)/$(OUTPUT_FILENAME)-nosd.out +size: $(BUILD)/$(OUT_FILE)-nosd.out -@echo '' $(QUIET)$(SIZE) $< -@echo '' @@ -375,21 +377,21 @@ size: $(BUILD)/$(OUTPUT_FILENAME)-nosd.out .phony: genhex genpkg ## Create binary .hex file from the .out file -genhex: $(BUILD)/$(OUTPUT_FILENAME)-nosd.hex +genhex: $(BUILD)/$(OUT_FILE)-nosd.hex -$(BUILD)/$(OUTPUT_FILENAME)-nosd.hex: $(BUILD)/$(OUTPUT_FILENAME)-nosd.out - @echo CR $(OUTPUT_FILENAME)-nosd.hex +$(BUILD)/$(OUT_FILE)-nosd.hex: $(BUILD)/$(OUT_FILE)-nosd.out + @echo CR $(OUT_FILE)-nosd.hex $(QUIET)$(OBJCOPY) -O ihex $< $@ # merge bootloader and sd hex together -combinehex: $(BUILD)/$(MERGED_FNAME).hex +combinehex: $(BUILD)/$(MERGED_FILE).hex -$(BUILD)/$(MERGED_FNAME).hex: $(BUILD)/$(OUTPUT_FILENAME)-nosd.hex - @echo CR $(MERGED_FNAME).hex +$(BUILD)/$(MERGED_FILE).hex: $(BUILD)/$(OUT_FILE)-nosd.hex + @echo CR $(MERGED_FILE).hex @mergehex -q -m $< $(SD_HEX) -o $@ ## Create pkg file for bootloader+SD combo to use with DFU -genpkg: $(BUILD)/$(MERGED_FNAME).zip +genpkg: $(BUILD)/$(MERGED_FILE).zip -$(BUILD)/$(MERGED_FNAME).zip: $(BUILD)/$(OUTPUT_FILENAME)-nosd.hex +$(BUILD)/$(MERGED_FILE).zip: $(BUILD)/$(OUT_FILE)-nosd.hex @$(NRFUTIL) dfu genpkg --dev-type 0x0052 --dev-revision $(DFU_DEV_REV) --bootloader $< --softdevice $(SD_HEX) $@ From e37c88446397515c92c88ed4ccefaebd7e411cb0 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 24 Mar 2020 23:26:52 +0700 Subject: [PATCH 09/26] remove unused macros BLE_STACK_SUPPORT_REQD, SWI_DISABLE0, FLOAT_ABI_HARD --- Makefile | 6 ------ segger/Adafruit_nRF52_Bootloader.emProject | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 19cfc44..4c08b6b 100644 --- a/Makefile +++ b/Makefile @@ -232,10 +232,7 @@ CFLAGS += -fno-builtin --short-enums -fstack-usage CFLAGS += -D__HEAP_SIZE=0 CFLAGS += -DCONFIG_GPIO_AS_PINRESET CFLAGS += -DCONFIG_NFCT_PINS_AS_GPIOS -CFLAGS += -DBLE_STACK_SUPPORT_REQD -CFLAGS += -DSWI_DISABLE0 CFLAGS += -DSOFTDEVICE_PRESENT -CFLAGS += -DFLOAT_ABI_HARD CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096 CFLAGS += $(MCU_FLAGS) @@ -269,10 +266,7 @@ LDFLAGS += --specs=nano.specs -lc -lnosys #****************************************************************************** ASMFLAGS += -x assembler-with-cpp ASMFLAGS += -D__HEAP_SIZE=0 -ASMFLAGS += -DBLE_STACK_SUPPORT_REQD -ASMFLAGS += -DSWI_DISABLE0 ASMFLAGS += -DSOFTDEVICE_PRESENT -ASMFLAGS += -DFLOAT_ABI_HARD ASMFLAGS += $(MCU_FLAGS) diff --git a/segger/Adafruit_nRF52_Bootloader.emProject b/segger/Adafruit_nRF52_Bootloader.emProject index 1c7238c..d5e8133 100644 --- a/segger/Adafruit_nRF52_Bootloader.emProject +++ b/segger/Adafruit_nRF52_Bootloader.emProject @@ -19,7 +19,7 @@ arm_target_device_name="nRF52840_xxAA" arm_target_interface_type="SWD" build_treat_warnings_as_errors="Yes" - c_preprocessor_definitions="__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;NO_VTOR_CONFIG;MK_BOOTLOADER_VERSION=0x00020A;CONFIG_GPIO_AS_PINRESET;CONFIG_NFCT_PINS_AS_GPIOS;BLE_STACK_SUPPORT_REQD;SWI_DISABLE0;SOFTDEVICE_PRESENT;FLOAT_ABI_HARD;CFG_TUSB_DEBUG=2;UF2_VERSION="Segger";BLEDIS_FW_VERSION="Segger"" + c_preprocessor_definitions="__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;NO_VTOR_CONFIG;MK_BOOTLOADER_VERSION=0x00020A;CONFIG_GPIO_AS_PINRESET;CONFIG_NFCT_PINS_AS_GPIOS;SOFTDEVICE_PRESENT;CFG_TUSB_DEBUG=2;UF2_VERSION="Segger";BLEDIS_FW_VERSION="Segger"" c_user_include_directories=".;../src/;../src/usb;../src/boards;../src/cmsis/include;$(tusbDir);$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include;$(nrfxDir)/drivers/src;$(sdDir)/include;$(sdDir)/include/nrf52;$(sdk11Dir)/drivers_nrf/pstorage;$(sdk11Dir)/ble/common/;$(sdk11Dir)/ble/ble_services/ble_dfu;$(sdk11Dir)/ble/ble_services/ble_dis;$(sdk11Dir)/libraries/bootloader_dfu;$(sdk11Dir)/libraries/bootloader_dfu/hci_transport;$(sdk11Dir)/libraries/util;$(sdkDir)/toolchain/cmsis/include;$(sdkDir)/device;$(sdkDir)/toolchain;$(sdkDir)/drivers_nrf/hal;$(sdkDir)/drivers_nrf/systick;$(sdkDir)/drivers_nrf/uart;$(sdkDir)/drivers_nrf/usbd;$(sdkDir)/drivers_nrf/common;$(sdkDir)/drivers_nrf/delay;$(sdkDir)/drivers_nrf/power;$(sdkDir)/drivers_nrf/clock;$(sdkDir)/libraries/util;$(sdkDir)/libraries/timer;$(sdkDir)/libraries/scheduler;$(sdkDir)/libraries/crc16;$(sdkDir)/libraries/util;$(sdkDir)/libraries/hci/config;$(sdkDir)/libraries/uart;$(sdkDir)/libraries/hci;$(sdkDir)/external/fprintf;$(sdkDir)/libraries/strerror;$(sdkDir)/libraries/atomic;$(sdkDir)/libraries/balloc;$(sdkDir)/libraries/experimental_log/src;$(sdkDir)/libraries/experimental_log;$(sdkDir)/libraries/experimental_section_vars;$(sdkDir)/libraries/experimental_memobj" debug_register_definition_file="$(ProjectDir)/nrf52840_Registers.xml" debug_target_connection="J-Link" From 54ddaa142d8623a595f9b9850c49b74a420ea3c1 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 24 Mar 2020 23:51:42 +0700 Subject: [PATCH 10/26] use gcc for linker instead of ld --- Makefile | 55 +++++++++++++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index 4c08b6b..05a0284 100644 --- a/Makefile +++ b/Makefile @@ -38,28 +38,20 @@ MERGED_FILE = $(OUT_FILE)_$(SD_NAME)_$(SD_VERSION) # Toolchain commands # Should be added to your PATH CROSS_COMPILE = arm-none-eabi- -CC := $(CROSS_COMPILE)gcc -AS := $(CROSS_COMPILE)as -AR := $(CROSS_COMPILE)ar -r -LD := $(CROSS_COMPILE)ld -NM := $(CROSS_COMPILE)nm -OBJDUMP := $(CROSS_COMPILE)objdump -OBJCOPY := $(CROSS_COMPILE)objcopy -SIZE := $(CROSS_COMPILE)size -GDB := $(CROSS_COMPILE)gdb +CC = $(CROSS_COMPILE)gcc +AS = $(CROSS_COMPILE)as +AR = $(CROSS_COMPILE)ar -r +NM = $(CROSS_COMPILE)nm +OBJDUMP = $(CROSS_COMPILE)objdump +OBJCOPY = $(CROSS_COMPILE)objcopy +SIZE = $(CROSS_COMPILE)size +GDB = $(CROSS_COMPILE)gdb NRFUTIL = adafruit-nrfutil NRFJPROG = nrfjprog -MK := mkdir -p -RM := rm -rf - -# Verbose mode (V=). 0: default, 1: print out CFLAG, LDFLAG 2: print all compile command -ifeq ("$(V)","2") - QUIET = -else - QUIET = @ -endif +MK = mkdir -p +RM = rm -rf # auto-detect BMP on macOS, otherwise have to specify BMP_PORT ?= $(shell ls -1 /dev/cu.usbmodem????????1 | head -1) @@ -226,7 +218,7 @@ CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 # 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 -fstack-usage +CFLAGS += -fno-builtin -fshort-enums -fstack-usage # Defined Symbol (MACROS) CFLAGS += -D__HEAP_SIZE=0 @@ -248,17 +240,13 @@ CFLAGS += -DMK_BOOTLOADER_VERSION='($(word 1,$(_VER)) << 16) + ($(word 2,$(_VER) # #****************************************************************************** -# keep every function in separate section. This will allow linker to dump unused functions -LDFLAGS += -Xlinker -Map=$(BUILD)/$(OUT_FILE).map -LDFLAGS += -mthumb -mabi=aapcs -Llinker -T$(LD_FILE) -LDFLAGS += -mcpu=cortex-m4 -LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 +LDFLAGS += \ + $(CFLAGS) \ + -Wl,-L,linker -Wl,-T,$(LD_FILE) \ + -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections \ + -specs=nosys.specs -specs=nano.specs -# let linker to dump unused sections -LDFLAGS += -Wl,--gc-sections - -# use newlib in nano version -LDFLAGS += --specs=nano.specs -lc -lnosys +LIBS += -lm -lc #****************************************************************************** # Assembler flags @@ -290,6 +278,7 @@ OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS) # BUILD TARGETS #****************************************************************************** +# Verbose mode (V=). 0: default, 1: print out CFLAG, LDFLAG 2: print all compile command ifeq ("$(V)","1") $(info CFLAGS $(CFLAGS)) $(info ) @@ -299,6 +288,12 @@ $(info ASMFLAGS $(ASMFLAGS)) $(info ) endif +ifeq ("$(V)","2") + QUIET = +else + QUIET = @ +endif + .phony: all clean size flash sd erase # default target to build @@ -359,7 +354,7 @@ $(BUILD)/%.o: %.S # Link $(BUILD)/$(OUT_FILE)-nosd.out: $(BUILD) $(OBJECTS) @echo LD $(OUT_FILE)-nosd.out - $(QUIET)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -lm -o $@ + $(QUIET)$(CC) -o $@ $(LDFLAGS) $(OBJECTS) -Wl,--start-group $(LIBS) -Wl,--end-group size: $(BUILD)/$(OUT_FILE)-nosd.out -@echo '' From 487871db8e85b607b8affdbd3b6b8aec7b495ef2 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 24 Mar 2020 23:53:11 +0700 Subject: [PATCH 11/26] tool clean up --- Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Makefile b/Makefile index 05a0284..8cb8abb 100644 --- a/Makefile +++ b/Makefile @@ -40,9 +40,6 @@ MERGED_FILE = $(OUT_FILE)_$(SD_NAME)_$(SD_VERSION) CROSS_COMPILE = arm-none-eabi- CC = $(CROSS_COMPILE)gcc AS = $(CROSS_COMPILE)as -AR = $(CROSS_COMPILE)ar -r -NM = $(CROSS_COMPILE)nm -OBJDUMP = $(CROSS_COMPILE)objdump OBJCOPY = $(CROSS_COMPILE)objcopy SIZE = $(CROSS_COMPILE)size GDB = $(CROSS_COMPILE)gdb From 0516c2e2477c14408d198b4ef5a03406f70b6e8f Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Mar 2020 00:04:28 +0700 Subject: [PATCH 12/26] CFLAGS clean up --- Makefile | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 8cb8abb..8611554 100644 --- a/Makefile +++ b/Makefile @@ -207,15 +207,30 @@ INC_PATHS = $(addprefix -I,$(IPATH)) # - Additional compiler flags #****************************************************************************** -#flags common to all targets -CFLAGS += -mcpu=cortex-m4 -CFLAGS += -mthumb -mabi=aapcs --std=gnu99 -CFLAGS += -Wall -Werror -Os -g3 -CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 +# Debugging/Optimization +ifeq ($(DEBUG), 1) + CFLAGS += -Og -ggdb +else + CFLAGS += -Os +endif -# 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 -fshort-enums -fstack-usage +#flags common to all targets +CFLAGS += \ + -mthumb \ + -mabi=aapcs \ + -mcpu=cortex-m4 \ + -mfloat-abi=hard \ + -mfpu=fpv4-sp-d16 \ + -ffunction-sections \ + -fdata-sections \ + -fno-builtin \ + -fshort-enums \ + -fstack-usage \ + -fno-strict-aliasing \ + -Wall \ + -Werror + +CFLAGS += -Wno-error=unused-parameter # Defined Symbol (MACROS) CFLAGS += -D__HEAP_SIZE=0 From 79ae930f1574bb11cbb46cfd757933b52e6cbc73 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Mar 2020 00:31:27 +0700 Subject: [PATCH 13/26] fix some warnings with Wextra --- Makefile | 3 ++- .../libraries/bootloader_dfu/bootloader.c | 3 ++- .../libraries/bootloader_dfu/dfu_single_bank.c | 6 ++++-- tools/build_all.py | 15 +++++++++------ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 8611554..d6054c7 100644 --- a/Makefile +++ b/Makefile @@ -228,7 +228,8 @@ CFLAGS += \ -fstack-usage \ -fno-strict-aliasing \ -Wall \ - -Werror + -Werror \ + -Wfatal-errors \ CFLAGS += -Wno-error=unused-parameter diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c index 2ad777f..44465a3 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c @@ -442,7 +442,8 @@ uint32_t bootloader_dfu_sd_update_continue(void) uint32_t bootloader_dfu_sd_update_finalize(void) { - dfu_update_status_t update_status = {DFU_UPDATE_SD_SWAPPED, }; + dfu_update_status_t update_status = { 0 }; + update_status.status_code = DFU_UPDATE_SD_SWAPPED; bootloader_dfu_update_process(update_status); diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c index 60a1729..80d8293 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c @@ -164,7 +164,8 @@ static void dfu_prepare_func_app_erase(uint32_t image_size) */ static void dfu_cleared_func_app(void) { - dfu_update_status_t update_status = {DFU_BANK_0_ERASED, }; + dfu_update_status_t update_status = { 0 }; + update_status.status_code = DFU_BANK_0_ERASED; bootloader_dfu_update_process(update_status); } @@ -498,7 +499,8 @@ uint32_t dfu_init_pkt_handle(dfu_update_packet_t * p_packet) { case DFU_STATE_RDY: m_dfu_state = DFU_STATE_RX_INIT_PKT; - // When receiving init packet in state ready just update and fall through this case. + // When receiving init packet in state ready just update and fall through this case. + /* FALLTHRU */ case DFU_STATE_RX_INIT_PKT: // DFU initialization has been done and a start packet has been received. diff --git a/tools/build_all.py b/tools/build_all.py index 09e1b15..0243724 100644 --- a/tools/build_all.py +++ b/tools/build_all.py @@ -37,9 +37,18 @@ for board in all_boards: make_result = subprocess.run("make -j 4 BOARD={} combinehex genpkg".format(board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) build_duration = time.monotonic() - start_time + flash_size = "-" + sram_size = "-" + if make_result.returncode == 0: success = "\033[32msucceeded\033[0m" success_count += 1 + + out_file = glob.glob('_build/build-{}/*.out'.format(board))[0] + size_output = subprocess.run('size {}'.format(out_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8") + size_list = size_output.split('\n')[1].split('\t') + flash_size = int(size_list[0]) + sram_size = int(size_list[1]) + int(size_list[2]) else: exit_status = make_result.returncode success = "\033[31mfailed\033[0m " @@ -50,12 +59,6 @@ for board in all_boards: if entry.name.endswith(extension) and "nosd" not in entry.name: shutil.copy(entry.path, bin_directory) - out_file = glob.glob('_build/build-{}/*.out'.format(board))[0] - size_output = subprocess.run('size {}'.format(out_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8") - size_list = size_output.split('\n')[1].split('\t') - flash_size = int(size_list[0]) - sram_size = int(size_list[1]) + int(size_list[2]) - print(build_format.format(board, success, "{:.2f}s".format(build_duration), flash_size, sram_size)) if make_result.returncode != 0: From 01ac2b3d46f90a61d08cf5b888a0eb261034af8c Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Mar 2020 00:31:39 +0700 Subject: [PATCH 14/26] clean up --- src/usb/uf2/ghostfat.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/usb/uf2/ghostfat.c b/src/usb/uf2/ghostfat.c index 6f13980..498c61e 100644 --- a/src/usb/uf2/ghostfat.c +++ b/src/usb/uf2/ghostfat.c @@ -128,7 +128,7 @@ static FAT_BootBlock const BootBlock = { .SectorsPerFAT = SECTORS_PER_FAT, .SectorsPerTrack = 1, .Heads = 1, - .PhysicalDriveNum = 0x80, // to match MediaDescriptor of 0xF8 + .PhysicalDriveNum = 0x80, // to match MediaDescriptor of 0xF8 .ExtendedBootSig = 0x29, .VolumeSerialNumber = 0x00420042, .VolumeLabel = UF2_VOLUME_LABEL, @@ -172,6 +172,7 @@ static uint32_t current_flash_size(void) result = FLASH_SIZE; } } + flash_sz = result; // presumes atomic 32-bit read/write and static result } @@ -180,13 +181,14 @@ static uint32_t current_flash_size(void) void padded_memcpy (char *dst, char const *src, int len) { - for (int i = 0; i < len; ++i) { - if (*src) - *dst = *src++; - else - *dst = ' '; - dst++; - } + for ( int i = 0; i < len; ++i ) + { + if ( *src ) + *dst = *src++; + else + *dst = ' '; + dst++; + } } From b2d4b016a983fba472e52d04950540ee17f61cef Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Mar 2020 14:09:07 +0700 Subject: [PATCH 15/26] enale Wextra clean up some warning --- Makefile | 7 ++++++- src/usb/uf2/compile_date.h | 14 +++++++------- src/usb/uf2/ghostfat.c | 6 +++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index d6054c7..9fde372 100644 --- a/Makefile +++ b/Makefile @@ -230,8 +230,13 @@ CFLAGS += \ -Wall \ -Werror \ -Wfatal-errors \ + -Wextra -CFLAGS += -Wno-error=unused-parameter +# Suppress warning caused by SDK +CFLAGS += -Wno-error=unused-parameter -Wno-error=expansion-to-defined + +# TinyUSB tusb_hal_nrf_power_event +CFLAGS += -Wno-error=cast-function-type # Defined Symbol (MACROS) CFLAGS += -D__HEAP_SIZE=0 diff --git a/src/usb/uf2/compile_date.h b/src/usb/uf2/compile_date.h index d16f4ad..7175c83 100644 --- a/src/usb/uf2/compile_date.h +++ b/src/usb/uf2/compile_date.h @@ -50,22 +50,22 @@ SOFTWARE. : 12u /*Dec*/ ) #define __DAY_INT__ ( \ - (__DATE__ [4u] == ' ' ? 0u : __DATE__ [4u] - '0') * 10u \ + (__DATE__ [4u] == ' ' ? 0 : __DATE__ [4u] - '0') * 10u \ + (__DATE__ [5u] - '0') ) // __TIME__ expands to an eight-character string constant // "23:59:01", or (if cannot determine time) "??:??:??" #define __HOUR_INT__ ( \ - (__TIME__ [0u] == '?' ? 0u : __TIME__ [0u] - '0') * 10u \ - + (__TIME__ [1u] == '?' ? 0u : __TIME__ [1u] - '0') ) + (__TIME__ [0u] == '?' ? 0 : __TIME__ [0u] - '0') * 10u \ + + (__TIME__ [1u] == '?' ? 0 : __TIME__ [1u] - '0') ) #define __MINUTE_INT__ ( \ - (__TIME__ [3u] == '?' ? 0u : __TIME__ [3u] - '0') * 10u \ - + (__TIME__ [4u] == '?' ? 0u : __TIME__ [4u] - '0') ) + (__TIME__ [3u] == '?' ? 0 : __TIME__ [3u] - '0') * 10u \ + + (__TIME__ [4u] == '?' ? 0 : __TIME__ [4u] - '0') ) #define __SECONDS_INT__ ( \ - (__TIME__ [6u] == '?' ? 0u : __TIME__ [6u] - '0') * 10u \ - + (__TIME__ [7u] == '?' ? 0u : __TIME__ [7u] - '0') ) + (__TIME__ [6u] == '?' ? 0 : __TIME__ [6u] - '0') * 10u \ + + (__TIME__ [7u] == '?' ? 0 : __TIME__ [7u] - '0') ) #define __DOSDATE__ ( \ diff --git a/src/usb/uf2/ghostfat.c b/src/usb/uf2/ghostfat.c index 498c61e..28f1e0a 100644 --- a/src/usb/uf2/ghostfat.c +++ b/src/usb/uf2/ghostfat.c @@ -214,11 +214,11 @@ void read_block(uint32_t block_no, uint8_t *data) { // WARNING -- code presumes only one NULL .content for .UF2 file // and all non-NULL .content fit in one sector // and requires it be the last element of the array - for (int i = 1; i < NUM_FILES * 2 + 4; ++i) { + for (uint32_t i = 1; i < NUM_FILES * 2 + 4; ++i) { data[i] = 0xff; } } - for (int i = 0; i < 256; ++i) { // Generate the FAT chain for the firmware "file" + for (uint32_t i = 0; i < 256; ++i) { // Generate the FAT chain for the firmware "file" uint32_t v = sectionIdx * 256 + i; if (UF2_FIRST_SECTOR <= v && v <= UF2_LAST_SECTOR) ((uint16_t *)(void *)data)[i] = v == UF2_LAST_SECTOR ? 0xffff : v + 1; @@ -237,7 +237,7 @@ void read_block(uint32_t block_no, uint8_t *data) { remainingEntries--; } - for (int i = DIRENTRIES_PER_SECTOR * sectionIdx; + for (uint32_t i = DIRENTRIES_PER_SECTOR * sectionIdx; remainingEntries > 0 && i < NUM_FILES; i++, d++) { From b91a76a16e1019f3aba2b1233161aeb61bc3626f Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Mar 2020 14:15:13 +0700 Subject: [PATCH 16/26] clean up ASFLAGS --- Makefile | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 9fde372..f05d4ea 100644 --- a/Makefile +++ b/Makefile @@ -75,15 +75,15 @@ BUILD = _build/build-$(BOARD) ifeq ($(MCU_SUB_VARIANT),nrf52) SD_NAME = s132 DFU_DEV_REV = 0xADAF - MCU_FLAGS = -DNRF52 -DNRF52832_XXAA -DS132 + CFLAGS += -DNRF52 -DNRF52832_XXAA -DS132 else ifeq ($(MCU_SUB_VARIANT),nrf52833) SD_NAME = s140 DFU_DEV_REV = 52840 - MCU_FLAGS = -DNRF52833_XXAA -DS140 + CFLAGS += -DNRF52833_XXAA -DS140 else ifeq ($(MCU_SUB_VARIANT),nrf52840) SD_NAME = s140 DFU_DEV_REV = 52840 - MCU_FLAGS = -DNRF52840_XXAA -DS140 + CFLAGS += -DNRF52840_XXAA -DS140 else $(error Sub Variant $(MCU_SUB_VARIANT) is unknown) endif @@ -244,7 +244,6 @@ CFLAGS += -DCONFIG_GPIO_AS_PINRESET CFLAGS += -DCONFIG_NFCT_PINS_AS_GPIOS CFLAGS += -DSOFTDEVICE_PRESENT CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096 -CFLAGS += $(MCU_FLAGS) CFLAGS += -DUF2_VERSION='"$(GIT_VERSION) $(GIT_SUBMODULE_VERSIONS) $(SD_NAME) $(SD_VERSION)"' CFLAGS += -DBLEDIS_FW_VERSION='"$(GIT_VERSION) $(SD_NAME) $(SD_VERSION)"' @@ -270,10 +269,7 @@ LIBS += -lm -lc # Assembler flags # #****************************************************************************** -ASMFLAGS += -x assembler-with-cpp -ASMFLAGS += -D__HEAP_SIZE=0 -ASMFLAGS += -DSOFTDEVICE_PRESENT -ASMFLAGS += $(MCU_FLAGS) +ASFLAGS += $(CFLAGS) #function for removing duplicates in a list @@ -302,7 +298,7 @@ $(info CFLAGS $(CFLAGS)) $(info ) $(info LDFLAGS $(LDFLAGS)) $(info ) -$(info ASMFLAGS $(ASMFLAGS)) +$(info ASFLAGS $(ASFLAGS)) $(info ) endif @@ -367,7 +363,7 @@ $(BUILD)/%.o: %.c # Assemble files $(BUILD)/%.o: %.S @echo AS $(notdir $<) - $(QUIET)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $< + $(QUIET)$(CC) -x assembler-with-cpp $(ASFLAGS) $(INC_PATHS) -c -o $@ $< # Link $(BUILD)/$(OUT_FILE)-nosd.out: $(BUILD) $(OBJECTS) From 98271c9f56d497656b8af00118e25e9e195dff1c Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Mar 2020 14:16:24 +0700 Subject: [PATCH 17/26] clean up QUIET --- Makefile | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index f05d4ea..0f7f352 100644 --- a/Makefile +++ b/Makefile @@ -302,12 +302,6 @@ $(info ASFLAGS $(ASFLAGS)) $(info ) endif -ifeq ("$(V)","2") - QUIET = -else - QUIET = @ -endif - .phony: all clean size flash sd erase # default target to build @@ -358,21 +352,21 @@ clean: # Create objects from C SRC files $(BUILD)/%.o: %.c @echo CC $(notdir $<) - $(QUIET)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $< + @$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $< # Assemble files $(BUILD)/%.o: %.S @echo AS $(notdir $<) - $(QUIET)$(CC) -x assembler-with-cpp $(ASFLAGS) $(INC_PATHS) -c -o $@ $< + @$(CC) -x assembler-with-cpp $(ASFLAGS) $(INC_PATHS) -c -o $@ $< # Link $(BUILD)/$(OUT_FILE)-nosd.out: $(BUILD) $(OBJECTS) @echo LD $(OUT_FILE)-nosd.out - $(QUIET)$(CC) -o $@ $(LDFLAGS) $(OBJECTS) -Wl,--start-group $(LIBS) -Wl,--end-group + @$(CC) -o $@ $(LDFLAGS) $(OBJECTS) -Wl,--start-group $(LIBS) -Wl,--end-group size: $(BUILD)/$(OUT_FILE)-nosd.out -@echo '' - $(QUIET)$(SIZE) $< + @$(SIZE) $< -@echo '' @@ -384,7 +378,7 @@ genhex: $(BUILD)/$(OUT_FILE)-nosd.hex $(BUILD)/$(OUT_FILE)-nosd.hex: $(BUILD)/$(OUT_FILE)-nosd.out @echo CR $(OUT_FILE)-nosd.hex - $(QUIET)$(OBJCOPY) -O ihex $< $@ + @$(OBJCOPY) -O ihex $< $@ # merge bootloader and sd hex together combinehex: $(BUILD)/$(MERGED_FILE).hex From c0f75b21b099163fe2974116d1ffc7ab1d3e4021 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Mar 2020 14:25:52 +0700 Subject: [PATCH 18/26] change comment style --- Makefile | 56 +++++++++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 0f7f352..c3fc53d 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,11 @@ -#****************************************************************************** +#------------------------------------------------------------------------------ # CONFIGURE -# - SDK_PATH : path to SDK directory +# - SDK_PATH : path to SDK directory # -# - SD_NAME : e.g s132, s140 +# - SD_NAME : e.g s132, s140 # - SD_VERSION : SoftDevice version e.g 6.0.0 -# - SD_HEX : to bootloader hex binary -#****************************************************************************** +# - SD_HEX : to bootloader hex binary +#------------------------------------------------------------------------------ SDK_PATH = lib/sdk/components SDK11_PATH = lib/sdk11/components @@ -31,9 +31,9 @@ OUT_FILE = $(BOARD)_bootloader-$(GIT_VERSION) # merged file = compiled + sd MERGED_FILE = $(OUT_FILE)_$(SD_NAME)_$(SD_VERSION) -#****************************************************************************** +#------------------------------------------------------------------------------ # Tool configure -#****************************************************************************** +#------------------------------------------------------------------------------ # Toolchain commands # Should be added to your PATH @@ -88,9 +88,9 @@ else $(error Sub Variant $(MCU_SUB_VARIANT) is unknown) endif -#****************************************************************************** +#------------------------------------------------------------------------------ # SOURCE FILES -#****************************************************************************** +#------------------------------------------------------------------------------ # all files in src C_SRC += $(wildcard src/*.c) @@ -110,11 +110,9 @@ C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_util.c C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_transport_serial.c C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_transport_ble.c C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_single_bank.c - -C_SRC += $(SDK11_PATH)/drivers_nrf/pstorage/pstorage_raw.c - C_SRC += $(SDK11_PATH)/ble/ble_services/ble_dfu/ble_dfu.c C_SRC += $(SDK11_PATH)/ble/ble_services/ble_dis/ble_dis.c +C_SRC += $(SDK11_PATH)/drivers_nrf/pstorage/pstorage_raw.c # Latest SDK files: peripheral drivers C_SRC += $(SDK_PATH)/libraries/timer/app_timer.c @@ -155,14 +153,14 @@ C_SRC += $(TUSB_PATH)/tusb.c endif -#****************************************************************************** +#------------------------------------------------------------------------------ # Assembly Files -#****************************************************************************** +#------------------------------------------------------------------------------ ASM_SRC = $(NRFX_PATH)/mdk/gcc_startup_$(MCU_SUB_VARIANT).S -#****************************************************************************** +#------------------------------------------------------------------------------ # INCLUDE PATH -#****************************************************************************** +#------------------------------------------------------------------------------ # src IPATH += src @@ -202,10 +200,9 @@ IPATH += $(SD_API_PATH)/include/nrf52 INC_PATHS = $(addprefix -I,$(IPATH)) -#****************************************************************************** +#------------------------------------------------------------------------------ # Compiler Flags -# - Additional compiler flags -#****************************************************************************** +#------------------------------------------------------------------------------ # Debugging/Optimization ifeq ($(DEBUG), 1) @@ -252,10 +249,9 @@ _VER = $(subst ., ,$(word 1, $(subst -, ,$(GIT_VERSION)))) CFLAGS += -DMK_BOOTLOADER_VERSION='($(word 1,$(_VER)) << 16) + ($(word 2,$(_VER)) << 8) + $(word 3,$(_VER))' -#****************************************************************************** +#------------------------------------------------------------------------------ # Linker Flags -# -#****************************************************************************** +#------------------------------------------------------------------------------ LDFLAGS += \ $(CFLAGS) \ @@ -265,10 +261,9 @@ LDFLAGS += \ LIBS += -lm -lc -#****************************************************************************** +#------------------------------------------------------------------------------ # Assembler flags -# -#****************************************************************************** +#------------------------------------------------------------------------------ ASFLAGS += $(CFLAGS) @@ -288,9 +283,9 @@ vpath %.S $(ASM_PATHS) OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS) -#****************************************************************************** +#------------------------------------------------------------------------------ # BUILD TARGETS -#****************************************************************************** +#------------------------------------------------------------------------------ # Verbose mode (V=). 0: default, 1: print out CFLAG, LDFLAG 2: print all compile command ifeq ("$(V)","1") @@ -307,7 +302,7 @@ endif # default target to build all: $(BUILD)/$(OUT_FILE)-nosd.out size -#******************* Flash target ******************* +#------------------- Flash target ------------------- check_defined = \ $(strip $(foreach 1,$1, \ @@ -340,7 +335,7 @@ gdbflash: $(BUILD)/$(MERGED_FILE).hex gdb: $(BUILD)/$(OUT_FILE)-nosd.out $(GDB_BMP) $< -#******************* Compile rules ******************* +#------------------- Compile rules ------------------- ## Create build directories $(BUILD): @@ -369,8 +364,7 @@ size: $(BUILD)/$(OUT_FILE)-nosd.out @$(SIZE) $< -@echo '' - -#******************* Binary generator ******************* +#------------------- Binary generator ------------------- .phony: genhex genpkg ## Create binary .hex file from the .out file From 7438933f2f0edb26cea71da51baf59edebd23a48 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Mar 2020 14:37:03 +0700 Subject: [PATCH 19/26] more clean up --- Makefile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index c3fc53d..0c11ef5 100644 --- a/Makefile +++ b/Makefile @@ -9,14 +9,12 @@ SDK_PATH = lib/sdk/components SDK11_PATH = lib/sdk11/components -SD_PATH = lib/softdevice/$(SD_FILENAME) - TUSB_PATH = lib/tinyusb/src NRFX_PATH = lib/nrfx +SD_PATH = lib/softdevice/$(SD_FILENAME) SD_VERSION = 6.1.1 SD_FILENAME = $(SD_NAME)_nrf52_$(SD_VERSION) -SD_API_PATH = $(SD_PATH)/$(SD_FILENAME)_API SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex # linker by MCU and SoftDevice eg. nrf52840_s140_v6.ld @@ -195,8 +193,8 @@ IPATH += $(SDK_PATH)/libraries/hci IPATH += $(SDK_PATH)/drivers_nrf/delay # Softdevice -IPATH += $(SD_API_PATH)/include -IPATH += $(SD_API_PATH)/include/nrf52 +IPATH += $(SD_PATH)/$(SD_FILENAME)_API/include +IPATH += $(SD_PATH)/$(SD_FILENAME)_API/include/nrf52 INC_PATHS = $(addprefix -I,$(IPATH)) From 09fdd7dee2e34bbce97e089df7d8d39b070bd619 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Mar 2020 17:34:49 +0700 Subject: [PATCH 20/26] remove unused dual banks --- .../libraries/bootloader_dfu/dfu_dual_bank.c | 843 ------------------ 1 file changed, 843 deletions(-) delete mode 100644 lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c deleted file mode 100644 index c98e229..0000000 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c +++ /dev/null @@ -1,843 +0,0 @@ -/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -#include -#include "dfu.h" -#include -#include "dfu_bank_internal.h" -#include "nrf.h" -#include "nrf_sdm.h" -#include "app_error.h" -#include "app_timer.h" -#include "bootloader.h" -#include "bootloader_types.h" -#include "pstorage.h" -#include "nrf_mbr.h" -#include "dfu_init.h" -#include "sdk_common.h" - -static dfu_state_t m_dfu_state; /**< Current DFU state. */ -static uint32_t m_image_size; /**< Size of the image that will be transmitted. */ - -static dfu_start_packet_t m_start_packet; /**< Start packet received for this update procedure. Contains update mode and image sizes information to be used for image transfer. */ -static uint8_t m_init_packet[128]; /**< Init packet, can hold CRC, Hash, Signed Hash and similar, for image validation, integrety check and authorization checking. */ -static uint8_t m_init_packet_length; /**< Length of init packet received. */ -static uint16_t m_image_crc; /**< Calculated CRC of the image received. */ - -APP_TIMER_DEF(m_dfu_timer_id); /**< Application timer id. */ -static bool m_dfu_timed_out = false; /**< Boolean flag value for tracking DFU timer timeout state. */ - -static pstorage_handle_t m_storage_handle_swap; /**< Pstorage handle for the swap area (bank 1). Bank used when updating an application or bootloader without SoftDevice. */ -static pstorage_handle_t m_storage_handle_app; /**< Pstorage handle for the application area (bank 0). Bank used when updating a SoftDevice w/wo bootloader. Handle also used when swapping received application from bank 1 to bank 0. */ -static pstorage_handle_t * mp_storage_handle_active; /**< Pointer to the pstorage handle for the active bank for receiving of data packets. */ - -static dfu_callback_t m_data_pkt_cb; /**< Callback from DFU Bank module for notification of asynchronous operation such as flash prepare. */ -static dfu_bank_func_t m_functions; /**< Structure holding operations for the selected update process. */ - - -/**@brief Function for handling callbacks from pstorage module. - * - * @details Handles pstorage results for clear and storage operation. For detailed description of - * the parameters provided with the callback, please refer to \ref pstorage_ntf_cb_t. - */ -static void pstorage_callback_handler(pstorage_handle_t * p_handle, - uint8_t op_code, - uint32_t result, - uint8_t * p_data, - uint32_t data_len) -{ - switch (op_code) - { - case PSTORAGE_STORE_OP_CODE: - if ((m_dfu_state == DFU_STATE_RX_DATA_PKT) && (m_data_pkt_cb != NULL)) - { - m_data_pkt_cb(DATA_PACKET, result, p_data); - } - break; - - case PSTORAGE_CLEAR_OP_CODE: - if (m_dfu_state == DFU_STATE_PREPARING) - { - m_functions.cleared(); - m_dfu_state = DFU_STATE_RDY; - if (m_data_pkt_cb != NULL) - { - m_data_pkt_cb(START_PACKET, result, p_data); - } - } - break; - - default: - break; - } - APP_ERROR_CHECK(result); -} - - -/**@brief Function for handling the DFU timeout. - * - * @param[in] p_context The timeout context. - */ -static void dfu_timeout_handler(void * p_context) -{ - UNUSED_PARAMETER(p_context); - dfu_update_status_t update_status; - - m_dfu_timed_out = true; - update_status.status_code = DFU_TIMEOUT; - - bootloader_dfu_update_process(update_status); -} - - -/**@brief Function for restarting the DFU Timer. - * - * @details This function will stop and restart the DFU timer. This function will be called by the - * functions handling any DFU packet received from the peer that is transferring a firmware - * image. - */ -static uint32_t dfu_timer_restart(void) -{ - if (m_dfu_timed_out) - { - // The DFU timer had already timed out. - return NRF_ERROR_INVALID_STATE; - } - - uint32_t err_code = app_timer_stop(m_dfu_timer_id); - APP_ERROR_CHECK(err_code); - - err_code = app_timer_start(m_dfu_timer_id, DFU_TIMEOUT_INTERVAL, NULL); - APP_ERROR_CHECK(err_code); - - return err_code; -} - - -/**@brief Function for preparing of flash before receiving SoftDevice image. - * - * @details This function will erase current application area to ensure sufficient amount of - * storage for the SoftDevice image. Upon erase complete a callback will be done. - * See \ref dfu_bank_prepare_t for further details. - */ -static void dfu_prepare_func_app_erase(uint32_t image_size) -{ - uint32_t err_code; - - mp_storage_handle_active = &m_storage_handle_app; - - // Doing a SoftDevice update thus current application must be cleared to ensure enough space - // for new SoftDevice. - m_dfu_state = DFU_STATE_PREPARING; - err_code = pstorage_clear(&m_storage_handle_app, m_image_size); - APP_ERROR_CHECK(err_code); -} - - -/**@brief Function for preparing swap before receiving application or bootloader image. - * - * @details This function will erase current swap area to ensure flash is ready for storage of the - * Application or Bootloader image. Upon erase complete a callback will be done. - * See \ref dfu_bank_prepare_t for further details. - */ -static void dfu_prepare_func_swap_erase(uint32_t image_size) -{ - uint32_t err_code; - - mp_storage_handle_active = &m_storage_handle_swap; - - m_dfu_state = DFU_STATE_PREPARING; -// err_code = pstorage_clear(&m_storage_handle_swap, DFU_IMAGE_MAX_SIZE_BANKED); - err_code = pstorage_clear(&m_storage_handle_swap, image_size); - APP_ERROR_CHECK(err_code); -} - - -/**@brief Function for handling behaviour when clear operation has completed. - */ -static void dfu_cleared_func_swap(void) -{ - // Do nothing. -} - - -/**@brief Function for handling behaviour when clear operation has completed. - */ -static void dfu_cleared_func_app(void) -{ - dfu_update_status_t update_status = {DFU_BANK_0_ERASED, }; - bootloader_dfu_update_process(update_status); -} - - -/**@brief Function for calculating storage offset for receiving SoftDevice image. - * - * @details When a new SoftDevice is received it will be temporary stored in flash before moved to - * address 0x0. In order to succesfully validate transfer and relocation it is important - * that temporary image and final installed image does not ovwerlap hence an offset must - * be calculated in case new image is larger than currently installed SoftDevice. - */ -uint32_t offset_calculate(uint32_t sd_image_size) -{ - uint32_t offset = 0; - - if (m_start_packet.sd_image_size > DFU_BANK_0_REGION_START) - { - uint32_t page_mask = (CODE_PAGE_SIZE - 1); - uint32_t diff = m_start_packet.sd_image_size - DFU_BANK_0_REGION_START; - - offset = diff & ~page_mask; - - // Align offset to next page if image size is not page sized. - if ((diff & page_mask) > 0) - { - offset += CODE_PAGE_SIZE; - } - } - - return offset; -} - - -/**@brief Function for activating received SoftDevice image. - * - * @note This function will not move the SoftDevice image. - * The bootloader settings will be marked as SoftDevice update complete and the swapping of - * current SoftDevice will occur after system reset. - * - * @return NRF_SUCCESS on success. - */ -static uint32_t dfu_activate_sd(void) -{ - dfu_update_status_t update_status; - - update_status.status_code = DFU_UPDATE_SD_COMPLETE; - update_status.app_crc = m_image_crc; - update_status.sd_image_start = DFU_BANK_0_REGION_START; - update_status.sd_size = m_start_packet.sd_image_size; - update_status.bl_size = m_start_packet.bl_image_size; - update_status.app_size = m_start_packet.app_image_size; - - bootloader_dfu_update_process(update_status); - - return NRF_SUCCESS; -} - - -/**@brief Function for activating received Application image. - * - * @details This function will move the received application image fram swap (bank 1) to - * application area (bank 0). - * - * @return NRF_SUCCESS on success. Error code otherwise. - */ -static uint32_t dfu_activate_app(void) -{ - uint32_t err_code; - - // Erase BANK 0. - err_code = pstorage_clear(&m_storage_handle_app, m_start_packet.app_image_size); - APP_ERROR_CHECK(err_code); - - err_code = pstorage_store(&m_storage_handle_app, - (uint8_t *)m_storage_handle_swap.block_id, - m_start_packet.app_image_size, - 0); - - if (err_code == NRF_SUCCESS) - { - dfu_update_status_t update_status; - - memset(&update_status, 0, sizeof(dfu_update_status_t )); - update_status.status_code = DFU_UPDATE_APP_COMPLETE; - update_status.app_crc = m_image_crc; - update_status.app_size = m_start_packet.app_image_size; - - bootloader_dfu_update_process(update_status); - } - - return err_code; -} - - -/**@brief Function for activating received Bootloader image. - * - * @note This function will not move the bootloader image. - * The bootloader settings will be marked as Bootloader update complete and the swapping of - * current bootloader will occur after system reset. - * - * @return NRF_SUCCESS on success. - */ -static uint32_t dfu_activate_bl(void) -{ - dfu_update_status_t update_status; - - update_status.status_code = DFU_UPDATE_BOOT_COMPLETE; - update_status.app_crc = m_image_crc; - update_status.sd_size = m_start_packet.sd_image_size; - update_status.bl_size = m_start_packet.bl_image_size; - update_status.app_size = m_start_packet.app_image_size; - - bootloader_dfu_update_process(update_status); - - return NRF_SUCCESS; -} - - -uint32_t dfu_init(void) -{ - uint32_t err_code; - pstorage_module_param_t storage_module_param = {.cb = pstorage_callback_handler}; - - m_init_packet_length = 0; - m_image_crc = 0; - - err_code = pstorage_register(&storage_module_param, &m_storage_handle_app); - if (err_code != NRF_SUCCESS) - { - m_dfu_state = DFU_STATE_INIT_ERROR; - return err_code; - } - - m_storage_handle_app.block_id = DFU_BANK_0_REGION_START; - m_storage_handle_swap = m_storage_handle_app; - m_storage_handle_swap.block_id = DFU_BANK_1_REGION_START; - - // Create the timer to monitor the activity by the peer doing the firmware update. - err_code = app_timer_create(&m_dfu_timer_id, - APP_TIMER_MODE_SINGLE_SHOT, - dfu_timeout_handler); - APP_ERROR_CHECK(err_code); - - // Start the DFU timer. - err_code = app_timer_start(m_dfu_timer_id, DFU_TIMEOUT_INTERVAL, NULL); - APP_ERROR_CHECK(err_code); - - m_data_received = 0; - m_dfu_state = DFU_STATE_IDLE; - - return NRF_SUCCESS; -} - - -void dfu_register_callback(dfu_callback_t callback_handler) -{ - m_data_pkt_cb = callback_handler; -} - - -uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet) -{ - uint32_t err_code; - - m_start_packet = *(p_packet->params.start_packet); - - // Check that the requested update procedure is supported. - // Currently the following combinations are allowed: - // - Application - // - SoftDevice - // - Bootloader - // - SoftDevice with Bootloader - if (IS_UPDATING_APP(m_start_packet) && - (IS_UPDATING_SD(m_start_packet) || IS_UPDATING_BL(m_start_packet))) - { - // App update is only supported independently. - return NRF_ERROR_NOT_SUPPORTED; - } - - if (!(IS_WORD_SIZED(m_start_packet.sd_image_size) && - IS_WORD_SIZED(m_start_packet.bl_image_size) && - IS_WORD_SIZED(m_start_packet.app_image_size))) - { - // Image_sizes are not a multiple of 4 (word size). - return NRF_ERROR_NOT_SUPPORTED; - } - - m_image_size = m_start_packet.sd_image_size + m_start_packet.bl_image_size + - m_start_packet.app_image_size; - - if (m_start_packet.bl_image_size > DFU_BL_IMAGE_MAX_SIZE) - { - return NRF_ERROR_DATA_SIZE; - } - - if (IS_UPDATING_SD(m_start_packet)) - { - if (m_image_size > (DFU_IMAGE_MAX_SIZE_FULL)) - { - return NRF_ERROR_DATA_SIZE; - } - m_functions.prepare = dfu_prepare_func_app_erase; - m_functions.cleared = dfu_cleared_func_app; - m_functions.activate = dfu_activate_sd; - } - else - { - if (m_image_size > DFU_IMAGE_MAX_SIZE_BANKED) - { - return NRF_ERROR_DATA_SIZE; - } - - m_functions.prepare = dfu_prepare_func_swap_erase; - m_functions.cleared = dfu_cleared_func_swap; - if (IS_UPDATING_BL(m_start_packet)) - { - m_functions.activate = dfu_activate_bl; - } - else - { - m_functions.activate = dfu_activate_app; - } - } - - switch (m_dfu_state) - { - case DFU_STATE_IDLE: - // Valid peer activity detected. Hence restart the DFU timer. - err_code = dfu_timer_restart(); - VERIFY_SUCCESS(err_code); - m_functions.prepare(m_image_size); - - break; - - default: - err_code = NRF_ERROR_INVALID_STATE; - break; - } - - return err_code; -} - - -uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet) -{ - uint32_t data_length; - uint32_t err_code; - uint32_t * p_data; - - VERIFY_PARAM_NOT_NULL(p_packet); - - // Check pointer alignment. - if (!is_word_aligned(p_packet->params.data_packet.p_data_packet)) - { - // The p_data_packet is not word aligned address. - return NRF_ERROR_INVALID_ADDR; - } - - switch (m_dfu_state) - { - case DFU_STATE_RDY: - case DFU_STATE_RX_INIT_PKT: - return NRF_ERROR_INVALID_STATE; - - case DFU_STATE_RX_DATA_PKT: - data_length = p_packet->params.data_packet.packet_length * sizeof(uint32_t); - - if ((m_data_received + data_length) > m_image_size) - { - // The caller is trying to write more bytes into the flash than the size provided to - // the dfu_image_size_set function. This is treated as a serious error condition and - // an unrecoverable one. Hence point the variable mp_app_write_address to the top of - // the flash area. This will ensure that all future application data packet writes - // will be blocked because of the above check. - m_data_received = 0xFFFFFFFF; - - return NRF_ERROR_DATA_SIZE; - } - - // Valid peer activity detected. Hence restart the DFU timer. - err_code = dfu_timer_restart(); - VERIFY_SUCCESS(err_code); - - p_data = (uint32_t *)p_packet->params.data_packet.p_data_packet; - - err_code = pstorage_store(mp_storage_handle_active, - (uint8_t *)p_data, - data_length, - m_data_received); - VERIFY_SUCCESS(err_code); - - m_data_received += data_length; - - if (m_data_received != m_image_size) - { - // The entire image is not received yet. More data is expected. - err_code = NRF_ERROR_INVALID_LENGTH; - } - else - { - // The entire image has been received. Return NRF_SUCCESS. - err_code = NRF_SUCCESS; - } - break; - - default: - err_code = NRF_ERROR_INVALID_STATE; - break; - } - - return err_code; -} - - -uint32_t dfu_init_pkt_complete(void) -{ - uint32_t err_code = NRF_ERROR_INVALID_STATE; - - // DFU initialization has been done and a start packet has been received. - if (IMAGE_WRITE_IN_PROGRESS()) - { - // Image write is already in progress. Cannot handle an init packet now. - return NRF_ERROR_INVALID_STATE; - } - - if (m_dfu_state == DFU_STATE_RX_INIT_PKT) - { - err_code = dfu_init_prevalidate(m_init_packet, m_init_packet_length, m_start_packet.dfu_update_mode); - if (err_code == NRF_SUCCESS) - { - m_dfu_state = DFU_STATE_RX_DATA_PKT; - } - else - { - m_init_packet_length = 0; - } - } - return err_code; -} - - -uint32_t dfu_init_pkt_handle(dfu_update_packet_t * p_packet) -{ - uint32_t err_code = NRF_SUCCESS; - uint32_t length; - - switch (m_dfu_state) - { - case DFU_STATE_RDY: - m_dfu_state = DFU_STATE_RX_INIT_PKT; - // When receiving init packet in state ready just update and fall through this case. - - case DFU_STATE_RX_INIT_PKT: - // DFU initialization has been done and a start packet has been received. - if (IMAGE_WRITE_IN_PROGRESS()) - { - // Image write is already in progress. Cannot handle an init packet now. - return NRF_ERROR_INVALID_STATE; - } - - // Valid peer activity detected. Hence restart the DFU timer. - err_code = dfu_timer_restart(); - VERIFY_SUCCESS(err_code); - - length = p_packet->params.data_packet.packet_length * sizeof(uint32_t); - if ((m_init_packet_length + length) > sizeof(m_init_packet)) - { - return NRF_ERROR_INVALID_LENGTH; - } - - memcpy(&m_init_packet[m_init_packet_length], - &p_packet->params.data_packet.p_data_packet[0], - length); - m_init_packet_length += length; - break; - - default: - // Either the start packet was not received or dfu_init function was not called before. - err_code = NRF_ERROR_INVALID_STATE; - break; - } - - return err_code; -} - - -uint32_t dfu_image_validate() -{ - uint32_t err_code; - - switch (m_dfu_state) - { - case DFU_STATE_RX_DATA_PKT: - // Check if the application image write has finished. - if (m_data_received != m_image_size) - { - // Image not yet fully transfered by the peer or the peer has attempted to write - // too much data. Hence the validation should fail. - err_code = NRF_ERROR_INVALID_STATE; - } - else - { - m_dfu_state = DFU_STATE_VALIDATE; - - // Valid peer activity detected. Hence restart the DFU timer. - err_code = dfu_timer_restart(); - if (err_code == NRF_SUCCESS) - { - err_code = dfu_init_postvalidate((uint8_t *)mp_storage_handle_active->block_id, - m_image_size); - VERIFY_SUCCESS(err_code); - - m_dfu_state = DFU_STATE_WAIT_4_ACTIVATE; - } - } - break; - - default: - err_code = NRF_ERROR_INVALID_STATE; - break; - } - - return err_code; -} - - -uint32_t dfu_image_activate() -{ - uint32_t err_code; - - switch (m_dfu_state) - { - case DFU_STATE_WAIT_4_ACTIVATE: - - // Stop the DFU Timer because the peer activity need not be monitored any longer. - err_code = app_timer_stop(m_dfu_timer_id); - APP_ERROR_CHECK(err_code); - - err_code = m_functions.activate(); - break; - - default: - err_code = NRF_ERROR_INVALID_STATE; - break; - } - - return err_code; -} - - -void dfu_reset(void) -{ - dfu_update_status_t update_status; - - update_status.status_code = DFU_RESET; - - bootloader_dfu_update_process(update_status); -} - - -static uint32_t dfu_compare_block(uint32_t * ptr1, uint32_t * ptr2, uint32_t len) -{ - sd_mbr_command_t sd_mbr_cmd; - - sd_mbr_cmd.command = SD_MBR_COMMAND_COMPARE; - sd_mbr_cmd.params.compare.ptr1 = ptr1; - sd_mbr_cmd.params.compare.ptr2 = ptr2; - sd_mbr_cmd.params.compare.len = len / sizeof(uint32_t); - - return sd_mbr_command(&sd_mbr_cmd); -} - - -static uint32_t dfu_copy_sd(uint32_t * src, uint32_t * dst, uint32_t len) -{ - sd_mbr_command_t sd_mbr_cmd; - - sd_mbr_cmd.command = SD_MBR_COMMAND_COPY_SD; - sd_mbr_cmd.params.copy_sd.src = src; - sd_mbr_cmd.params.copy_sd.dst = dst; - sd_mbr_cmd.params.copy_sd.len = len / sizeof(uint32_t); - - return sd_mbr_command(&sd_mbr_cmd); -} - - -static uint32_t dfu_sd_img_block_swap(uint32_t * src, - uint32_t * dst, - uint32_t len, - uint32_t block_size) -{ - // It is neccesarry to swap the new SoftDevice in 3 rounds to ensure correct copy of data - // and verifucation of data in case power reset occurs during write to flash. - // To ensure the robustness of swapping the images are compared backwards till start of - // image swap. If the back is identical everything is swapped. - uint32_t err_code = dfu_compare_block(src, dst, len); - if (err_code == NRF_SUCCESS) - { - return err_code; - } - - if ((uint32_t)dst > SOFTDEVICE_REGION_START) - { - err_code = dfu_sd_img_block_swap((uint32_t *)((uint32_t)src - block_size), - (uint32_t *)((uint32_t)dst - block_size), - block_size, - block_size); - VERIFY_SUCCESS(err_code); - } - - err_code = dfu_copy_sd(src, dst, len); - VERIFY_SUCCESS(err_code); - - return dfu_compare_block(src, dst, len); -} - - -uint32_t dfu_sd_image_swap(void) -{ - bootloader_settings_t boot_settings; - - bootloader_settings_get(&boot_settings); - - if (boot_settings.sd_image_size == 0) - { - return NRF_SUCCESS; - } - - if ((SOFTDEVICE_REGION_START + boot_settings.sd_image_size) > boot_settings.sd_image_start) - { - uint32_t err_code; - uint32_t sd_start = SOFTDEVICE_REGION_START; - uint32_t block_size = (boot_settings.sd_image_start - sd_start) / 2; - - /* ##### FIX START ##### */ - block_size &= ~(uint32_t)(CODE_PAGE_SIZE - 1); - /* ##### FIX END ##### */ - - uint32_t image_end = boot_settings.sd_image_start + boot_settings.sd_image_size; - - uint32_t img_block_start = boot_settings.sd_image_start + 2 * block_size; - uint32_t sd_block_start = sd_start + 2 * block_size; - - if (SD_SIZE_GET(MBR_SIZE) < boot_settings.sd_image_size) - { - // This will clear a page thus ensuring the old image is invalidated before swapping. - err_code = dfu_copy_sd((uint32_t *)(sd_start + block_size), - (uint32_t *)(sd_start + block_size), - sizeof(uint32_t)); - VERIFY_SUCCESS(err_code); - - err_code = dfu_copy_sd((uint32_t *)sd_start, (uint32_t *)sd_start, sizeof(uint32_t)); - VERIFY_SUCCESS(err_code); - } - - return dfu_sd_img_block_swap((uint32_t *)img_block_start, - (uint32_t *)sd_block_start, - image_end - img_block_start, - block_size); - } - else - { - if (boot_settings.sd_image_size != 0) - { - return dfu_copy_sd((uint32_t *)boot_settings.sd_image_start, - (uint32_t *)SOFTDEVICE_REGION_START, - boot_settings.sd_image_size); - } - } - - return NRF_SUCCESS; -} - - -uint32_t dfu_bl_image_swap(void) -{ - bootloader_settings_t bootloader_settings; - sd_mbr_command_t sd_mbr_cmd; - - bootloader_settings_get(&bootloader_settings); - - if (bootloader_settings.bl_image_size != 0) - { - uint32_t bl_image_start = (bootloader_settings.sd_image_size == 0) ? - DFU_BANK_1_REGION_START : - bootloader_settings.sd_image_start + - bootloader_settings.sd_image_size; - - sd_mbr_cmd.command = SD_MBR_COMMAND_COPY_BL; - sd_mbr_cmd.params.copy_bl.bl_src = (uint32_t *)(bl_image_start); - sd_mbr_cmd.params.copy_bl.bl_len = bootloader_settings.bl_image_size / sizeof(uint32_t); - - return sd_mbr_command(&sd_mbr_cmd); - } - return NRF_SUCCESS; -} - - -uint32_t dfu_bl_image_validate(void) -{ - bootloader_settings_t bootloader_settings; - sd_mbr_command_t sd_mbr_cmd; - - bootloader_settings_get(&bootloader_settings); - - if (bootloader_settings.bl_image_size != 0) - { - uint32_t bl_image_start = (bootloader_settings.sd_image_size == 0) ? - DFU_BANK_1_REGION_START : - bootloader_settings.sd_image_start + - bootloader_settings.sd_image_size; - - sd_mbr_cmd.command = SD_MBR_COMMAND_COMPARE; - sd_mbr_cmd.params.compare.ptr1 = (uint32_t *)BOOTLOADER_REGION_START; - sd_mbr_cmd.params.compare.ptr2 = (uint32_t *)(bl_image_start); - sd_mbr_cmd.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); - - return sd_mbr_command(&sd_mbr_cmd); - } - return NRF_SUCCESS; -} - - -uint32_t dfu_sd_image_validate(void) -{ - bootloader_settings_t bootloader_settings; - sd_mbr_command_t sd_mbr_cmd; - - bootloader_settings_get(&bootloader_settings); - - if (bootloader_settings.sd_image_size == 0) - { - return NRF_SUCCESS; - } - - if ((SOFTDEVICE_REGION_START + bootloader_settings.sd_image_size) > bootloader_settings.sd_image_start) - { - uint32_t sd_start = SOFTDEVICE_REGION_START; - uint32_t block_size = (bootloader_settings.sd_image_start - sd_start) / 2; - uint32_t image_end = bootloader_settings.sd_image_start + - bootloader_settings.sd_image_size; - - /* ##### FIX START ##### */ - block_size &= ~(uint32_t)(CODE_PAGE_SIZE - 1); - /* ##### FIX END ##### */ - uint32_t img_block_start = bootloader_settings.sd_image_start + 2 * block_size; - uint32_t sd_block_start = sd_start + 2 * block_size; - - if (SD_SIZE_GET(MBR_SIZE) < bootloader_settings.sd_image_size) - { - return NRF_ERROR_NULL; - } - - return dfu_sd_img_block_swap((uint32_t *)img_block_start, - (uint32_t *)sd_block_start, - image_end - img_block_start, - block_size); - } - - sd_mbr_cmd.command = SD_MBR_COMMAND_COMPARE; - sd_mbr_cmd.params.compare.ptr1 = (uint32_t *)SOFTDEVICE_REGION_START; - sd_mbr_cmd.params.compare.ptr2 = (uint32_t *)bootloader_settings.sd_image_start; - sd_mbr_cmd.params.compare.len = bootloader_settings.sd_image_size / sizeof(uint32_t); - - return sd_mbr_command(&sd_mbr_cmd); -} From 6b3f70db470a149db0283af2c90aae7286ba6062 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Mar 2020 18:18:27 +0700 Subject: [PATCH 21/26] remove all uart pin from nrf52840 board, since it is not used. --- src/boards/aramcon_badge_2019/board.h | 13 ++------ .../arcade_feather_nrf52840_express/board.h | 9 ------ src/boards/arduino_nano_33_ble/board.h | 13 ++------ src/boards/circuitplayground_nrf52840/board.h | 13 ++------ src/boards/clue_nrf52840/board.h | 13 ++------ src/boards/electronut_labs_papyr/board.h | 16 ++++------ src/boards/feather_nrf52832/board.h | 4 ++- src/boards/feather_nrf52840_sense/board.h | 9 ------ src/boards/itsybitsy_nrf52840_express/board.h | 13 ++------ src/boards/mdk_nrf52840_dongle/board.h | 8 ++++- src/boards/metro_nrf52840_express/board.h | 13 ++------ src/boards/ohs2020_badge/board.h | 13 ++------ src/boards/particle_argon/board.h | 16 ++++------ src/boards/particle_boron/board.h | 16 ++++------ src/boards/particle_xenon/board.h | 30 ++++++++----------- src/boards/pca10056/board.h | 16 ++++------ src/boards/pca10059/board.h | 16 ++++------ src/boards/pca10100/board.h | 16 ++++------ src/boards/raytac_mdbt50q_rx/board.h | 9 ------ src/boards/waveshare_nrf52840_eval/board.h | 9 ------ 20 files changed, 80 insertions(+), 185 deletions(-) diff --git a/src/boards/aramcon_badge_2019/board.h b/src/boards/aramcon_badge_2019/board.h index 9e84b23..3dc666d 100644 --- a/src/boards/aramcon_badge_2019/board.h +++ b/src/boards/aramcon_badge_2019/board.h @@ -46,16 +46,9 @@ #define BUTTON_2 _PINNUM(0, 29) // middle button #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER _PINNUM(0, 28) // SDA -#define TX_PIN_NUMBER _PINNUM(0, 3) // SCL -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - -// Used as model string in OTA mode +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ #define BLEDIS_MANUFACTURER "ARAMCON Badge Team" #define BLEDIS_MODEL "ARAMCON Badge 2019" diff --git a/src/boards/arcade_feather_nrf52840_express/board.h b/src/boards/arcade_feather_nrf52840_express/board.h index 738d8a9..aed04ed 100644 --- a/src/boards/arcade_feather_nrf52840_express/board.h +++ b/src/boards/arcade_feather_nrf52840_express/board.h @@ -47,15 +47,6 @@ #define BUTTON_2 _PINNUM(0, 10) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ diff --git a/src/boards/arduino_nano_33_ble/board.h b/src/boards/arduino_nano_33_ble/board.h index ad3420e..00fb2ef 100644 --- a/src/boards/arduino_nano_33_ble/board.h +++ b/src/boards/arduino_nano_33_ble/board.h @@ -42,16 +42,9 @@ #define BUTTON_2 _PINNUM(1, 12) // D3 switch #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER _PINNUM(1, 10) -#define TX_PIN_NUMBER _PINNUM(1, 3) -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - -// Used as model string in OTA mode +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ #define BLEDIS_MANUFACTURER "Arduino" #define BLEDIS_MODEL "Nano 33 BLE" diff --git a/src/boards/circuitplayground_nrf52840/board.h b/src/boards/circuitplayground_nrf52840/board.h index 8f58e13..5544502 100644 --- a/src/boards/circuitplayground_nrf52840/board.h +++ b/src/boards/circuitplayground_nrf52840/board.h @@ -46,16 +46,9 @@ #define BUTTON_2 _PINNUM(1, 15) // right button #define BUTTON_PULL NRF_GPIO_PIN_PULLDOWN -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER _PINNUM(0, 30) -#define TX_PIN_NUMBER _PINNUM(0, 14) -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - -// Used as model string in OTA mode +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ #define BLEDIS_MANUFACTURER "Adafruit Industries" #define BLEDIS_MODEL "Circuit Playground nRF52840" diff --git a/src/boards/clue_nrf52840/board.h b/src/boards/clue_nrf52840/board.h index f8d32aa..efba060 100644 --- a/src/boards/clue_nrf52840/board.h +++ b/src/boards/clue_nrf52840/board.h @@ -46,16 +46,9 @@ #define BUTTON_2 _PINNUM(1, 10) // right button #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER _PINNUM(0, 09) -#define TX_PIN_NUMBER _PINNUM(0, 10) -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - -// Used as model string in OTA mode +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ #define BLEDIS_MANUFACTURER "Adafruit Industries" #define BLEDIS_MODEL "CLUE nRF52840" diff --git a/src/boards/electronut_labs_papyr/board.h b/src/boards/electronut_labs_papyr/board.h index 408f62a..738dd50 100644 --- a/src/boards/electronut_labs_papyr/board.h +++ b/src/boards/electronut_labs_papyr/board.h @@ -47,19 +47,15 @@ #define BUTTON_2 1 // P0.1 not exposed anywhere, FRST n/a #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 7 -#define TX_PIN_NUMBER 8 -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - -// Used as model string in OTA mode +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ #define BLEDIS_MANUFACTURER "Electronut Labs" #define BLEDIS_MODEL "Papyr" +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ #define UF2_PRODUCT_NAME "Electronut Labs Papyr" #define UF2_BOARD_ID "nRF52840-Papyr-v1" #define UF2_INDEX_URL "https://docs.electronut.in/papyr" diff --git a/src/boards/feather_nrf52832/board.h b/src/boards/feather_nrf52832/board.h index aa35ee3..a31bafa 100644 --- a/src/boards/feather_nrf52832/board.h +++ b/src/boards/feather_nrf52832/board.h @@ -50,7 +50,9 @@ #define RTS_PIN_NUMBER 0 #define HWFC false -// Used as model string in OTA mode +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ #define BLEDIS_MANUFACTURER "Adafruit Industries" #define BLEDIS_MODEL "Feather nRF52832" diff --git a/src/boards/feather_nrf52840_sense/board.h b/src/boards/feather_nrf52840_sense/board.h index 9d3611b..fbaf9bc 100644 --- a/src/boards/feather_nrf52840_sense/board.h +++ b/src/boards/feather_nrf52840_sense/board.h @@ -47,15 +47,6 @@ #define BUTTON_2 _PINNUM(0, 10) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ diff --git a/src/boards/itsybitsy_nrf52840_express/board.h b/src/boards/itsybitsy_nrf52840_express/board.h index 68ea958..2bc82e0 100644 --- a/src/boards/itsybitsy_nrf52840_express/board.h +++ b/src/boards/itsybitsy_nrf52840_express/board.h @@ -46,16 +46,9 @@ #define BUTTON_2 _PINNUM(1, 02) // D2 breakout #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER _PINNUM(0, 25) -#define TX_PIN_NUMBER _PINNUM(0, 24) -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - -// Used as model string in OTA mode +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ #define BLEDIS_MANUFACTURER "Adafruit Industries" #define BLEDIS_MODEL "ItsyBitsy nRF52840 Express" diff --git a/src/boards/mdk_nrf52840_dongle/board.h b/src/boards/mdk_nrf52840_dongle/board.h index 3f3c6a3..c45213e 100644 --- a/src/boards/mdk_nrf52840_dongle/board.h +++ b/src/boards/mdk_nrf52840_dongle/board.h @@ -39,6 +39,7 @@ //#define LED_RGB_GREEN_PIN _PINNUM(0, 22) //#define LED_RGB_BLUE_PIN _PINNUM(0, 24) #define BOARD_RGB_BRIGHTNESS 0x404040 + /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ @@ -48,10 +49,15 @@ #define BUTTON_2 _PINNUM(0, 19) // no connection #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -// Used as model string in OTA mode +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ #define BLEDIS_MANUFACTURER "MakerDiary" #define BLEDIS_MODEL "nRF52840 Micro Dev Kit USB Dongle" +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ #define UF2_PRODUCT_NAME "MDK nRF52840 USB Dongle" #define UF2_VOLUME_LABEL "MDK840DONGL" #define UF2_BOARD_ID "nRF52840-Dongle-v1" diff --git a/src/boards/metro_nrf52840_express/board.h b/src/boards/metro_nrf52840_express/board.h index ef3c8a2..0b47a1c 100644 --- a/src/boards/metro_nrf52840_express/board.h +++ b/src/boards/metro_nrf52840_express/board.h @@ -47,16 +47,9 @@ #define BUTTON_2 _PINNUM(2, 2) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - -// Used as model string in OTA mode +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ #define BLEDIS_MANUFACTURER "Adafruit Industries" #define BLEDIS_MODEL "Metro nRF52840 Express" diff --git a/src/boards/ohs2020_badge/board.h b/src/boards/ohs2020_badge/board.h index 4776999..1a62811 100644 --- a/src/boards/ohs2020_badge/board.h +++ b/src/boards/ohs2020_badge/board.h @@ -43,16 +43,9 @@ #define BUTTON_2 _PINNUM(0, 03) // SW1 #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER _PINNUM(0, 09) -#define TX_PIN_NUMBER _PINNUM(0, 10) -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - -// Used as model string in OTA mode +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ #define BLEDIS_MANUFACTURER "OSHWA" #define BLEDIS_MODEL "OHS2020 Badge" diff --git a/src/boards/particle_argon/board.h b/src/boards/particle_argon/board.h index 312bfe3..467a7df 100644 --- a/src/boards/particle_argon/board.h +++ b/src/boards/particle_argon/board.h @@ -47,19 +47,15 @@ #define BUTTON_FRESET _PINNUM(0, 03) // A0 #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - -// Used as model string in OTA mode +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ #define BLEDIS_MANUFACTURER "Particle Industries" #define BLEDIS_MODEL "Argon" +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ #define UF2_PRODUCT_NAME "Particle Argon" #define UF2_VOLUME_LABEL "ARGONBOOT " #define UF2_BOARD_ID "nRF52840-Argon-v1" diff --git a/src/boards/particle_boron/board.h b/src/boards/particle_boron/board.h index 7d1d36d..b433cea 100644 --- a/src/boards/particle_boron/board.h +++ b/src/boards/particle_boron/board.h @@ -47,19 +47,15 @@ #define BUTTON_FRESET _PINNUM(0, 03) // A0 #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - -// Used as model string in OTA mode +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ #define BLEDIS_MANUFACTURER "Particle Industries" #define BLEDIS_MODEL "Boron" +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ #define UF2_PRODUCT_NAME "Particle Boron" #define UF2_VOLUME_LABEL "BORONBOOT " #define UF2_BOARD_ID "nRF52840-Boron-v1" diff --git a/src/boards/particle_xenon/board.h b/src/boards/particle_xenon/board.h index 3f945b0..5fe2474 100644 --- a/src/boards/particle_xenon/board.h +++ b/src/boards/particle_xenon/board.h @@ -30,14 +30,14 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ - #define LEDS_NUMBER 1 - #define LED_PRIMARY_PIN _PINNUM(1, 12) - #define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN _PINNUM(1, 12) +#define LED_STATE_ON 1 - #define LED_RGB_RED_PIN _PINNUM(0, 13) - #define LED_RGB_GREEN_PIN _PINNUM(0, 14) - #define LED_RGB_BLUE_PIN _PINNUM(0, 15) - #define BOARD_RGB_BRIGHTNESS 0x202020 +#define LED_RGB_RED_PIN _PINNUM(0, 13) +#define LED_RGB_GREEN_PIN _PINNUM(0, 14) +#define LED_RGB_BLUE_PIN _PINNUM(0, 15) +#define BOARD_RGB_BRIGHTNESS 0x202020 /*------------------------------------------------------------------*/ /* BUTTON @@ -47,19 +47,15 @@ #define BUTTON_FRESET _PINNUM(0, 03) // A0 #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - -// Used as model string in OTA mode +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ #define BLEDIS_MANUFACTURER "Particle Industries" #define BLEDIS_MODEL "Xenon" +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ #define UF2_PRODUCT_NAME "Particle Xenon" #define UF2_VOLUME_LABEL "XENONBOOT " #define UF2_BOARD_ID "nRF52840-Xenon-v1" diff --git a/src/boards/pca10056/board.h b/src/boards/pca10056/board.h index fbbdee6..a17d597 100644 --- a/src/boards/pca10056/board.h +++ b/src/boards/pca10056/board.h @@ -41,19 +41,15 @@ #define BUTTON_2 12 #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - -// Used as model string in OTA mode +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ #define BLEDIS_MANUFACTURER "Nordic" #define BLEDIS_MODEL "PCA10056" +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ #define UF2_PRODUCT_NAME "Nordic nRF52840 DK" #define UF2_BOARD_ID "nRF52840-pca10056-v1" #define UF2_INDEX_URL "https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-DK" diff --git a/src/boards/pca10059/board.h b/src/boards/pca10059/board.h index 336b62f..6654b87 100644 --- a/src/boards/pca10059/board.h +++ b/src/boards/pca10059/board.h @@ -44,19 +44,15 @@ #define BUTTON_2 _PINNUM(1, 10) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 20 -#define TX_PIN_NUMBER 17 -#define CTS_PIN_NUMBER 15 -#define RTS_PIN_NUMBER 13 -#define HWFC false - -// Used as model string in OTA mode +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ #define BLEDIS_MANUFACTURER "Nordic" #define BLEDIS_MODEL "PCA10059" +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ #define UF2_PRODUCT_NAME "Nordic nRF52840 Dongle" #define UF2_BOARD_ID "nRF52840-pca10059-v1" #define UF2_INDEX_URL "https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-Dongle" diff --git a/src/boards/pca10100/board.h b/src/boards/pca10100/board.h index 4e7dfbe..d82e2d1 100644 --- a/src/boards/pca10100/board.h +++ b/src/boards/pca10100/board.h @@ -41,19 +41,15 @@ #define BUTTON_2 12 #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - -// Used as model string in OTA mode +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ #define BLEDIS_MANUFACTURER "Nordic" #define BLEDIS_MODEL "PCA10100" +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ #define UF2_PRODUCT_NAME "Nordic nRF52833 DK" #define UF2_BOARD_ID "nRF52833-pca10100-v1" #define UF2_INDEX_URL "https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52833-DK" diff --git a/src/boards/raytac_mdbt50q_rx/board.h b/src/boards/raytac_mdbt50q_rx/board.h index fb4bdef..18b7c90 100644 --- a/src/boards/raytac_mdbt50q_rx/board.h +++ b/src/boards/raytac_mdbt50q_rx/board.h @@ -43,15 +43,6 @@ #define BUTTON_2 _PINNUM(0, 10) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ diff --git a/src/boards/waveshare_nrf52840_eval/board.h b/src/boards/waveshare_nrf52840_eval/board.h index d4f0efc..27991df 100644 --- a/src/boards/waveshare_nrf52840_eval/board.h +++ b/src/boards/waveshare_nrf52840_eval/board.h @@ -50,15 +50,6 @@ #define BUTTON_2 _PINNUM(0, 29) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ From 2128d60cc92da0342aba8a177a9de4087e500a5e Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Mar 2020 18:39:39 +0700 Subject: [PATCH 22/26] enable most warning option, fix all warnings --- Makefile | 20 ++++++++++++++----- .../bootloader_dfu/dfu_transport_ble.c | 2 +- src/boards.c | 2 +- src/nrfx_config.h | 10 +++++++++- src/sdk_config.h | 2 ++ src/usb/uf2/ghostfat.c | 5 +---- 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 0c11ef5..f9349d1 100644 --- a/Makefile +++ b/Makefile @@ -52,9 +52,9 @@ RM = rm -rf BMP_PORT ?= $(shell ls -1 /dev/cu.usbmodem????????1 | head -1) GDB_BMP = $(GDB) -ex 'target extended-remote $(BMP_PORT)' -ex 'monitor swdp_scan' -ex 'attach 1' -#********************************* +#--------------------------------- # Select the board to build -#********************************* +#--------------------------------- BOARD_LIST = $(sort $(subst src/boards/,,$(wildcard src/boards/*))) ifeq ($(filter $(BOARD),$(BOARD_LIST)),) @@ -125,6 +125,7 @@ C_SRC += $(SDK_PATH)/libraries/util/nrf_assert.c # UART or USB Serial ifeq ($(MCU_SUB_VARIANT),nrf52) + C_SRC += $(SDK_PATH)/libraries/uart/app_uart.c C_SRC += $(SDK_PATH)/drivers_nrf/uart/nrf_drv_uart.c C_SRC += $(SDK_PATH)/drivers_nrf/common/nrf_drv_common.c @@ -223,15 +224,24 @@ CFLAGS += \ -fstack-usage \ -fno-strict-aliasing \ -Wall \ + -Wextra \ -Werror \ -Wfatal-errors \ - -Wextra + -Werror-implicit-function-declaration \ + -Wfloat-equal \ + -Wundef \ + -Wshadow \ + -Wwrite-strings \ + -Wsign-compare \ + -Wmissing-format-attribute \ + -Wno-endif-labels \ + -Wunreachable-code # Suppress warning caused by SDK -CFLAGS += -Wno-error=unused-parameter -Wno-error=expansion-to-defined +CFLAGS += -Wno-unused-parameter -Wno-expansion-to-defined # TinyUSB tusb_hal_nrf_power_event -CFLAGS += -Wno-error=cast-function-type +CFLAGS += -Wno-cast-function-type # Defined Symbol (MACROS) CFLAGS += -D__HEAP_SIZE=0 diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c index 89c2096..d731d31 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c @@ -967,7 +967,7 @@ static void service_error_handler(uint32_t nrf_error) } -static void ascii_to_utf8(ble_srv_utf8_str_t * p_utf8, char * p_ascii) +static void ascii_to_utf8(ble_srv_utf8_str_t * p_utf8, const char * p_ascii) { p_utf8->length = (uint16_t)strlen(p_ascii); p_utf8->p_str = (uint8_t *)p_ascii; diff --git a/src/boards.c b/src/boards.c index fa68ddd..b4d7ede 100644 --- a/src/boards.c +++ b/src/boards.c @@ -295,7 +295,7 @@ void led_state(uint32_t state) } else if (temp_color_active) { final_color = (uint8_t*)&rgb_color; } - #if LED_NEOPIXEL || defined(LED_RGB_RED_PIN) + #if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN) if (final_color != NULL) { neopixel_write(final_color); } diff --git a/src/nrfx_config.h b/src/nrfx_config.h index 419dc19..b626e00 100644 --- a/src/nrfx_config.h +++ b/src/nrfx_config.h @@ -6,11 +6,19 @@ #define NRFX_POWER_DEFAULT_CONFIG_IRQ_PRIORITY 7 #define NRFX_CLOCK_ENABLED 0 - #define NRFX_NVMC_ENABLED 1 +#define NRFX_PRS_ENABLED 0 + +#define NRFX_PWM_ENABLED 0 +#define NRFX_PWM0_ENABLED 0 +#define NRFX_PWM1_ENABLED 0 +#define NRFX_PWM2_ENABLED 0 +#define NRFX_PWM3_ENABLED 0 + // UART #ifdef NRF52832_XXAA + #define NRFX_UART_ENABLED 1 #define NRFX_UART0_ENABLED 1 diff --git a/src/sdk_config.h b/src/sdk_config.h index 51d9e92..50e8196 100644 --- a/src/sdk_config.h +++ b/src/sdk_config.h @@ -78,10 +78,12 @@ #define UART_DEFAULT_CONFIG_IRQ_PRIORITY 7 #define UART_EASY_DMA_SUPPORT 1 #define UART_LEGACY_SUPPORT 1 +#define UART_CONFIG_LOG_ENABLED 0 #define UART0_ENABLED 1 #define UART0_CONFIG_USE_EASY_DMA 0 + //========================================================== // APP_UART_ENABLED - app_uart - UART driver //========================================================== diff --git a/src/usb/uf2/ghostfat.c b/src/usb/uf2/ghostfat.c index 28f1e0a..e6a2c67 100644 --- a/src/usb/uf2/ghostfat.c +++ b/src/usb/uf2/ghostfat.c @@ -311,10 +311,7 @@ int write_block(uint32_t block_no, uint8_t *data, bool quiet, WriteState *state) if ((bl->flags & UF2_FLAG_NOFLASH) || bl->payloadSize > 256 || (bl->targetAddr & 0xff) || bl->targetAddr < USER_FLASH_START || bl->targetAddr + bl->payloadSize > USER_FLASH_END) { -#if USE_DBG_MSC - if (!quiet) - logval("invalid target addr", bl->targetAddr); -#endif + NRF_LOG_WARNING("Skip block at %x", bl->targetAddr); // this happens when we're trying to re-flash CURRENT.UF2 file previously // copied from a device; we still want to count these blocks to reset properly From 9ea3f08e231f04d5d41989959fa8cb240764447c Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Mar 2020 18:49:54 +0700 Subject: [PATCH 23/26] more cleanup --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f9349d1..2c11186 100644 --- a/Makefile +++ b/Makefile @@ -305,7 +305,7 @@ $(info ASFLAGS $(ASFLAGS)) $(info ) endif -.phony: all clean size flash sd erase +.PHONY: all clean size flash dfu-flash sd erase gdbflash gdb # default target to build all: $(BUILD)/$(OUT_FILE)-nosd.out size @@ -373,7 +373,7 @@ size: $(BUILD)/$(OUT_FILE)-nosd.out -@echo '' #------------------- Binary generator ------------------- -.phony: genhex genpkg +.PHONY: genhex genpkg combinehex ## Create binary .hex file from the .out file genhex: $(BUILD)/$(OUT_FILE)-nosd.hex From 1db3ffe968ae228b78df3430ba4f0a7661646dd3 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Mar 2020 19:46:08 +0700 Subject: [PATCH 24/26] remove size target, make it part of Linking --- Makefile | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 2c11186..c5491fd 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ MERGED_FILE = $(OUT_FILE)_$(SD_NAME)_$(SD_VERSION) # Toolchain commands # Should be added to your PATH -CROSS_COMPILE = arm-none-eabi- +CROSS_COMPILE ?= arm-none-eabi- CC = $(CROSS_COMPILE)gcc AS = $(CROSS_COMPILE)as OBJCOPY = $(CROSS_COMPILE)objcopy @@ -59,7 +59,7 @@ BOARD_LIST = $(sort $(subst src/boards/,,$(wildcard src/boards/*))) ifeq ($(filter $(BOARD),$(BOARD_LIST)),) $(info You must provide a BOARD parameter with 'BOARD='. Supported boards are:) - $(info $(BOARD_LIST)) + $(foreach b,$(BOARD_LIST),$(info - $(b))) $(error Invalid BOARD specified) endif @@ -305,10 +305,10 @@ $(info ASFLAGS $(ASFLAGS)) $(info ) endif -.PHONY: all clean size flash dfu-flash sd erase gdbflash gdb +.PHONY: all clean flash dfu-flash sd erase gdbflash gdb # default target to build -all: $(BUILD)/$(OUT_FILE)-nosd.out size +all: $(BUILD)/$(OUT_FILE)-nosd.out $(BUILD)/$(MERGED_FILE).hex #------------------- Flash target ------------------- @@ -366,11 +366,7 @@ $(BUILD)/%.o: %.S $(BUILD)/$(OUT_FILE)-nosd.out: $(BUILD) $(OBJECTS) @echo LD $(OUT_FILE)-nosd.out @$(CC) -o $@ $(LDFLAGS) $(OBJECTS) -Wl,--start-group $(LIBS) -Wl,--end-group - -size: $(BUILD)/$(OUT_FILE)-nosd.out - -@echo '' - @$(SIZE) $< - -@echo '' + @$(SIZE) $@ #------------------- Binary generator ------------------- .PHONY: genhex genpkg combinehex From f097cae0cd12200802a07f0768b4dd8e3be2ad7c Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Mar 2020 19:58:17 +0700 Subject: [PATCH 25/26] remove combinehex and erase target update Readme --- Makefile | 10 ++-------- README.md | 37 ++++--------------------------------- tools/build_all.py | 2 +- 3 files changed, 7 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index c5491fd..cea263f 100644 --- a/Makefile +++ b/Makefile @@ -305,7 +305,7 @@ $(info ASFLAGS $(ASFLAGS)) $(info ) endif -.PHONY: all clean flash dfu-flash sd erase gdbflash gdb +.PHONY: all clean flash dfu-flash sd gdbflash gdb # default target to build all: $(BUILD)/$(OUT_FILE)-nosd.out $(BUILD)/$(MERGED_FILE).hex @@ -332,10 +332,6 @@ sd: @echo Flashing: $(SD_HEX) $(NRFJPROG) --program $(SD_HEX) -f nrf52 --chiperase --reset -erase: - @echo Erasing chip - $(NRFJPROG) --eraseall -f nrf52 - gdbflash: $(BUILD)/$(MERGED_FILE).hex @echo Flashing: $< @$(GDB_BMP) -nx --batch -ex 'load $<' -ex 'compare-sections' -ex 'kill' @@ -369,7 +365,7 @@ $(BUILD)/$(OUT_FILE)-nosd.out: $(BUILD) $(OBJECTS) @$(SIZE) $@ #------------------- Binary generator ------------------- -.PHONY: genhex genpkg combinehex +.PHONY: genhex genpkg ## Create binary .hex file from the .out file genhex: $(BUILD)/$(OUT_FILE)-nosd.hex @@ -379,8 +375,6 @@ $(BUILD)/$(OUT_FILE)-nosd.hex: $(BUILD)/$(OUT_FILE)-nosd.out @$(OBJCOPY) -O ihex $< $@ # merge bootloader and sd hex together -combinehex: $(BUILD)/$(MERGED_FILE).hex - $(BUILD)/$(MERGED_FILE).hex: $(BUILD)/$(OUT_FILE)-nosd.hex @echo CR $(MERGED_FILE).hex @mergehex -q -m $< $(SD_HEX) -o $@ diff --git a/README.md b/README.md index 1ff105d..6c65816 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,7 @@ both bootloader and the Nordic SoftDevice, you can freely upgrade/downgrade to a ## How to compile and build You should only continue if you are looking to develop bootloader for your own. -You must have have a J-Link available to "unbrick" your device. - -### Option 1: Build with Makefile +You must have have a J-Link available to "unbrick" your device. Prerequisites @@ -117,7 +115,7 @@ Prerequisites To build: ``` -make BOARD=feather_nrf52840_express all combinehex +make BOARD=feather_nrf52840_express all ``` To flash the bootloader with JLink: @@ -138,12 +136,6 @@ To flash SoftDevice (and chip erase): make BOARD=feather_nrf52840_express sd ``` -To erase all of flash: - -``` -make BOARD=feather_nrf52840_express erase -``` - For the list of supported boards, run `make` without `BOARD=` : ``` @@ -167,13 +159,11 @@ make: *** [_build/main.o] Error 127 ``` ... you may need to pass the location of the GCC ARM toolchain binaries to `make` using -the variable `GNU_INSTALL_ROOT` as below: +the variable `CROSS_COMPILE` as below: ``` -$ make GNU_INSTALL_ROOT=/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/ BOARD=feather_nrf52832 all +$ make CROSS_COMPILE=/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi- BOARD=feather_nrf52832 all ``` -_Please note that the path needs a trailing path separator (a `/`)_ - #### 2. `mergehex: No such file or directory` Make sure that `mergehex` is available from the command-line. This binary is @@ -184,22 +174,3 @@ part of Nordic's nRF5x Command Line Tools. Make sure that `nrfjprog` is available from the command-line. This binary is part of Nordic's nRF5x Command Line Tools. -On POSIX-type systems you can temporarily add the path to `nrfjprog` via a -variation on the following command: - -``` -$ export PATH=$PATH:/location/of/nRF5x-Command-Line-Tools_9_7_2_OSX/nrfjprog -``` - -### Option 2: Build using Segger Embedded Studio - -For easier debugging you can also use [SES](https://www.segger.com/products/development-tools/embedded-studio/). -The project file is located at `src/segger/Adafruit_nRF52_Bootloader.emProject`. - -> **Note**: SES only flashes the bootloader when you click download, not the SoftDevice. -You need to flash the SoftDevice beforehand if you haven't already done so. -As mentioned above do something like: - -``` -make BOARD=feather_nrf52840_express sd -``` diff --git a/tools/build_all.py b/tools/build_all.py index 0243724..24640f5 100644 --- a/tools/build_all.py +++ b/tools/build_all.py @@ -34,7 +34,7 @@ for board in all_boards: os.makedirs(bin_directory, exist_ok=True) start_time = time.monotonic() - make_result = subprocess.run("make -j 4 BOARD={} combinehex genpkg".format(board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + make_result = subprocess.run("make -j 4 BOARD={} all genpkg".format(board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) build_duration = time.monotonic() - start_time flash_size = "-" From 392f69a2c399469ebba7bc88a88bdfb062bd96f2 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Mar 2020 20:05:51 +0700 Subject: [PATCH 26/26] remove genhex target --- Makefile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index cea263f..1ff8a65 100644 --- a/Makefile +++ b/Makefile @@ -151,7 +151,6 @@ C_SRC += $(TUSB_PATH)/tusb.c endif - #------------------------------------------------------------------------------ # Assembly Files #------------------------------------------------------------------------------ @@ -256,7 +255,6 @@ CFLAGS += -DBLEDIS_FW_VERSION='"$(GIT_VERSION) $(SD_NAME) $(SD_VERSION)"' _VER = $(subst ., ,$(word 1, $(subst -, ,$(GIT_VERSION)))) CFLAGS += -DMK_BOOTLOADER_VERSION='($(word 1,$(_VER)) << 16) + ($(word 2,$(_VER)) << 8) + $(word 3,$(_VER))' - #------------------------------------------------------------------------------ # Linker Flags #------------------------------------------------------------------------------ @@ -365,11 +363,8 @@ $(BUILD)/$(OUT_FILE)-nosd.out: $(BUILD) $(OBJECTS) @$(SIZE) $@ #------------------- Binary generator ------------------- -.PHONY: genhex genpkg ## Create binary .hex file from the .out file -genhex: $(BUILD)/$(OUT_FILE)-nosd.hex - $(BUILD)/$(OUT_FILE)-nosd.hex: $(BUILD)/$(OUT_FILE)-nosd.out @echo CR $(OUT_FILE)-nosd.hex @$(OBJCOPY) -O ihex $< $@ @@ -379,7 +374,8 @@ $(BUILD)/$(MERGED_FILE).hex: $(BUILD)/$(OUT_FILE)-nosd.hex @echo CR $(MERGED_FILE).hex @mergehex -q -m $< $(SD_HEX) -o $@ -## Create pkg file for bootloader+SD combo to use with DFU +## Create pkg zip file for bootloader+SD combo to use with DFU Serial +.PHONY: genpkg genpkg: $(BUILD)/$(MERGED_FILE).zip $(BUILD)/$(MERGED_FILE).zip: $(BUILD)/$(OUT_FILE)-nosd.hex