From 6c0bb9d8ecfe4009457868653da3a76355330f35 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 12 Jul 2022 20:40:57 +0700 Subject: [PATCH 1/6] clean up makefile - rename target sd -> flash-sd, mbr -> flash-mbr, dfu-flash -> flash-dfu - update readme - clean up python script, add multiprocess build --- Makefile | 102 ++++++++++++++++++---------------- README.md | 52 +++++++++-------- tools/build_all.py | 91 ++++++++++++++---------------- tools/github_requests.py | 76 ------------------------- tools/upload_release_files.py | 34 ------------ 5 files changed, 126 insertions(+), 229 deletions(-) delete mode 100644 tools/github_requests.py delete mode 100755 tools/upload_release_files.py diff --git a/Makefile b/Makefile index 9ea2c887..0a983579 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ # - SD_HEX : to bootloader hex binary #------------------------------------------------------------------------------ +# local customization -include Makefile.user SDK_PATH = lib/sdk/components @@ -37,7 +38,7 @@ OUT_NAME = $(BOARD)_bootloader-$(GIT_VERSION) MERGED_FILE = $(OUT_NAME)_$(SD_NAME)_$(SD_VERSION) #------------------------------------------------------------------------------ -# Tool configure +# Tool Configure #------------------------------------------------------------------------------ # Toolchain commands @@ -208,39 +209,46 @@ ASM_SRC = $(NRFX_PATH)/mdk/gcc_startup_$(MCU_SUB_VARIANT).S #------------------------------------------------------------------------------ # src -IPATH += src -IPATH += src/boards -IPATH += src/boards/$(BOARD) -IPATH += src/cmsis/include -IPATH += src/usb -IPATH += $(TUSB_PATH) +IPATH += \ + src \ + src/boards \ + src/boards/$(BOARD) \ + src/cmsis/include \ + src/usb \ + $(TUSB_PATH) # nrfx -IPATH += $(NRFX_PATH) -IPATH += $(NRFX_PATH)/mdk -IPATH += $(NRFX_PATH)/hal -IPATH += $(NRFX_PATH)/drivers/include -IPATH += $(NRFX_PATH)/drivers/src - -IPATH += $(SDK11_PATH)/libraries/bootloader_dfu/hci_transport -IPATH += $(SDK11_PATH)/libraries/bootloader_dfu -IPATH += $(SDK11_PATH)/drivers_nrf/pstorage -IPATH += $(SDK11_PATH)/ble/common -IPATH += $(SDK11_PATH)/ble/ble_services/ble_dfu -IPATH += $(SDK11_PATH)/ble/ble_services/ble_dis - -IPATH += $(SDK_PATH)/libraries/timer -IPATH += $(SDK_PATH)/libraries/scheduler -IPATH += $(SDK_PATH)/libraries/crc16 -IPATH += $(SDK_PATH)/libraries/util -IPATH += $(SDK_PATH)/libraries/hci/config -IPATH += $(SDK_PATH)/libraries/uart -IPATH += $(SDK_PATH)/libraries/hci -IPATH += $(SDK_PATH)/drivers_nrf/delay - -# Softdevice -IPATH += $(SD_PATH)/$(SD_FILENAME)_API/include -IPATH += $(SD_PATH)/$(SD_FILENAME)_API/include/nrf52 +IPATH += \ + $(NRFX_PATH) \ + $(NRFX_PATH)/mdk \ + $(NRFX_PATH)/hal \ + $(NRFX_PATH)/drivers/include \ + $(NRFX_PATH)/drivers/src + +# sdk11 for cdc/ble dfu +IPATH += \ + $(SDK11_PATH)/libraries/bootloader_dfu/hci_transport \ + $(SDK11_PATH)/libraries/bootloader_dfu \ + $(SDK11_PATH)/drivers_nrf/pstorage \ + $(SDK11_PATH)/ble/common \ + $(SDK11_PATH)/ble/ble_services/ble_dfu \ + $(SDK11_PATH)/ble/ble_services/ble_dis + +# later sdk with updated drivers +IPATH += \ + $(SDK_PATH)/libraries/timer \ + $(SDK_PATH)/libraries/scheduler \ + $(SDK_PATH)/libraries/crc16 \ + $(SDK_PATH)/libraries/util \ + $(SDK_PATH)/libraries/hci/config \ + $(SDK_PATH)/libraries/uart \ + $(SDK_PATH)/libraries/hci \ + $(SDK_PATH)/drivers_nrf/delay + +# SoftDevice +IPATH += \ + $(SD_PATH)/$(SD_FILENAME)_API/include \ + $(SD_PATH)/$(SD_FILENAME)_API/include/nrf52 #------------------------------------------------------------------------------ # Compiler Flags @@ -278,9 +286,6 @@ CFLAGS += \ # Suppress warning caused by SDK CFLAGS += -Wno-unused-parameter -Wno-expansion-to-defined -# TinyUSB tusb_hal_nrf_power_event -CFLAGS += -Wno-cast-function-type - # Nordic Softdevice SDK header files contains inline assembler that has # broken constraints. As a result the IPA-modref pass, introduced in gcc-11, # is able to "prove" that arguments to wrapper functions generated with @@ -332,6 +337,7 @@ LIBS += -lm -lc #------------------------------------------------------------------------------ # Assembler flags #------------------------------------------------------------------------------ + ASFLAGS += $(CFLAGS) #function for removing duplicates in a list @@ -356,7 +362,7 @@ INC_PATHS = $(addprefix -I,$(IPATH)) # BUILD TARGETS #------------------------------------------------------------------------------ -.PHONY: all clean flash dfu-flash sd gdbflash gdb +.PHONY: all clean flash dfu-flash flash-dfu flash-sd flash-mbr gdbflash gdb # default target to build all: $(BUILD)/$(OUT_NAME).out $(BUILD)/$(OUT_NAME)_nosd.hex $(BUILD)/update-$(OUT_NAME)_nosd.uf2 $(BUILD)/$(MERGED_FILE).hex $(BUILD)/$(MERGED_FILE).zip @@ -431,7 +437,9 @@ copy-artifact: $(BIN) @$(CP) $(BUILD)/$(MERGED_FILE).hex $(BIN) @$(CP) $(BUILD)/$(MERGED_FILE).zip $(BIN) -#------------------- Flash target ------------------- +#-------------------------------------- +# Flash Target +#-------------------------------------- check_defined = \ $(strip $(foreach 1,$1, \ @@ -440,29 +448,29 @@ __check_defined = \ $(if $(value $1),, \ $(error Undefined make flag: $1$(if $2, ($2)))) +# erase chip +erase: + @echo Erasing flash + $(call FLASH_ERASE_CMD) + # Flash the compiled flash: $(BUILD)/$(OUT_NAME)_nosd.hex @echo Flashing: $(notdir $<) $(call FLASH_CMD,$<) -erase: - @echo Erasing flash - $(call FLASH_ERASE_CMD) - # flash SD only -sd: +flash-sd: @echo Flashing: $(SD_HEX) $(call FLASH_NOUICR_CMD,$(SD_HEX)) # flash MBR only -mbr: +flash-mbr: @echo Flashing: $(MBR_HEX) $(call FLASH_NOUICR_CMD,$(MBR_HEX)) -#------------------- Flash with NRFUTIL via DFU ------------------- - -# dfu using CDC interface -dfu-flash: $(BUILD)/$(MERGED_FILE).zip +# dfu with adafruit-nrfutil using CDC interface +dfu-flash: flash-dfu +flash-dfu: $(BUILD)/$(MERGED_FILE).zip @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0) $(NRFUTIL) --verbose dfu serial --package $< -p $(SERIAL) -b 115200 --singlebank --touch 1200 diff --git a/README.md b/README.md index da93af1c..e62d146e 100644 --- a/README.md +++ b/README.md @@ -121,57 +121,62 @@ both bootloader and the Nordic SoftDevice, you can freely upgrade/downgrade to a 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. -Prerequisites +### Prerequisites - ARM GCC - -To install for macos - -```bash -brew tap ArmMbed/homebrew-formulae -brew install arm-none-eabi-gcc -brew link --overwrite arm-none-eabi-gcc # if a prior version was present -``` - - Nordic's [nRF5x Command Line Tools](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools) - [Python IntelHex](https://pypi.org/project/IntelHex/) -To build: +### Build: ``` make BOARD=feather_nrf52840_express all ``` -To flash the bootloader with JLink: +For the list of supported boards, run `make` without `BOARD=` : + +``` +$ make +You must provide a BOARD parameter with 'BOARD=' +Supported boards are: feather_nrf52840_express feather_nrf52840_express pca10056 +Makefile:90: *** BOARD not defined. Stop +``` + +### Flash + +To flash the bootloader (without softdevice/mbr) using JLink: ``` make BOARD=feather_nrf52840_express flash ``` +If you are using pyocd as debugger, add `FLASHER=pyocd` to make command: + +``` +make BOARD=feather_nrf52840_express FLASHER=pyocd flash +``` + To upgrade the bootloader using DFU Serial via port /dev/ttyACM0 ``` -make BOARD=feather_nrf52840_express SERIAL=/dev/ttyACM0 dfu-flash +make BOARD=feather_nrf52840_express SERIAL=/dev/ttyACM0 flash-dfu ``` -To flash SoftDevice (and chip erase): +To flash SoftDevice (will also erase chip): ``` -make BOARD=feather_nrf52840_express sd +make BOARD=feather_nrf52840_express flash-sd ``` -For the list of supported boards, run `make` without `BOARD=` : +To flash MBR only ``` -$ make -You must provide a BOARD parameter with 'BOARD=' -Supported boards are: feather_nrf52840_express feather_nrf52840_express pca10056 -Makefile:90: *** BOARD not defined. Stop +make BOARD=feather_nrf52840_express flash-mbr ``` ### Common makefile problems -#### 1. `arm-none-eabi-gcc`: No such file or directory +#### `arm-none-eabi-gcc`: No such file or directory If you get the following error ... @@ -190,7 +195,7 @@ $ make CROSS_COMPILE=/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi- B For other compile errors, check the gcc version with `arm-none-eabi-gcc --version` to insure it is at least 9.x. -#### 2. `ModuleNotFoundError: No module named 'intelhex'` +#### `ModuleNotFoundError: No module named 'intelhex'` Install python-intelhex with @@ -198,8 +203,7 @@ Install python-intelhex with pip install intelhex ``` - -#### 3. `make: nrfjprog: No such file or directory` +#### `make: nrfjprog: No such file or directory` Make sure that `nrfjprog` is available from the command-line. This binary is part of Nordic's nRF5x Command Line Tools. diff --git a/tools/build_all.py b/tools/build_all.py index 0df69a3b..996823bc 100644 --- a/tools/build_all.py +++ b/tools/build_all.py @@ -1,78 +1,73 @@ import os -import shutil import glob import sys import subprocess import time - -subprocess.run("rm -rf _build/", shell=True) -subprocess.run("rm -rf bin/", shell=True) +from multiprocessing import Pool SUCCEEDED = "\033[32msucceeded\033[0m" FAILED = "\033[31mfailed\033[0m" -success_count = 0 -fail_count = 0 -exit_status = 0 - build_format = '| {:32} | {:18} | {:5} | {:6} | {:6} |' build_separator = '-' * 74 -# All supported boards -all_boards = [] -for entry in os.scandir("src/boards"): - if entry.is_dir(): - 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.format('Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM')) -print(build_separator) - -for board in all_boards: - bin_directory = "bin/{}/".format(board) - os.makedirs(bin_directory, exist_ok=True) +def build_board(board): start_time = time.monotonic() - make_result = subprocess.run("make -j 4 BOARD={} all".format(board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + make_result = subprocess.run("make -j BOARD={} all".format(board), shell=True, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) build_duration = time.monotonic() - start_time flash_size = "-" sram_size = "-" + succeeded = 0 if make_result.returncode == 0: - success = SUCCEEDED - success_count += 1 - + succeeded = 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_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 = FAILED - fail_count += 1 - for entry in os.scandir("_build/build-{}".format(board)): - for extension in ["zip", "hex", "uf2"]: - if entry.name.endswith(extension): - if ("nosd" in entry.name) or ("s140" in entry.name) or ("s132" in entry.name): - shutil.copy(entry.path, bin_directory) - - print(build_format.format(board, success, "{:.2f}s".format(build_duration), flash_size, sram_size)) + print(build_format.format(board, SUCCEEDED if succeeded else FAILED, "{:.2f}s".format(build_duration), flash_size, + sram_size)) if make_result.returncode != 0: print(make_result.stdout.decode("utf-8")) -# Build Summary -total_time = time.monotonic() - total_time -print(build_separator) -print("Build Sumamary: {} {}, {} {} and took {:.2f}s".format(success_count, SUCCEEDED, fail_count, FAILED, total_time)) -print(build_separator) + return succeeded + + +if __name__ == '__main__': + # remove build folder first + subprocess.run("rm -rf _build/", shell=True) + + # All supported boards + all_boards = [] + for entry in os.scandir("src/boards"): + if entry.is_dir(): + all_boards.append(entry.name) + all_boards.sort() + + print(build_separator) + print(build_format.format('Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM')) + print(build_separator) + + success_count = 0 + total_time = time.monotonic() + + with Pool(processes=os.cpu_count()) as pool: + success_count = sum(pool.map(build_board, all_boards)) + + total_time = time.monotonic() - total_time + fail_count = len(all_boards) - success_count + + # Build Summary + print(build_separator) + print( + "Build Summary: {} {}, {} {} and took {:.2f}s".format(success_count, SUCCEEDED, fail_count, FAILED, total_time)) + print(build_separator) -sys.exit(exit_status) + sys.exit(fail_count) diff --git a/tools/github_requests.py b/tools/github_requests.py deleted file mode 100644 index 6b8e74c5..00000000 --- a/tools/github_requests.py +++ /dev/null @@ -1,76 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2017 Scott Shawcroft for Adafruit Industries -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -""" -`adafruit_adabot` -==================================================== - -TODO(description) - -* Author(s): Scott Shawcroft -""" -import os - -import requests - - -def _fix_url(url): - if url.startswith("/"): - url = "https://api.github.com" + url - return url - -def _fix_kwargs(kwargs): - api_version = "application/vnd.github.scarlet-witch-preview+json;application/vnd.github.hellcat-preview+json" - if "headers" in kwargs: - if "Accept" in kwargs["headers"]: - kwargs["headers"]["Accept"] += ";" + api_version - else: - kwargs["headers"]["Accept"] = api_version - else: - kwargs["headers"] = {"Accept": "application/vnd.github.hellcat-preview+json"} - if "ADABOT_GITHUB_ACCESS_TOKEN" in os.environ and "auth" not in kwargs: - access_token = os.environ["ADABOT_GITHUB_ACCESS_TOKEN"] - if "params" in kwargs: - kwargs["params"]["access_token"] = access_token - else: - kwargs["params"] = {"access_token": access_token} - if "timeout" not in kwargs: - kwargs["timeout"] = 30 - return kwargs - -def get(url, **kwargs): - response = requests.get(_fix_url(url), **_fix_kwargs(kwargs)) - remaining = int(response.headers["X-RateLimit-Remaining"]) - if remaining % 100 == 0: - print(remaining, "requests remaining this hour") - return response - -def post(url, **kwargs): - return requests.post(_fix_url(url), **_fix_kwargs(kwargs)) - -def put(url, **kwargs): - return requests.put(_fix_url(url), **_fix_kwargs(kwargs)) - -def patch(url, **kwargs): - return requests.patch(_fix_url(url), **_fix_kwargs(kwargs)) - -def delete(url, **kwargs): - return requests.delete(_fix_url(url), **_fix_kwargs(kwargs)) diff --git a/tools/upload_release_files.py b/tools/upload_release_files.py deleted file mode 100755 index b7ee02ca..00000000 --- a/tools/upload_release_files.py +++ /dev/null @@ -1,34 +0,0 @@ -#! /usr/bin/env python3 - -import os -import os.path -import sys -import uritemplate -import glob - -sys.path.append("adabot") -import github_requests as github - -exit_status = 0 - -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 0811a477aeacf55014a427e05b660093fac33799 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 12 Jul 2022 23:37:04 +0700 Subject: [PATCH 2/6] fix -Wcast-function-type warnings --- Makefile | 4 ++-- src/main.c | 7 +++++-- src/usb/usb.c | 12 ++++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 0a983579..d680e6bd 100644 --- a/Makefile +++ b/Makefile @@ -261,6 +261,7 @@ CFLAGS += \ -mcpu=cortex-m4 \ -mfloat-abi=hard \ -mfpu=fpv4-sp-d16 \ + -ggdb \ -Os \ -ffunction-sections \ -fdata-sections \ @@ -280,8 +281,7 @@ CFLAGS += \ -Wsign-compare \ -Wmissing-format-attribute \ -Wno-endif-labels \ - -Wunreachable-code \ - -ggdb + -Wunreachable-code # Suppress warning caused by SDK CFLAGS += -Wno-unused-parameter -Wno-expansion-to-defined diff --git a/src/main.c b/src/main.c index 8cbe93f1..47d290e4 100644 --- a/src/main.c +++ b/src/main.c @@ -76,6 +76,10 @@ void usb_init(bool cdc_only); void usb_teardown(void); +// tinyusb function that handles power event (detected, ready, removed) +// We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. +extern void tusb_hal_nrf_power_event(uint32_t event); + #else #define usb_init(x) led_state(STATE_USB_MOUNTED) // mark nrf52832 as mounted @@ -474,13 +478,12 @@ uint32_t proc_soc(void) pstorage_sys_event_handler(soc_evt); #ifdef NRF_USBD - extern void tusb_hal_nrf_power_event(uint32_t event); /*------------- usb power event handler -------------*/ int32_t usbevt = (soc_evt == NRF_EVT_POWER_USB_DETECTED ) ? NRFX_POWER_USB_EVT_DETECTED: (soc_evt == NRF_EVT_POWER_USB_POWER_READY) ? NRFX_POWER_USB_EVT_READY : (soc_evt == NRF_EVT_POWER_USB_REMOVED ) ? NRFX_POWER_USB_EVT_REMOVED : -1; - if ( usbevt >= 0) tusb_hal_nrf_power_event(usbevt); + if ( usbevt >= 0) tusb_hal_nrf_power_event((uint32_t) usbevt); #endif } diff --git a/src/usb/usb.c b/src/usb/usb.c index 6a48483f..6cbfa76d 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -42,9 +42,13 @@ * We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. */ extern void tusb_hal_nrf_power_event(uint32_t event); -//--------------------------------------------------------------------+ +// power callback when SD is not enabled +static void power_event_handler(nrfx_power_usb_evt_t event) +{ + tusb_hal_nrf_power_event((uint32_t) event); +} + // Forward USB interrupt events to TinyUSB IRQ Handler -//--------------------------------------------------------------------+ void USBD_IRQHandler(void) { tud_int_handler(0); @@ -80,8 +84,8 @@ void usb_init(bool cdc_only) const nrfx_power_config_t pwr_cfg = { 0 }; nrfx_power_init(&pwr_cfg); - // Register tusb function as USB power handler - const nrfx_power_usbevt_config_t config = { .handler = (nrfx_power_usb_event_handler_t) tusb_hal_nrf_power_event }; + // Register USB power handler + const nrfx_power_usbevt_config_t config = { .handler = power_event_handler }; nrfx_power_usbevt_init(&config); nrfx_power_usbevt_enable(); From dbeaafa7b509b50f497f7d2e751aaa5bfcae19ea Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 13 Jul 2022 01:04:54 +0700 Subject: [PATCH 3/6] added feather 833 --- .github/workflows/githubci.yml | 1 + Makefile | 3 +- linker/nrf52833.ld | 9 ++- src/boards/feather_nrf52833_express/board.h | 69 +++++++++++++++++++ src/boards/feather_nrf52833_express/board.mk | 2 + .../feather_nrf52833_express/pinconfig.c | 19 +++++ src/boards/feather_nrf52840_express/board.h | 2 +- 7 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 src/boards/feather_nrf52833_express/board.h create mode 100644 src/boards/feather_nrf52833_express/board.mk create mode 100644 src/boards/feather_nrf52833_express/pinconfig.c diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml index 338c5ccb..7644c7c8 100644 --- a/.github/workflows/githubci.yml +++ b/.github/workflows/githubci.yml @@ -19,6 +19,7 @@ jobs: - 'circuitplayground_nrf52840' - 'clue_nrf52840' - 'feather_nrf52832' + - 'feather_nrf52833_express' - 'feather_nrf52840_express' - 'feather_nrf52840_sense' - 'itsybitsy_nrf52840_express' diff --git a/Makefile b/Makefile index d680e6bd..63d5556d 100644 --- a/Makefile +++ b/Makefile @@ -16,8 +16,9 @@ TUSB_PATH = lib/tinyusb/src NRFX_PATH = lib/nrfx SD_PATH = lib/softdevice/$(SD_FILENAME) +# SD_VERSION can be overwritten by board.mk ifndef SD_VERSION - SD_VERSION = 6.1.1 +SD_VERSION = 6.1.1 endif SD_FILENAME = $(SD_NAME)_nrf52_$(SD_VERSION) diff --git a/linker/nrf52833.ld b/linker/nrf52833.ld index 46a23dca..49d8350f 100644 --- a/linker/nrf52833.ld +++ b/linker/nrf52833.ld @@ -11,7 +11,9 @@ MEMORY * those values do not match. The check is performed in main.c, see * APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); */ - FLASH (rx) : ORIGIN = 0x74000, LENGTH = 0x7E000-0x74000 /* 40 KB */ + FLASH (rx) : ORIGIN = 0x74000, LENGTH = 0x7E000-0x74000-2K /* 38 KB */ + + BOOTLOADER_CONFIG (r): ORIGIN = 0x7E000 - 2K, LENGTH = 2K /** Location of mbr params page in flash. */ MBR_PARAMS_PAGE (rw) : ORIGIN = 0x0007E000, LENGTH = 0x1000 @@ -50,6 +52,11 @@ SECTIONS PROVIDE( __stop_fs_data = .); } = 0 + .bootloaderConfig : + { + KEEP(*(.bootloaderConfig)) + } > BOOTLOADER_CONFIG + /* Place the bootloader settings page in flash. */ .bootloaderSettings(NOLOAD) : { diff --git a/src/boards/feather_nrf52833_express/board.h b/src/boards/feather_nrf52833_express/board.h new file mode 100644 index 00000000..af0e1ec4 --- /dev/null +++ b/src/boards/feather_nrf52833_express/board.h @@ -0,0 +1,69 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _FEATHER_NRF52833_H +#define _FEATHER_NRF52833_H + +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN _PINNUM(1, 15) +#define LED_SECONDARY_PIN _PINNUM(1, 10) +#define LED_STATE_ON 1 + +#define LED_NEOPIXEL _PINNUM(0, 16) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTONS_NUMBER 2 +#define BUTTON_1 _PINNUM(1, 02) +#define BUTTON_2 _PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "Feather nRF52833 Express" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0029 // TODO change later +#define USB_DESC_CDC_ONLY_PID 0x002A // TODO change later + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "Adafruit Feather nRF52833 Express" +#define UF2_VOLUME_LABEL "FTHR833BOOT" +#define UF2_BOARD_ID "nRF52833-Feather-revD" +#define UF2_INDEX_URL "https://www.adafruit.com/product/4062" // TODO change later + +#endif diff --git a/src/boards/feather_nrf52833_express/board.mk b/src/boards/feather_nrf52833_express/board.mk new file mode 100644 index 00000000..3c43fdfc --- /dev/null +++ b/src/boards/feather_nrf52833_express/board.mk @@ -0,0 +1,2 @@ +MCU_SUB_VARIANT = nrf52833 +SD_VERSION = 7.2.0 \ No newline at end of file diff --git a/src/boards/feather_nrf52833_express/pinconfig.c b/src/boards/feather_nrf52833_express/pinconfig.c new file mode 100644 index 00000000..72308c4a --- /dev/null +++ b/src/boards/feather_nrf52833_express/pinconfig.c @@ -0,0 +1,19 @@ +#include "boards.h" +#include "uf2/configkeys.h" + +__attribute__((used, section(".bootloaderConfig"))) +const uint32_t bootloaderConfig[] = +{ + /* CF2 START */ + CFG_MAGIC0, CFG_MAGIC1, // magic + 5, 100, // used entries, total entries + + 204, 0x80000, // FLASH_BYTES + 205, 0x20000, // RAM_BYTES + 208, (USB_DESC_VID << 16) | USB_DESC_UF2_PID, // BOOTLOADER_BOARD_ID = USB VID+PID, used for verification when updating bootloader via uf2 + 209, 0x621e937a, // UF2_FAMILY + 210, 0x20, // PINS_PORT_SIZE = PA_32 + + 0, 0, 0, 0, 0, 0, 0, 0 + /* CF2 END */ +}; diff --git a/src/boards/feather_nrf52840_express/board.h b/src/boards/feather_nrf52840_express/board.h index 2477ea4e..3be5593b 100644 --- a/src/boards/feather_nrf52840_express/board.h +++ b/src/boards/feather_nrf52840_express/board.h @@ -35,7 +35,7 @@ #define LED_SECONDARY_PIN _PINNUM(1, 10) #define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(0, 16) +#define LED_NEOPIXEL _PINNUM(0, 16) #define NEOPIXELS_NUMBER 1 #define BOARD_RGB_BRIGHTNESS 0x040404 From cda1798d702a32bc576308839ed7e031b1ebe059 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 13 Jul 2022 12:00:11 +0700 Subject: [PATCH 4/6] clean up --- src/usb/uf2/uf2cfg.h | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/usb/uf2/uf2cfg.h b/src/usb/uf2/uf2cfg.h index b4cdb7ca..a6382e3b 100644 --- a/src/usb/uf2/uf2cfg.h +++ b/src/usb/uf2/uf2cfg.h @@ -1,32 +1,29 @@ #include "boards.h" #include "dfu_types.h" -// Family ID for updating generic Application -#if defined(NRF52833_XXAA) - #define CFG_UF2_FAMILY_APP_ID 0x621E937A -#elif defined(NRF52840_XXAA) - #define CFG_UF2_FAMILY_APP_ID 0xADA52840 -#endif +// Virtual disk size: just under 32MB +#define CFG_UF2_NUM_BLOCKS 0x10109 + +// Family ID for updating Bootloader +#define CFG_UF2_FAMILY_BOOT_ID 0xd663823c // Board-specific ID for board-specific Application #if defined(USB_DESC_VID) && defined(USB_DESC_UF2_PID) && USB_DESC_VID && USB_DESC_UF2_PID #define CFG_UF2_BOARD_APP_ID ((USB_DESC_VID << 16) | USB_DESC_UF2_PID) #endif - -// Family ID for updating Bootloader -#define CFG_UF2_FAMILY_BOOT_ID 0xd663823c - -#define CFG_UF2_NUM_BLOCKS 0x10109 // just under 32MB +// Family ID and size for updating generic Application #if defined(NRF52833_XXAA) - #define CFG_UF2_FLASH_SIZE 0x80000 // 512 kB -#else - #define CFG_UF2_FLASH_SIZE (1024*1024) // 1 MB + #define CFG_UF2_FAMILY_APP_ID 0x621E937A + #define CFG_UF2_FLASH_SIZE (512*1024) // 512 kB +#elif defined(NRF52840_XXAA) + #define CFG_UF2_FAMILY_APP_ID 0xADA52840 + #define CFG_UF2_FLASH_SIZE (1024*1024) // 1 MB #endif // Application Address Space -#define USER_FLASH_START MBR_SIZE // skip MBR included in SD hex -#define USER_FLASH_END (BOOTLOADER_REGION_START - DFU_APP_DATA_RESERVED) +#define USER_FLASH_START MBR_SIZE // skip MBR included in SD hex +#define USER_FLASH_END (BOOTLOADER_REGION_START - DFU_APP_DATA_RESERVED) // Bootloader start address #define BOOTLOADER_ADDR_START BOOTLOADER_REGION_START From c9a548f0c8d3c2bbc243456e29e79e765501d365 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 13 Jul 2022 12:01:53 +0700 Subject: [PATCH 5/6] more clean up --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 63d5556d..a698aaab 100644 --- a/Makefile +++ b/Makefile @@ -363,7 +363,7 @@ INC_PATHS = $(addprefix -I,$(IPATH)) # BUILD TARGETS #------------------------------------------------------------------------------ -.PHONY: all clean flash dfu-flash flash-dfu flash-sd flash-mbr gdbflash gdb +.PHONY: all clean flash flash-dfu flash-sd flash-mbr dfu-flash sd mbr gdbflash gdb # default target to build all: $(BUILD)/$(OUT_NAME).out $(BUILD)/$(OUT_NAME)_nosd.hex $(BUILD)/update-$(OUT_NAME)_nosd.uf2 $(BUILD)/$(MERGED_FILE).hex $(BUILD)/$(MERGED_FILE).zip @@ -460,11 +460,13 @@ flash: $(BUILD)/$(OUT_NAME)_nosd.hex $(call FLASH_CMD,$<) # flash SD only +sd: flash-sd flash-sd: @echo Flashing: $(SD_HEX) $(call FLASH_NOUICR_CMD,$(SD_HEX)) # flash MBR only +mbr: flash-mbr flash-mbr: @echo Flashing: $(MBR_HEX) $(call FLASH_NOUICR_CMD,$(MBR_HEX)) From 90c856e9bfa97a2aa3b7a6dcee9055df455a56fc Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 13 Jul 2022 12:11:01 +0700 Subject: [PATCH 6/6] fix build with 832 --- src/main.c | 3 +-- src/usb/uf2/uf2cfg.h | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index 47d290e4..47386ca8 100644 --- a/src/main.c +++ b/src/main.c @@ -61,15 +61,14 @@ #include "nrf_error.h" #include "boards.h" -#include "uf2/uf2.h" #include "pstorage_platform.h" #include "nrf_mbr.h" #include "pstorage.h" #include "nrfx_nvmc.h" - #ifdef NRF_USBD +#include "uf2/uf2.h" #include "nrf_usbd.h" #include "tusb.h" diff --git a/src/usb/uf2/uf2cfg.h b/src/usb/uf2/uf2cfg.h index a6382e3b..e5a63988 100644 --- a/src/usb/uf2/uf2cfg.h +++ b/src/usb/uf2/uf2cfg.h @@ -13,12 +13,12 @@ #endif // Family ID and size for updating generic Application -#if defined(NRF52833_XXAA) - #define CFG_UF2_FAMILY_APP_ID 0x621E937A - #define CFG_UF2_FLASH_SIZE (512*1024) // 512 kB -#elif defined(NRF52840_XXAA) +#if defined(NRF52840_XXAA) #define CFG_UF2_FAMILY_APP_ID 0xADA52840 #define CFG_UF2_FLASH_SIZE (1024*1024) // 1 MB +#elif defined(NRF52833_XXAA) + #define CFG_UF2_FAMILY_APP_ID 0x621E937A + #define CFG_UF2_FLASH_SIZE (512*1024) // 512 kB #endif // Application Address Space