diff --git a/.gitmodules b/.gitmodules index bd80adc..f8d4023 100644 --- a/.gitmodules +++ b/.gitmodules @@ -8,3 +8,6 @@ path = lib/uf2 url = https://github.com/microsoft/uf2.git +[submodule "lib/tinycrypt"] + path = lib/tinycrypt + url = https://github.com/intel/tinycrypt diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..4df910e --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,25 @@ +# Agent Instructions + +## Style +- Follow the repo `.clang-format` when making changes. + +## Build / Verify +- Prefer CMake for testing/verification. +- Always build both boards during verification: + - `feather_nrf52832` + - `feather_nrf52840_express` + +### CMake (preferred) +```bash +cmake -S . -B cmake-build-feather_nrf52832 -DBOARD=feather_nrf52832 +cmake --build cmake-build-feather_nrf52832 + +cmake -S . -B cmake-build-feather_nrf52840_express -DBOARD=feather_nrf52840_express +cmake --build cmake-build-feather_nrf52840_express +``` + +### Make (alternate) +```bash +make BOARD=feather_nrf52832 all +make BOARD=feather_nrf52840_express all +``` diff --git a/CMakeLists.txt b/CMakeLists.txt index 401acc2..1e17d10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,14 @@ set(SDK_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/sdk/components) set(SOFTDEVICE_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/softdevice) set(MBR_HEX ${SOFTDEVICE_DIR}/mbr/hex/mbr_nrf52_2.4.1_mbr.hex) set(TINYUSB_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/tinyusb/src) +set(TCRYPT_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/tinycrypt/lib) + +option(DEFAULT_TO_OTA_DFU "Default to OTA DFU instead of Serial DFU" OFF) +option(SIGNED_FW "Enable signed firmware verification" OFF) +option(DUALBANK_FW "Enable dual bank DFU support" OFF) +option(FORCE_UF2 "Force UF2 support even with SIGNED_FW" OFF) +set(SIGNED_FW_QX "" CACHE STRING "Public key Qx (comma-separated bytes)") +set(SIGNED_FW_QY "" CACHE STRING "Public key Qy (comma-separated bytes)") set(UF2CONV_PY ${CMAKE_CURRENT_LIST_DIR}/lib/uf2/utils/uf2conv.py) set(UF2_FAMILY_ID_BOOTLOADER 0xd663823c) @@ -58,7 +66,6 @@ add_executable(bootloader ${SDK11_DIR}/libraries/bootloader_dfu/bootloader_util.c ${SDK11_DIR}/libraries/bootloader_dfu/dfu_transport_serial.c ${SDK11_DIR}/libraries/bootloader_dfu/dfu_transport_ble.c - ${SDK11_DIR}/libraries/bootloader_dfu/dfu_single_bank.c ${SDK11_DIR}/ble/ble_services/ble_dfu/ble_dfu.c ${SDK11_DIR}/ble/ble_services/ble_dis/ble_dis.c ${SDK11_DIR}/drivers_nrf/pstorage/pstorage_raw.c @@ -75,6 +82,30 @@ add_executable(bootloader # startup ${NRFX_DIR}/mdk/gcc_startup_${MCU_VARIANT}.S ) + +if (DUALBANK_FW) + target_sources(bootloader PUBLIC + ${SDK11_DIR}/libraries/bootloader_dfu/dfu_dual_bank.c + ) +else () + target_sources(bootloader PUBLIC + ${SDK11_DIR}/libraries/bootloader_dfu/dfu_single_bank.c + ) +endif () + +if (SIGNED_FW) + target_sources(bootloader PUBLIC + ${TCRYPT_DIR}/source/sha256.c + ${TCRYPT_DIR}/source/ecc.c + ${TCRYPT_DIR}/source/ecc_dsa.c + ${TCRYPT_DIR}/source/utils.c + ) + + target_include_directories(bootloader PUBLIC + ${TCRYPT_DIR}/include + ) +endif () + target_include_directories(bootloader PUBLIC src src/boards @@ -149,6 +180,27 @@ target_compile_definitions(bootloader PUBLIC __STARTUP_CLEAR_BSS ) +if (SIGNED_FW) + if (SIGNED_FW_QX STREQUAL "" OR SIGNED_FW_QY STREQUAL "") + message(FATAL_ERROR "SIGNED_FW requires SIGNED_FW_QX and SIGNED_FW_QY to be set") + endif () + string(REPLACE " " "" SIGNED_FW_QX_STR "${SIGNED_FW_QX}") + string(REPLACE " " "" SIGNED_FW_QY_STR "${SIGNED_FW_QY}") + target_compile_definitions(bootloader PUBLIC + SIGNED_FW + "SIGNED_FW_QX=${SIGNED_FW_QX_STR}" + "SIGNED_FW_QY=${SIGNED_FW_QY_STR}" + ) +endif () + +if (FORCE_UF2) + target_compile_definitions(bootloader PUBLIC FORCE_UF2) +endif () + +if (DEFAULT_TO_OTA_DFU) + target_compile_definitions(bootloader PUBLIC DEFAULT_TO_OTA_DFU) +endif () + if (TRACE_ETM STREQUAL "1") # ENABLE_TRACE will cause system_nrf5x.c to set up ETM trace target_compile_definitions(bootloader PUBLIC ENABLE_TRACE) diff --git a/Makefile b/Makefile index 5af9ac4..5866d15 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,20 @@ #------------------------------------------------------------------------------ # CONFIGURE -# - SDK_PATH : path to SDK directory +# - SDK_PATH : path to SDK directory # -# - SD_NAME : e.g s132, s140 -# - SD_VERSION : SoftDevice version e.g 6.0.0 -# - SD_HEX : to bootloader hex binary +# - SD_NAME : e.g s132, s140 +# - SD_VERSION : SoftDevice version e.g 6.0.0 +# - SD_HEX : to bootloader hex binary +# - SIGNED_FW : if bootloader will ONLY accept signed firmware +# - SIGNED_FW_QX : Qx for signed firmware verification +# - SIGNED_FW_QY : Qy for signed firmware verification +# - DUALBANK_FW : If bootloader will implement a dual bank feature to allow autorecover from failed +# - FORCE_UF2 : if SIGNED_FW is 1, will force to include UF2 support (UNSECURE, UF2 does NOT validate signature!) +# - DEFAULT_TO_OTA_DFU : if entering DFU, by default enter OTA DFU instead of Serial DFU #------------------------------------------------------------------------------ +PYTHON = python + # local customization -include Makefile.user @@ -16,6 +24,7 @@ SDK_PATH = lib/sdk/components SDK11_PATH = lib/sdk11/components TUSB_PATH = lib/tinyusb/src +TCRYPT_PATH = lib/tinycrypt/lib NRFX_PATH = lib/nrfx SD_PATH = lib/softdevice/$(SD_FILENAME) @@ -33,6 +42,15 @@ SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex MBR_HEX = lib/softdevice/mbr/hex/mbr_nrf52_2.4.1_mbr.hex +# Detect the operating system +# The "OS" environment variable on Windows is always "Windows_NT" +# when running under a modern shell like cmd.exe or powershell +ifeq ($(OS),Windows_NT) + NULL_DEVICE = NUL +else + NULL_DEVICE = /dev/null +endif + # linker by MCU eg. nrf52840.ld ifeq ($(DEBUG), 1) LD_FILE = linker/$(MCU_SUB_VARIANT)_debug.ld @@ -149,6 +167,15 @@ C_SRC += \ src/screen.c \ src/images.c \ +# if using a signed firmware +ifeq ($(SIGNED_FW), 1) +C_SRC += \ + $(TCRYPT_PATH)/source/sha256.c \ + $(TCRYPT_PATH)/source/ecc.c \ + $(TCRYPT_PATH)/source/ecc_dsa.c \ + $(TCRYPT_PATH)/source/utils.c +endif + # all files in boards C_SRC += src/boards/boards.c @@ -163,7 +190,11 @@ 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 +ifeq ($(DUALBANK_FW), 1) +C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_dual_bank.c +else C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_single_bank.c +endif 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 @@ -197,10 +228,10 @@ C_SRC += src/boards/$(BOARD)/pinconfig.c # USB Application ( MSC + UF2 ) C_SRC += \ - src/usb/msc_uf2.c \ src/usb/usb_desc.c \ - src/usb/usb.c \ - src/usb/uf2/ghostfat.c + src/usb/msc_uf2.c \ + src/usb/uf2/ghostfat.c \ + src/usb/usb.c # TinyUSB stack C_SRC += \ @@ -211,9 +242,9 @@ C_SRC += \ $(TUSB_PATH)/class/cdc/cdc_device.c \ $(TUSB_PATH)/class/msc/msc_device.c \ $(TUSB_PATH)/tusb.c - endif + #------------------------------------------------------------------------------ # Assembly Files #------------------------------------------------------------------------------ @@ -232,6 +263,11 @@ IPATH += \ src/usb \ $(TUSB_PATH) +ifeq ($(SIGNED_FW), 1) +IPATH += \ + $(TCRYPT_PATH)/include +endif + # nrfx IPATH += \ $(NRFX_PATH) \ @@ -326,6 +362,20 @@ CFLAGS += -DSOFTDEVICE_PRESENT CFLAGS += -DUF2_VERSION='"$(GIT_VERSION)"' CFLAGS += -DBLEDIS_FW_VERSION='"$(GIT_VERSION) $(SD_NAME) $(SD_VERSION)"' +ifeq ($(SIGNED_FW), 1) +CFLAGS += -DSIGNED_FW +CFLAGS += -DSIGNED_FW_QX='$(SIGNED_FW_QX)' +CFLAGS += -DSIGNED_FW_QY='$(SIGNED_FW_QY)' +endif + +ifeq ($(FORCE_UF2), 1) +CFLAGS += -DFORCE_UF2 +endif + +ifeq ($(DEFAULT_TO_OTA_DFU), 1) +CFLAGS += -DDEFAULT_TO_OTA_DFU +endif + # Extract semantic version numbers (MAJOR.MINOR.PATCH) from GIT_VERSION. # Supports tags like: # v1.2.3 @@ -346,7 +396,6 @@ _VER_PAT := $(word 3,$(_VER3)) # This value is stored in the bootloader version register and must be a valid C integer constant. CFLAGS += -DMK_BOOTLOADER_VERSION='((($(_VER_MAJ)<<16)|($(_VER_MIN)<<8)|($(_VER_PAT))))' - # Debug option use RTT for printf ifeq ($(DEBUG), 1) CFLAGS += -DCFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL @@ -365,12 +414,6 @@ endif CFLAGS += -DDFU_APP_DATA_RESERVED=$(DFU_APP_DATA_RESERVED) -# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 -# Fixes for gcc version 12, 13 and 14. -ifneq (,$(filter 12.% 13.% 14.%,$(shell $(CC) -dumpversion 2>/dev/null))) - CFLAGS += --param=min-pagesize=0 -endif - #------------------------------------------------------------------------------ # Linker Flags #------------------------------------------------------------------------------ @@ -462,17 +505,17 @@ $(BUILD)/$(OUT_NAME).hex: $(BUILD)/$(OUT_NAME).out # Hex file with mbr (still no SD) $(BUILD)/$(OUT_NAME)_nosd.hex: $(BUILD)/$(OUT_NAME).hex @echo Create $(notdir $@) - @python3 tools/hexmerge.py --overlap=replace -o $@ $< $(MBR_HEX) + @$(PYTHON) tools/hexmerge.py --overlap=replace -o $@ $< $(MBR_HEX) # Bootolader self-update uf2 $(BUILD)/update-$(OUT_NAME)_nosd.uf2: $(BUILD)/$(OUT_NAME)_nosd.hex @echo Create $(notdir $@) - @python3 lib/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID_BOOTLOADER) -c -o $@ $^ + $(PYTHON) lib/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID_BOOTLOADER) -c -o $@ $^ # merge bootloader and sd hex together $(BUILD)/$(MERGED_FILE).hex: $(BUILD)/$(OUT_NAME).hex @echo Create $(notdir $@) - @python3 tools/hexmerge.py -o $@ $< $(SD_HEX) + @$(PYTHON) tools/hexmerge.py -o $@ $< $(SD_HEX) # Create pkg zip file for bootloader+SD combo to use with DFU CDC $(BUILD)/$(MERGED_FILE).zip: $(BUILD)/$(OUT_NAME).hex diff --git a/README.md b/README.md index 8fda77a..e66eb64 100644 --- a/README.md +++ b/README.md @@ -24,14 +24,21 @@ Officially supported boards are: - Adafruit Metro nRF52840 Express - [Raytac MDBT50Q-RX Dongle](https://www.adafruit.com/product/5199) -In addition, there is also lots of other 3rd-party boards which are added by other makers, users and community. Check out the [complete list of all boards here](/src/boards). +In addition, there is also lots of other 3rd-party boards which are added by other makers, users and community. Check +out the [complete list of all boards here](/supported_boards.md). ## Features -- DFU over Serial and OTA ( application, Bootloader+SD ) +- DFU over Serial and OTA (application, Bootloader+SD) - Self-upgradable via Serial and OTA - DFU using UF2 (https://github.com/Microsoft/uf2) (application only) - Auto-enter DFU briefly on startup for DTR auto-reset trick (832 only) +- Supports dual bank firmware updates (disabled by default) +- Supports signed firmware updates (disabled by default) + +Note: For OTA, `Packet Receipt Notification` (PRN) must be 8 or less, which can be configured in nRF DFU. Otherwise, the +bootloader will run out of +memory. ## How to use @@ -101,7 +108,7 @@ Pre-builtin binaries are available on GitHub [releases](https://github.com/adafr Note: The bootloader can be downgraded. Since the binary release is a merged version of both bootloader and the Nordic SoftDevice, you can freely upgrade/downgrade to any version you like. -## How to compile and build +## 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. @@ -206,6 +213,57 @@ To flash MBR only make BOARD=feather_nrf52840_express flash-mbr ``` +### Dual bank firmware support: + +This bootloader can split the FLASH memory into 2 partitions, one for the last successfully uploaded firmware, and the other for the new firmware that is being uploaded. In case the firmware upload fails, the bootloader will revert to the last working firmware version. The only drawback is that the maximum firmware size is half of the device FLASH size: That is why it is disabled by default. +You can enable this feature by passing DUALBANK_FW=1 to the make process while compiling the bootloader + +### Signed firmware support: +This bootloader can validate that the uploaded firmware is digitally signed, and refuse to install unsigned or signed with the improper key firmware. Because this will make Arduino uploads stop working (because they are not digitally signed), this feature is disabled by default. +But if you want to ensure noone else is allowed to upload firmware to your device, this option is probably what you want to enable. + +To create a signing key, you will need the adafruit-nrfutil utility. First, generate a signing key and store at given path by using + +``` +adafruit-nrfutil keys --gen-key stored_key.pem +``` + +This command will create a signing key and store it in the file stored_key.pem. STORE THIS FILE IN A SAFE PLACE, as without it, you won't be able to sign your firmware packages, and the bootloader will refuse to flash them!! + +Now, you must show the verification key (that is calculated from the signing key): + +``` +adafruit-nrfutil keys --show-vk code stored_key.pem +``` + +This command will read your signing key (from the file stored_key.pem) and display C source code with the Qx and Qy arrays: Something along the lines + +``` +static uint8_t Qx[] = { ... }; +static uint8_t Qy[] = { ... }; +``` + +You must save the Qx and Qy values, remove all spaces, and pass them to the make command line +``` +make BOARD=feather_nrf52840_express SIGNED_FW=1 SIGNED_FW_QX='Qx values' SIGNED_FW_QY='Qy values' +``` + +And replace Qx values with the Qx array values, and the Qy values with the Qy array values. That will create a bootloader that ONLY accepts firmware signed with the stored_key.pem signing key. Take into account that the option SIGNED_FW=1 is what enables to build a bootloader that enforces signing, and will ALSO result in disabling UF2 support, as UF2 format does NOT support signing keys. There is an option (only for testing!) called FORCE_UF2 that will FORCE UF2 support on bootloaders that enforce firmware security. It is there to bypass security so you can test a secure bootloader and have a way to recover it something goes wrong, but should NEVER be used if you want to enforce security + +Finally, to create a signed firmware application/bootloader update package, you can use, for example + +``` +adafruit-nrfutil dfu genpkg --dev-type 0x0052 --sd-req 0x0123 --application "application.hex" --key-file "stored_key.pem" "application_package.zip" +``` + +Please, use full paths for all files. The examples omit them for clarity! + +And, to upload it to your device, + +``` +adafruit-nrfutil.exe --verbose dfu serial -pkg "application_package.zip" -p /dev/tty0 -b 115200 +``` + ### Common makefile problems #### `arm-none-eabi-gcc`: No such file or directory diff --git a/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c b/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c index ea716cb..a79e4cb 100644 --- a/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c +++ b/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c @@ -17,13 +17,13 @@ #include #include "sdk_common.h" -#define MAX_DFU_PKT_LEN 20 /**< Maximum length (in bytes) of the DFU Packet characteristic. */ -#define PKT_START_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Start DFU Request. */ -#define PKT_INIT_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Init DFU Request. */ -#define PKT_RCPT_NOTIF_REQ_LEN 3 /**< Length (in bytes) of the Packet Receipt Notification Request. */ -#define MAX_PKTS_RCPT_NOTIF_LEN 6 /**< Maximum length (in bytes) of the Packets Receipt Notification. */ -#define MAX_RESPONSE_LEN 7 /**< Maximum length (in bytes) of the response to a Control Point command. */ -#define MAX_NOTIF_BUFFER_LEN MAX(MAX_PKTS_RCPT_NOTIF_LEN, MAX_RESPONSE_LEN) /**< Maximum length (in bytes) of the buffer needed by DFU Service while sending notifications to peer. */ +#define MAX_DFU_PKT_LEN (BLEGATT_ATT_MTU_MAX - 3) /**< Maximum length (in bytes) of the DFU Packet characteristic. */ +#define PKT_START_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Start DFU Request. */ +#define PKT_INIT_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Init DFU Request. */ +#define PKT_RCPT_NOTIF_REQ_LEN 3 /**< Length (in bytes) of the Packet Receipt Notification Request. */ +#define MAX_PKTS_RCPT_NOTIF_LEN 6 /**< Maximum length (in bytes) of the Packets Receipt Notification. */ +#define MAX_RESPONSE_LEN 7 /**< Maximum length (in bytes) of the response to a Control Point command. */ +#define MAX_NOTIF_BUFFER_LEN MAX(MAX_PKTS_RCPT_NOTIF_LEN, MAX_RESPONSE_LEN) /**< Maximum length (in bytes) of the buffer needed by DFU Service while sending notifications to peer. */ enum { @@ -57,7 +57,8 @@ static uint32_t dfu_pkt_char_add(ble_dfu_t * const p_dfu) memset(&char_md, 0, sizeof(char_md)); - char_md.char_props.write_wo_resp = 1; + char_md.char_props.write = 1; // For those improved apps that can take advantage of ACK + char_md.char_props.write_wo_resp = 1; // Nordic IOS DFU app REQUIRES Write Without Response */ char_md.p_char_user_desc = NULL; char_md.p_char_pf = NULL; char_md.p_user_desc_md = NULL; @@ -555,29 +556,35 @@ uint32_t ble_dfu_bytes_rcvd_report(ble_dfu_t * p_dfu, uint32_t num_of_firmware_b return NRF_ERROR_INVALID_STATE; } - ble_gatts_hvx_params_t hvx_params; - uint16_t index = 0; + uint32_t err_code; + do { - // Encode the Op Code. - m_notif_buffer[index++] = OP_CODE_RESPONSE; + ble_gatts_hvx_params_t hvx_params; + uint16_t index = 0; + + // Encode the Op Code. + m_notif_buffer[index++] = OP_CODE_RESPONSE; + + // Encode the Reqest Op Code. + m_notif_buffer[index++] = OP_CODE_IMAGE_SIZE_REQ; + + // Encode the Response Value. + m_notif_buffer[index++] = (uint8_t)BLE_DFU_RESP_VAL_SUCCESS; + + index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]); + + memset(&hvx_params, 0, sizeof(hvx_params)); + + hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; + hvx_params.type = BLE_GATT_HVX_NOTIFICATION; + hvx_params.offset = 0; + hvx_params.p_len = &index; + hvx_params.p_data = m_notif_buffer; + + err_code = sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); + } while (err_code == NRF_ERROR_RESOURCES); - // Encode the Reqest Op Code. - m_notif_buffer[index++] = OP_CODE_IMAGE_SIZE_REQ; - - // Encode the Response Value. - m_notif_buffer[index++] = (uint8_t)BLE_DFU_RESP_VAL_SUCCESS; - - index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]); - - memset(&hvx_params, 0, sizeof(hvx_params)); - - hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; - hvx_params.type = BLE_GATT_HVX_NOTIFICATION; - hvx_params.offset = 0; - hvx_params.p_len = &index; - hvx_params.p_data = m_notif_buffer; - - return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); + return err_code; } @@ -593,22 +600,28 @@ uint32_t ble_dfu_pkts_rcpt_notify(ble_dfu_t * p_dfu, uint32_t num_of_firmware_by return NRF_ERROR_INVALID_STATE; } - ble_gatts_hvx_params_t hvx_params; - uint16_t index = 0; + uint32_t err_code; + do { - m_notif_buffer[index++] = OP_CODE_PKT_RCPT_NOTIF; + ble_gatts_hvx_params_t hvx_params; + uint16_t index = 0; + + m_notif_buffer[index++] = OP_CODE_PKT_RCPT_NOTIF; + + index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]); + + memset(&hvx_params, 0, sizeof(hvx_params)); + + hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; + hvx_params.type = BLE_GATT_HVX_NOTIFICATION; + hvx_params.offset = 0; + hvx_params.p_len = &index; + hvx_params.p_data = m_notif_buffer; - index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]); + err_code = sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); + } while (err_code == NRF_ERROR_RESOURCES); - memset(&hvx_params, 0, sizeof(hvx_params)); - - hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; - hvx_params.type = BLE_GATT_HVX_NOTIFICATION; - hvx_params.offset = 0; - hvx_params.p_len = &index; - hvx_params.p_data = m_notif_buffer; - - return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); + return err_code; } @@ -626,24 +639,30 @@ uint32_t ble_dfu_response_send(ble_dfu_t * p_dfu, return NRF_ERROR_INVALID_STATE; } - ble_gatts_hvx_params_t hvx_params; - uint16_t index = 0; + uint32_t err_code; + do { - m_notif_buffer[index++] = OP_CODE_RESPONSE; + ble_gatts_hvx_params_t hvx_params; + uint16_t index = 0; + + m_notif_buffer[index++] = OP_CODE_RESPONSE; + + // Encode the Request Op code + m_notif_buffer[index++] = (uint8_t)dfu_proc; + + // Encode the Response Value. + m_notif_buffer[index++] = (uint8_t)resp_val; + + memset(&hvx_params, 0, sizeof(hvx_params)); + + hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; + hvx_params.type = BLE_GATT_HVX_NOTIFICATION; + hvx_params.offset = 0; + hvx_params.p_len = &index; + hvx_params.p_data = m_notif_buffer; + + err_code = sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); + } while (err_code == NRF_ERROR_RESOURCES); - // Encode the Request Op code - m_notif_buffer[index++] = (uint8_t)dfu_proc; - - // Encode the Response Value. - m_notif_buffer[index++] = (uint8_t)resp_val; - - memset(&hvx_params, 0, sizeof(hvx_params)); - - hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; - hvx_params.type = BLE_GATT_HVX_NOTIFICATION; - hvx_params.offset = 0; - hvx_params.p_len = &index; - hvx_params.p_data = m_notif_buffer; - - return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); + return err_code; } diff --git a/lib/sdk11/components/drivers_nrf/pstorage/pstorage_raw.c b/lib/sdk11/components/drivers_nrf/pstorage/pstorage_raw.c index f9404fe..a6ac067 100644 --- a/lib/sdk11/components/drivers_nrf/pstorage/pstorage_raw.c +++ b/lib/sdk11/components/drivers_nrf/pstorage/pstorage_raw.c @@ -280,6 +280,10 @@ static void app_notify(uint32_t result, cmd_queue_element_t * p_elem) */ void pstorage_sys_event_handler(uint32_t sys_evt) { + // Do not bother processing events we are not interested in + if (sys_evt != NRF_EVT_FLASH_OPERATION_SUCCESS && + sys_evt != NRF_EVT_FLASH_OPERATION_ERROR) return; + uint32_t retval = NRF_SUCCESS; // The event shall only be processed if requested by this module. @@ -339,6 +343,7 @@ void pstorage_sys_event_handler(uint32_t sys_evt) * @brief Function for processing of commands and issuing flash access request to the SoftDevice. * * @return The return value received from SoftDevice. + * @remark This function is only called when m_cmd_queue.flash_access == false */ static uint32_t cmd_process(void) { @@ -352,6 +357,9 @@ static uint32_t cmd_process(void) storage_addr = p_cmd->storage_addr.block_id; + // Let's assume we will do a flash access + m_cmd_queue.flash_access = true; + switch (p_cmd->op_code) { case PSTORAGE_STORE_OP_CODE: @@ -396,9 +404,10 @@ static uint32_t cmd_process(void) break; } - if (retval == NRF_SUCCESS) + // An error means we will not do it + if (retval != NRF_SUCCESS) { - m_cmd_queue.flash_access = true; + m_cmd_queue.flash_access = false; } return retval; diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c index 875ab6c..bd9b8cc 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c @@ -44,7 +44,8 @@ typedef enum BOOTLOADER_SETTINGS_SAVING, /**< Bootloader status for indicating that saving of bootloader settings is in progress. */ BOOTLOADER_COMPLETE, /**< Bootloader status for indicating that all operations for the update procedure has completed and it is safe to reset the system. */ BOOTLOADER_TIMEOUT, /**< Bootloader status field for indicating that a timeout has occured and current update process should be aborted. */ - BOOTLOADER_RESET, /**< Bootloader status field for indicating that a reset has been requested and current update process should be aborted. */ + BOOTLOADER_SYS_RESET, /**< Bootloader status field for indicating that a reset has been requested and current update process should be aborted. */ + BOOTLOADER_RESET_TO_SELF, /**< Bootloader status field for indicating that a reset has been requested and current update process should be aborted and the bootloader must be reentered. */ } bootloader_status_t; static pstorage_handle_t m_bootsettings_handle; /**< Pstorage handle to use for registration and identifying the bootloader module on subsequent calls to the pstorage module for load and store of bootloader setting in flash. */ @@ -136,9 +137,10 @@ static void wait_for_events(void) if ((m_update_status == BOOTLOADER_COMPLETE) || (m_update_status == BOOTLOADER_TIMEOUT) || - (m_update_status == BOOTLOADER_RESET) ) + (m_update_status == BOOTLOADER_SYS_RESET) || + (m_update_status == BOOTLOADER_RESET_TO_SELF)) { - // When update has completed or a timeout/reset occured we will return. + // When update has completed or a timeout/reset occurred we will return. return; } } @@ -186,10 +188,36 @@ static void bootloader_settings_save(bootloader_settings_t * p_settings) { if ( is_ota() ) { - uint32_t err_code = pstorage_clear(&m_bootsettings_handle, sizeof(bootloader_settings_t)); + uint32_t err_code; + while(1) { + err_code = pstorage_clear(&m_bootsettings_handle, sizeof(bootloader_settings_t)); + if (err_code != NRF_ERROR_NO_MEM) { + break; + } + // This means the write/erase queue of commands was completely full - Should not + // happen, but better safe than sorry, wait until space becomes available - + // the pstorage event handler is only run from the main loop, and we are also + // running from a BLE event on the main loop: This means if we wait here, the FLASH + // completion events will never be handled (will be queued by app_scheduler, but + // not handled, and that means this wait will never end... So, process SOC events + // from the SD (but NOT BLE events!) - This will free entries on the pstorage queue + // as soon as operations are complete, allowing this op to be queued + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } APP_ERROR_CHECK(err_code); - err_code = pstorage_store(&m_bootsettings_handle, (uint8_t *) p_settings, sizeof(bootloader_settings_t), 0); + while(1) { + err_code = pstorage_store(&m_bootsettings_handle, (uint8_t *) p_settings, sizeof(bootloader_settings_t), 0); + if (err_code != NRF_ERROR_NO_MEM) { + break; + } + // No space, wait until an entry in the queue is freed + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } APP_ERROR_CHECK(err_code); } else @@ -296,7 +324,8 @@ void bootloader_dfu_update_process(dfu_update_status_t update_status) } else if (update_status.status_code == DFU_RESET) { - m_update_status = BOOTLOADER_RESET; + m_update_status = + (update_status.restart_into_bootloader == false ? BOOTLOADER_SYS_RESET : BOOTLOADER_RESET_TO_SELF); } else { @@ -304,6 +333,10 @@ void bootloader_dfu_update_process(dfu_update_status_t update_status) } } +bool bootloader_must_reset_to_self(void) +{ + return m_update_status == BOOTLOADER_RESET_TO_SELF; +} uint32_t bootloader_init(void) { diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.h b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.h index efd72e7..9b6f754 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.h +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.h @@ -32,6 +32,13 @@ */ uint32_t bootloader_init(void); +/**@brief Function to check if bootloader must be reentered after a reset + * @details: This function can only be called after bootloader_dfu_start returns + * @retval true If device must reboot to the bootloader + * @retval false If device must reboot to the application, if possible + */ +bool bootloader_must_reset_to_self(void); + /**@brief Function for validating application region in flash. * @retval true If Application region is valid. * @retval false If Application region is not valid. @@ -92,6 +99,8 @@ uint32_t bootloader_dfu_sd_update_finalize(void); void bootloader_mbr_addrs_populate(void); +extern uint32_t proc_soc(void); + #endif // BOOTLOADER_H__ /**@} */ diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c index c071020..1febf3f 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c @@ -40,15 +40,22 @@ void bootloader_util_settings_get(const bootloader_settings_t ** pp_bootloader_s *pp_bootloader_settings = p_bootloader_settings; } -void bootloader_mbr_addrs_populate(void) -{ - if (*(const uint32_t *)MBR_BOOTLOADER_ADDR == 0xFFFFFFFF) - { - nrfx_nvmc_word_write(MBR_BOOTLOADER_ADDR, BOOTLOADER_REGION_START); - } - - if (*(const uint32_t *)MBR_PARAM_PAGE_ADDR == 0xFFFFFFFF) - { - nrfx_nvmc_word_write(MBR_PARAM_PAGE_ADDR, BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS); - } -} +void bootloader_mbr_addrs_populate(void) +{ +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#endif + if (*(const uint32_t *)MBR_BOOTLOADER_ADDR == 0xFFFFFFFF) + { + nrfx_nvmc_word_write(MBR_BOOTLOADER_ADDR, BOOTLOADER_REGION_START); + } + + if (*(const uint32_t *)MBR_PARAM_PAGE_ADDR == 0xFFFFFFFF) + { + nrfx_nvmc_word_write(MBR_PARAM_PAGE_ADDR, BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS); + } +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic pop +#endif +} diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader_util.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader_util.c index f6c2bcc..62cb285 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader_util.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader_util.c @@ -32,6 +32,12 @@ #if defined ( __CC_ARM ) __asm static void bootloader_util_reset(uint32_t start_addr) { + MOVS R5, #0x00 ; R5 = 0 + MSR CONTROL, R5 ; Clear CONTROL + MSR PRIMASK, R5 ; Clear PRIMASK + MSR BASEPRI, R5 ; Clear BASEPRI + MSR FAULTMASK, R5 ; Clear FAULTMASK + LDR R5, [R0] ; Get App initial MSP for bootloader. MSR MSP, R5 ; Set the main stack pointer to the applications MSP. LDR R0, [R0, #0x04] ; Load Reset handler into R0. This will be first argument to branch instruction (BX). @@ -69,6 +75,12 @@ static inline void bootloader_util_reset (uint32_t start_addr) __attribute__ ((o static inline void bootloader_util_reset(uint32_t start_addr) { __asm volatile( + "movs r5, #0x00\t\n" // R5 = 0 + "msr control, r5\t\n" // Clear CONTROL + "msr primask, r5\t\n" // Clear PRIMASK + "msr basepri, r5\t\n" // Clear BASEPRI + "msr faultmask, r5\t\n" // Clear FAULTMASK + "ldr r0, [%0]\t\n" // Get App initial MSP for bootloader. "msr msp, r0\t\n" // Set the main stack pointer to the applications MSP. "ldr r0, [%0, #0x04]\t\n" // Load Reset handler into R0. @@ -108,7 +120,13 @@ static inline void bootloader_util_reset(uint32_t start_addr) #elif defined ( __ICCARM__ ) static inline void bootloader_util_reset(uint32_t start_addr) { - asm("ldr r5, [%0]\n" // Get App initial MSP for bootloader. + asm("movs r5, #0x00\n" // R5 = 0 + "msr control, r5\n" // Clear CONTROL + "msr primask, r5\n" // Clear PRIMASK + "msr basepri, r5\n" // Clear BASEPRI + "msr faultmask, r5\n" // Clear FAULTMASK + + "ldr r5, [%0]\n" // Get App initial MSP for bootloader. "msr msp, r5\n" // Set the main stack pointer to the applications MSP. "ldr r0, [%0, #0x04]\n" // Load Reset handler into R0. diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_bank_internal.h b/lib/sdk11/components/libraries/bootloader_dfu/dfu_bank_internal.h index 03d20f6..f84d111 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_bank_internal.h +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_bank_internal.h @@ -40,6 +40,8 @@ typedef enum DFU_STATE_WAIT_4_ACTIVATE /**< State for: waiting for dfu_image_activate(). */ } dfu_state_t; +#define DFU_TIMEOUT_INTERVAL APP_TIMER_TICKS(360000) /**< DFU timeout interval in milliseconds. */ + #define IS_UPDATING_SD(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_SD) /**< Macro for determining if a SoftDevice update is ongoing. */ #define IS_UPDATING_BL(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_BL) /**< Macro for determining if a Bootloader update is ongoing. */ #define IS_UPDATING_APP(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_APP) /**< Macro for determining if a Application update is ongoing. */ diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c new file mode 100644 index 0000000..32cc71a --- /dev/null +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c @@ -0,0 +1,947 @@ +/* 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, integrity 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 = {0}; + + 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) +{ + 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; + + if ( is_ota() ) + { + uint32_t err_code; + while(1) { + err_code = pstorage_clear(&m_storage_handle_app, m_image_size); + if (err_code != NRF_ERROR_NO_MEM) + break; + // No space, wait until an entry in the queue is freed + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } + APP_ERROR_CHECK(err_code); + } + else + { + flash_nrf5x_erase(DFU_BANK_0_REGION_START, m_image_size); + + // invoke complete callback + pstorage_callback_handler(&m_storage_handle_app, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0); + } +} + + +/**@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) +{ + mp_storage_handle_active = &m_storage_handle_swap; + + m_dfu_state = DFU_STATE_PREPARING; + + if ( is_ota() ) + { + uint32_t err_code; + while(1) { + err_code = pstorage_clear(&m_storage_handle_swap, image_size); + if (err_code != NRF_ERROR_NO_MEM) + break; + // No space, wait until an entry in the queue is freed + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } + APP_ERROR_CHECK(err_code); + } + else + { + flash_nrf5x_erase(DFU_BANK_1_REGION_START, image_size); + + // invoke complete callback + pstorage_callback_handler(&m_storage_handle_swap, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0); + } +} + + +/**@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 = { 0 }; + update_status.status_code = 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 successfully validate transfer and relocation it is important + * that temporary image and final installed image does not overlap 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 = {0}; + + 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 from 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 = NRF_SUCCESS; + + // Erase BANK 0. + if ( is_ota() ) + { + while(1) { + err_code = pstorage_clear(&m_storage_handle_app, m_start_packet.app_image_size); + if (err_code != NRF_ERROR_NO_MEM) + break; + // No space, wait until an entry in the queue is freed + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } + APP_ERROR_CHECK(err_code); + + while(1) { + 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_ERROR_NO_MEM) + break; + // No space, wait until an entry in the queue is freed + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } + VERIFY_SUCCESS(err_code); + + } + else + { + flash_nrf5x_erase(DFU_BANK_0_REGION_START, m_start_packet.app_image_size); + pstorage_callback_handler(&m_storage_handle_app, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0); + + flash_nrf5x_write(DFU_BANK_0_REGION_START, (uint8_t *)DFU_BANK_1_REGION_START, m_start_packet.app_image_size, false); + flash_nrf5x_flush(false); + pstorage_callback_handler(&m_storage_handle_app, PSTORAGE_STORE_OP_CODE, NRF_SUCCESS, (uint8_t *) DFU_BANK_1_REGION_START, m_start_packet.app_image_size); + } + + if (err_code == NRF_SUCCESS) + { + dfu_update_status_t update_status = { 0 }; + + 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 = {0}; + + 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; + } + } + + if ( DFU_STATE_IDLE != m_dfu_state ) + return NRF_ERROR_INVALID_STATE; + + // Valid peer activity detected. Hence restart the DFU timer. + err_code = dfu_timer_restart(); + VERIFY_SUCCESS(err_code); + + m_functions.prepare(m_image_size); + + return NRF_SUCCESS; +} + + +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; + + if ( is_ota() ) + { + while(1) { + err_code = pstorage_store(mp_storage_handle_active, (uint8_t *)p_data, data_length, m_data_received); + if (err_code != NRF_ERROR_NO_MEM) + break; + // No space, wait until an entry in the queue is freed + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } + VERIFY_SUCCESS(err_code); + } + else + { + flash_nrf5x_write( + (mp_storage_handle_active == &m_storage_handle_app + ? DFU_BANK_0_REGION_START + : DFU_BANK_1_REGION_START) + + m_data_received, p_data, data_length, false); + pstorage_callback_handler(mp_storage_handle_active, PSTORAGE_STORE_OP_CODE, NRF_SUCCESS, (uint8_t *) p_data, data_length); + } + + 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 + { + if ( !is_ota() ) flash_nrf5x_flush(false); + + // 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. + /* FALLTHRU */ + + 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. + return NRF_ERROR_INVALID_STATE; + } + + return NRF_SUCCESS; +} + + +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 transferred 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 = { 0 }; + + update_status.status_code = DFU_RESET; + + // If we are still receiving packets, and we are expecting more of them, + // and we receive the RESET command, this means the DFU app is trying + // to interrupt and recover a failed previous attempt of FLASHing a new + // application. Make sure to reboot into DFU mode instead of starting + // a previously stored application (specially valid for double bank + // bootloaders + update_status.restart_into_bootloader = (m_dfu_state == DFU_STATE_RX_DATA_PKT && m_data_received != m_image_size); + + 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 necessary to swap the new SoftDevice in 3 rounds to ensure correct copy of data + // and verification 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_1; + sd_mbr_command_t sd_mbr_cmd_2; + + bootloader_settings_get(&bootloader_settings); + + if (bootloader_settings.bl_image_size != 0) + { + uint32_t bl_image_start_1 = (bootloader_settings.sd_image_size == 0) ? + DFU_BANK_0_REGION_START : + bootloader_settings.sd_image_start + + bootloader_settings.sd_image_size; + + sd_mbr_cmd_1.command = SD_MBR_COMMAND_COMPARE; + sd_mbr_cmd_1.params.compare.ptr1 = (uint32_t *)BOOTLOADER_REGION_START; + sd_mbr_cmd_1.params.compare.ptr2 = (uint32_t *)(bl_image_start_1); + sd_mbr_cmd_1.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); + + uint32_t err_code = sd_mbr_command(&sd_mbr_cmd_1); + if (err_code == NRF_SUCCESS) + return NRF_SUCCESS; + + uint32_t bl_image_start_2 = (bootloader_settings.sd_image_size == 0) ? + DFU_BANK_1_REGION_START : + bootloader_settings.sd_image_start + + bootloader_settings.sd_image_size; + + sd_mbr_cmd_2.command = SD_MBR_COMMAND_COMPARE; + sd_mbr_cmd_2.params.compare.ptr1 = (uint32_t *)BOOTLOADER_REGION_START; + sd_mbr_cmd_2.params.compare.ptr2 = (uint32_t *)(bl_image_start_2); + sd_mbr_cmd_2.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); + + return sd_mbr_command(&sd_mbr_cmd_2); + } + 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); +} 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 fa69ec8..114a57c 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c @@ -31,10 +31,13 @@ static dfu_state_t m_dfu_state; /**< Current DFU 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[64]; /**< Init packet, can hold CRC, Hash, Signed Hash and similar, for image validation, integrety check and authorization checking. */ +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_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. */ @@ -80,6 +83,47 @@ static void pstorage_callback_handler(pstorage_handle_t * p_handle, 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 @@ -88,31 +132,33 @@ static void pstorage_callback_handler(pstorage_handle_t * p_handle, */ static void dfu_prepare_func_app_erase(uint32_t image_size) { - mp_storage_handle_active = &m_storage_handle_app; + 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; + // Doing a SoftDevice update thus current application must be cleared to ensure enough space + // for new SoftDevice. + m_dfu_state = DFU_STATE_PREPARING; - if ( is_ota() ) - { - uint32_t err_code = pstorage_clear(&m_storage_handle_app, m_image_size); - APP_ERROR_CHECK(err_code); - } - else - { - uint32_t const page_count = NRFX_CEIL_DIV(m_image_size, CODE_PAGE_SIZE); - - for ( uint32_t i = 0; i < page_count; i++ ) + if ( is_ota() ) { - uint32_t const addr = DFU_BANK_0_REGION_START + i * CODE_PAGE_SIZE; - PRINTF("Erase 0x%08lX\r\n", addr); - nrfx_nvmc_page_erase(addr); + uint32_t err_code; + while(1) { + err_code = pstorage_clear(&m_storage_handle_app, m_image_size); + if (err_code != NRF_ERROR_NO_MEM) + break; + // No space, wait until an entry in the queue is freed + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } + APP_ERROR_CHECK(err_code); } + else + { + flash_nrf5x_erase(DFU_BANK_0_REGION_START, m_image_size); - // invoke complete callback - pstorage_callback_handler(&m_storage_handle_app, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0); - } + // invoke complete callback + pstorage_callback_handler(&m_storage_handle_app, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0); + } } @@ -136,14 +182,14 @@ static void dfu_cleared_func_app(void) 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) { @@ -189,8 +235,7 @@ static uint32_t dfu_activate_sd(void) */ static uint32_t dfu_activate_app(void) { - uint32_t err_code = NRF_SUCCESS; - dfu_update_status_t update_status; + dfu_update_status_t update_status = { 0 }; memset(&update_status, 0, sizeof(dfu_update_status_t )); update_status.status_code = DFU_UPDATE_APP_COMPLETE; @@ -199,7 +244,7 @@ static uint32_t dfu_activate_app(void) bootloader_dfu_update_process(update_status); - return err_code; + return NRF_SUCCESS; } @@ -213,7 +258,7 @@ static uint32_t dfu_activate_app(void) */ static uint32_t dfu_activate_bl(void) { - dfu_update_status_t update_status; + dfu_update_status_t update_status = {0}; update_status.status_code = DFU_UPDATE_BOOT_COMPLETE; update_status.app_crc = m_image_crc; @@ -244,6 +289,16 @@ uint32_t dfu_init(void) m_storage_handle_app.block_id = DFU_BANK_0_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; @@ -259,6 +314,8 @@ void dfu_register_callback(dfu_callback_t 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. @@ -267,7 +324,7 @@ uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet) // - SoftDevice // - Bootloader // - SoftDevice with Bootloader - if (IS_UPDATING_APP(m_start_packet) && + 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. @@ -284,7 +341,7 @@ uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet) 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; @@ -296,7 +353,7 @@ uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet) } m_functions.prepare = dfu_prepare_func_app_erase; m_functions.cleared = dfu_cleared_func_app; - + if (IS_UPDATING_SD(m_start_packet)) { m_functions.activate = dfu_activate_sd; @@ -312,6 +369,10 @@ uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet) if ( DFU_STATE_IDLE != m_dfu_state ) return NRF_ERROR_INVALID_STATE; + // Valid peer activity detected. Hence restart the DFU timer. + err_code = dfu_timer_restart(); + VERIFY_SUCCESS(err_code); + m_functions.prepare(m_image_size); return NRF_SUCCESS; @@ -354,17 +415,29 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet) 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; if ( is_ota() ) { - err_code = pstorage_store(mp_storage_handle_active, (uint8_t *)p_data, data_length, m_data_received); - VERIFY_SUCCESS(err_code); + while(1) { + err_code = pstorage_store(mp_storage_handle_active, (uint8_t *)p_data, data_length, m_data_received); + if (err_code != NRF_ERROR_NO_MEM) + break; + // No space, wait until an entry in the queue is freed + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } + VERIFY_SUCCESS(err_code); } else { - flash_nrf5x_write(DFU_BANK_0_REGION_START + m_data_received, p_data, data_length, false); - pstorage_callback_handler(mp_storage_handle_active, PSTORAGE_STORE_OP_CODE, NRF_SUCCESS, (uint8_t *) p_data, data_length); + flash_nrf5x_write(DFU_BANK_0_REGION_START + m_data_received, p_data, data_length, false); + pstorage_callback_handler(mp_storage_handle_active, PSTORAGE_STORE_OP_CODE, NRF_SUCCESS, (uint8_t *) p_data, data_length); } m_data_received += data_length; @@ -376,10 +449,10 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet) } else { - if ( !is_ota() ) flash_nrf5x_flush(false); + if ( !is_ota() ) flash_nrf5x_flush(false); - // The entire image has been received. Return NRF_SUCCESS. - err_code = NRF_SUCCESS; + // The entire image has been received. Return NRF_SUCCESS. + err_code = NRF_SUCCESS; } break; @@ -395,14 +468,14 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet) 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); @@ -421,6 +494,7 @@ uint32_t dfu_init_pkt_complete(void) 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) @@ -438,6 +512,10 @@ uint32_t dfu_init_pkt_handle(dfu_update_packet_t * p_packet) 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)) { @@ -477,9 +555,16 @@ uint32_t dfu_image_validate() { m_dfu_state = DFU_STATE_VALIDATE; - 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; + // 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; @@ -499,6 +584,11 @@ uint32_t dfu_image_activate() 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; @@ -513,10 +603,18 @@ uint32_t dfu_image_activate() void dfu_reset(void) { - dfu_update_status_t update_status; + dfu_update_status_t update_status = { 0 }; update_status.status_code = DFU_RESET; + // If we are still receiving packets, and we are expecting more of them, + // and we receive the RESET command, this means the DFU app is trying + // to interrupt and recover a failed previous attempt of FLASHing a new + // application. Make sure to reboot into DFU mode instead of starting + // a previously stored application (specially valid for double bank + // bootloaders + update_status.restart_into_bootloader = (m_dfu_state == DFU_STATE_RX_DATA_PKT && m_data_received != m_image_size); + bootloader_dfu_update_process(update_status); } @@ -547,13 +645,13 @@ static uint32_t dfu_copy_sd(uint32_t * src, uint32_t * dst, uint32_t len) } -static uint32_t dfu_sd_img_block_swap(uint32_t * src, - uint32_t * dst, - uint32_t len, +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. + // and verification 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); @@ -564,9 +662,9 @@ static uint32_t dfu_sd_img_block_swap(uint32_t * src, 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, + 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); } @@ -588,37 +686,37 @@ uint32_t dfu_sd_image_swap(void) { 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 ##### */ - + 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), + 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, + + return dfu_sd_img_block_swap((uint32_t *)img_block_start, + (uint32_t *)sd_block_start, + image_end - img_block_start, block_size); } else @@ -626,7 +724,7 @@ uint32_t dfu_sd_image_swap(void) if (boot_settings.sd_image_size != 0) { return dfu_copy_sd((uint32_t *)boot_settings.sd_image_start, - (uint32_t *)SOFTDEVICE_REGION_START, + (uint32_t *)SOFTDEVICE_REGION_START, boot_settings.sd_image_size); } } @@ -646,7 +744,7 @@ uint32_t dfu_bl_image_swap(void) { uint32_t bl_image_start = (bootloader_settings.sd_image_size == 0) ? DFU_BANK_0_REGION_START : - bootloader_settings.sd_image_start + + bootloader_settings.sd_image_start + bootloader_settings.sd_image_size; sd_mbr_cmd.command = SD_MBR_COMMAND_COPY_BL; @@ -658,27 +756,54 @@ uint32_t dfu_bl_image_swap(void) return NRF_SUCCESS; } - uint32_t dfu_bl_image_validate(void) { bootloader_settings_t bootloader_settings; - sd_mbr_command_t sd_mbr_cmd; + + sd_mbr_command_t sd_mbr_cmd_1; + sd_mbr_command_t sd_mbr_cmd_2; bootloader_settings_get(&bootloader_settings); if (bootloader_settings.bl_image_size != 0) { - uint32_t bl_image_start = (bootloader_settings.sd_image_size == 0) ? + /* + * The problem with updating the bootloader from a dual to single bank bootloader is that the new + * bootloader expects the firmware image to be at the start of BANK 0, while it's actually loaded + * to BANK1 by the old bootloader. After the update the new single bank bootloader verifies that + * the image was correctly written to flash by comparing itself with the firmware image that it + * expects to be located in BANK0. Since the actual firmware image is in BANK 1 this check will + * fail and the new bootloader updates itself with whatever data located in BANK0 using the MBR. + + * The fix is to modify the dfu_bl_image_validate() function in dfu_single_bank.c run verification + * on both addresses (BANK0 and BANK1) + */ + uint32_t bl_image_start_1 = (bootloader_settings.sd_image_size == 0) ? DFU_BANK_0_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); + sd_mbr_cmd_1.command = SD_MBR_COMMAND_COMPARE; + sd_mbr_cmd_1.params.compare.ptr1 = (uint32_t *)BOOTLOADER_REGION_START; + sd_mbr_cmd_1.params.compare.ptr2 = (uint32_t *)(bl_image_start_1); + sd_mbr_cmd_1.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); - return sd_mbr_command(&sd_mbr_cmd); + uint32_t err_code = sd_mbr_command(&sd_mbr_cmd_1); + if (err_code == NRF_SUCCESS) { + return NRF_SUCCESS; + } + + uint32_t bl_image_start_2 = (bootloader_settings.sd_image_size == 0) ? + DFU_BANK_1_REGION_START : + bootloader_settings.sd_image_start + + bootloader_settings.sd_image_size; + + sd_mbr_cmd_2.command = SD_MBR_COMMAND_COMPARE; + sd_mbr_cmd_2.params.compare.ptr1 = (uint32_t *)BOOTLOADER_REGION_START; + sd_mbr_cmd_2.params.compare.ptr2 = (uint32_t *)(bl_image_start_2); + sd_mbr_cmd_2.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); + + return sd_mbr_command(&sd_mbr_cmd_2); } return NRF_SUCCESS; } @@ -695,17 +820,18 @@ uint32_t dfu_sd_image_validate(void) { 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 + + 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 ##### */ + 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; @@ -714,12 +840,12 @@ uint32_t dfu_sd_image_validate(void) 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, + 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; 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 2715dce..be6b672 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c @@ -35,11 +35,6 @@ #include "nrf_delay.h" #include "sdk_common.h" - -#define BLEGAP_EVENT_LENGTH 6 -#define BLEGATT_ATT_MTU_MAX 23 -enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 }; - #define DFU_REV_MAJOR 0x00 /** DFU Major revision number to be exposed. */ #define DFU_REV_MINOR 0x08 /** DFU Minor revision number to be exposed. */ #define DFU_REVISION ((DFU_REV_MAJOR << 8) | DFU_REV_MINOR) /** DFU Revision number to be exposed. Combined of major and minor versions. */ @@ -47,16 +42,19 @@ enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 }; #define BLE_HANDLE_MAX 0xFFFF /**< Max handle value is BLE. */ // limit of 8 chars +#ifndef DEVICE_NAME #define DEVICE_NAME "AdaDFU" /**< Name of device. Will be included in the advertising data. */ +#endif -#define MIN_CONN_INTERVAL (uint16_t)(MSEC_TO_UNITS(10, UNIT_1_25_MS)) /**< Minimum acceptable connection interval (11.25 milliseconds). */ +#define MIN_CONN_INTERVAL (uint16_t)(MSEC_TO_UNITS(15, UNIT_1_25_MS)) /**< Minimum acceptable connection interval (11.25 milliseconds). */ #define MAX_CONN_INTERVAL (uint16_t)(MSEC_TO_UNITS(30, UNIT_1_25_MS)) /**< Maximum acceptable connection interval (15 milliseconds). */ -#define SLAVE_LATENCY 0 /**< Slave latency. */ -#define CONN_SUP_TIMEOUT (4 * 100) /**< Connection supervisory timeout (4 seconds). */ +#define SLAVE_LATENCY 4 /**< Slave latency. */ +#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(8000, UNIT_10_MS) /**< Connection supervisory timeout (4 seconds). */ +#define SPEEDUP_FLASH_WRITES 1 /**< Speedup FLASH writes by changing Softdevice local latency */ #define APP_ADV_INTERVAL MSEC_TO_UNITS(25, UNIT_0_625_MS) /**< The advertising interval (25 ms.). */ #define APP_ADV_TIMEOUT BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED /**< The advertising timeout in units of seconds. This is set to @ref BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED so that the advertisement is done as long as there there is a call to @ref dfu_transport_close function.*/ -#define APP_DIRECTED_ADV_TIMEOUT 50 /**< number of direct advertisement (each lasting 1.28seconds). */ +#define APP_DIRECTED_ADV_TIMEOUT 50 /**< number of direct advertisement (each lasting 1.28seconds). */ #define PEER_ADDRESS_TYPE_INVALID 0xFF /**< Value indicating that no valid peer address exists. This will be the case when a private resolvable address is used in which case there is no address available but instead an IRK is present. */ #define PEER_ADDRESS_TYPE_INVALID 0xFF /**< Value indicating that no valid peer address exists. This will be the case when a private resolvable address is used in which case there is no address available but instead an IRK is present. */ @@ -75,8 +73,9 @@ enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 }; #define IS_CONNECTED() (m_conn_handle != BLE_CONN_HANDLE_INVALID) /**< Macro to determine if the device is in connected state. */ -#define APP_FEATURE_NOT_SUPPORTED BLE_GATT_STATUS_ATTERR_APP_BEGIN + 2 /**< Reply when unsupported features are requested. */ -#define SD_IMAGE_SIZE_OFFSET 0 /**< Offset in start packet for the size information for SoftDevice. */ +#define APP_FEATURE_NOT_SUPPORTED \ + (BLE_GATT_STATUS_ATTERR_APP_BEGIN + 2) /**< Reply when unsupported features are requested. */ +#define SD_IMAGE_SIZE_OFFSET 0 /**< Offset in start packet for the size information for SoftDevice. */ #define BL_IMAGE_SIZE_OFFSET 4 /**< Offset in start packet for the size information for bootloader. */ #define APP_IMAGE_SIZE_OFFSET 8 /**< Offset in start packet for the size information for application. */ @@ -208,7 +207,35 @@ static ble_dfu_resp_val_t nrf_err_code_translate(uint32_t err_c } } +#ifdef SPEEDUP_FLASH_WRITES +static void prioritize_ble_over_flash_writes(void) { + // We set the local latency to 0: That will revert latency to the negotiated one with the host. + // That will increase throughput to the maximum possible + ble_opt_t opt; + varclr(&opt); + opt.gap_opt.local_conn_latency.conn_handle = m_conn_handle; /**< Connection Handle */ + opt.gap_opt.local_conn_latency.requested_latency = 0; /**< Requested local connection latency. */ + opt.gap_opt.local_conn_latency.p_actual_latency = + NULL; /**< Pointer to storage for the actual local connection latency (can be set to NULL to skip return value). */ + sd_ble_opt_set(BLE_GAP_OPT_LOCAL_CONN_LATENCY, &opt); +} +static void prioritize_flash_writes_over_ble(void) { + // We set the local latency to the maximum possible: That will make FLASH writes faster, as BLE comms will + // be delayed (even losing RXd packets, but this is the same as a poor connection and will be handled by + // the protocol itself) + ble_opt_t opt; + varclr(&opt); + opt.gap_opt.local_conn_latency.conn_handle = m_conn_handle; /**< Connection Handle */ + opt.gap_opt.local_conn_latency.requested_latency = 50; /**< Requested local connection latency. */ + opt.gap_opt.local_conn_latency.p_actual_latency = + NULL; /**< Pointer to storage for the actual local connection latency (can be set to NULL to skip return value). */ + sd_ble_opt_set(BLE_GAP_OPT_LOCAL_CONN_LATENCY, &opt); +} +#else + #define prioritize_ble_over_flash_writes() + #define prioritize_flash_writes_over_ble() +#endif /**@brief Function for handling the callback events from the dfu module. * Callbacks are expected when \ref dfu_data_pkt_handle has been executed. * @@ -226,6 +253,9 @@ static void dfu_cb_handler(uint32_t packet, uint32_t result, uint8_t * p_data) case DATA_PACKET: if (result != NRF_SUCCESS) { + // Restore latency to the negotiated one + prioritize_ble_over_flash_writes(); + // Disconnect from peer. if (IS_CONNECTED()) { @@ -242,6 +272,9 @@ static void dfu_cb_handler(uint32_t packet, uint32_t result, uint8_t * p_data) // If the callback matches final data packet received then the peer is notified. if (mp_final_packet == p_data) { + // Restore latency to the negotiated one + prioritize_ble_over_flash_writes(); + // Notify the DFU Controller about the success of the procedure. err_code = ble_dfu_response_send(&m_dfu, BLE_DFU_RECEIVE_APP_PROCEDURE, @@ -252,6 +285,10 @@ static void dfu_cb_handler(uint32_t packet, uint32_t result, uint8_t * p_data) break; case START_PACKET: + + // Restore latency to the negotiated one + prioritize_ble_over_flash_writes(); + // Translate the err_code returned by the above function to DFU Response Value. resp_val = nrf_err_code_translate(result, BLE_DFU_START_PROCEDURE); @@ -324,9 +361,15 @@ static void start_data_process(ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt) start_packet.bl_image_size = uint32_decode(p_length_data + BL_IMAGE_SIZE_OFFSET); start_packet.app_image_size = uint32_decode(p_length_data + APP_IMAGE_SIZE_OFFSET); + // Prioritize FLASH writes over BLE comms + prioritize_flash_writes_over_ble(); + err_code = dfu_start_pkt_handle(&update_packet); if (err_code != NRF_SUCCESS) { + // Prioritize BLE over flash writes + prioritize_ble_over_flash_writes(); + // Translate the err_code returned by the above function to DFU Response Value. ble_dfu_resp_val_t resp_val; @@ -743,8 +786,22 @@ static void on_ble_evt(ble_evt_t * p_ble_evt) switch (p_ble_evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: - m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; - m_is_advertising = false; + { + m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; + m_is_advertising = false; + + // Force changing the slave latency to try to improve transfer throughput (bandwidth) + // But Android and IOS will override it with their minimum supported value + ble_gap_conn_params_t p_conn_params; + p_conn_params.min_conn_interval = p_ble_evt->evt.gap_evt.params.connected.conn_params.min_conn_interval; + p_conn_params.max_conn_interval = p_ble_evt->evt.gap_evt.params.connected.conn_params.max_conn_interval; + p_conn_params.slave_latency = SLAVE_LATENCY; + p_conn_params.conn_sup_timeout = p_ble_evt->evt.gap_evt.params.connected.conn_params.conn_sup_timeout; + + err_code = sd_ble_gap_conn_param_update(m_conn_handle, &p_conn_params); + APP_ERROR_CHECK(err_code); + + } break; case BLE_GAP_EVT_DISCONNECTED: @@ -774,6 +831,9 @@ static void on_ble_evt(ble_evt_t * p_ble_evt) break; + case BLE_GAP_EVT_CONN_PARAM_UPDATE: + break; + case BLE_GAP_EVT_SEC_PARAMS_REQUEST: { ble_gap_sec_keyset_t keys; @@ -900,6 +960,11 @@ static void on_ble_evt(ble_evt_t * p_ble_evt) case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: { uint16_t att_mtu = MIN(p_ble_evt->evt.gatts_evt.params.exchange_mtu_request.client_rx_mtu, BLEGATT_ATT_MTU_MAX); + + // Round it to a multiple of 4 plus 3 bytes, as we need data packets to be multiple of 4 bytes + att_mtu &= 0xFFFCU; + att_mtu |= 3; + PRINTF("GAP ATT MTU is changed to %d\r\n", att_mtu); APP_ERROR_CHECK( sd_ble_gatts_exchange_mtu_reply(m_conn_handle, att_mtu) ); } diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h b/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h index 4148e1c..e186e05 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h @@ -24,6 +24,7 @@ #define DFU_TYPES_H__ #include +#include #include "nrf_sdm.h" #include "nrf_mbr.h" #include "nrf.h" @@ -74,8 +75,12 @@ static inline bool is_sd_existed(void) #endif #define DFU_IMAGE_MAX_SIZE_FULL (DFU_REGION_TOTAL_SIZE - DFU_APP_DATA_RESERVED) /**< Maximum size of an application, excluding save data from the application. */ +#define DFU_IMAGE_MAX_SIZE_BANKED (((DFU_IMAGE_MAX_SIZE_FULL) - \ + (DFU_IMAGE_MAX_SIZE_FULL % (2 * CODE_PAGE_SIZE)))/2) /**< Maximum size of an application, excluding save data from the application. */ + #define DFU_BL_IMAGE_MAX_SIZE (BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS - BOOTLOADER_REGION_START) /**< Maximum size of a bootloader, excluding save data from the current bootloader. */ #define DFU_BANK_0_REGION_START CODE_REGION_1_START /**< Bank 0 region start. */ +#define DFU_BANK_1_REGION_START (DFU_BANK_0_REGION_START + DFU_IMAGE_MAX_SIZE_BANKED) /**< Bank 1 region start. */ #define EMPTY_FLASH_MASK 0xFFFFFFFF /**< Bit mask that defines an empty address in flash. */ @@ -150,6 +155,7 @@ typedef struct uint32_t bl_size; /**< Size of the recieved BootLoader. */ uint32_t app_size; /**< Size of the recieved Application. */ uint32_t sd_image_start; /**< Location in flash where the received SoftDevice image is stored. */ + bool restart_into_bootloader; /**< If the chip must be reset and must reenter bootloader mode. */ } dfu_update_status_t; /**@brief Update complete handler type. */ diff --git a/lib/tinycrypt b/lib/tinycrypt new file mode 160000 index 0000000..cf24c90 --- /dev/null +++ b/lib/tinycrypt @@ -0,0 +1 @@ +Subproject commit cf24c907a61c01bc2c4e1ee0ae24457c27a840a2 diff --git a/src/boards/adm_b_nrf52840_1/board.h b/src/boards/adm_b_nrf52840_1/board.h index 49ea04b..34dfa54 100644 --- a/src/boards/adm_b_nrf52840_1/board.h +++ b/src/boards/adm_b_nrf52840_1/board.h @@ -25,43 +25,40 @@ #ifndef ADM_B_NRF52840_1_H #define ADM_B_NRF52840_1_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 19) // Red -//#define LED_SECONDARY_PIN 12 // Blue -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 19) // Red +// #define LED_SECONDARY_PIN 12 // Blue +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 11) -#define BUTTON_2 _PINNUM(0, 12) +#define BUTTON_DFU PINNUM(0, 11) +#define BUTTON_DFU_OTA PINNUM(0, 12) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Atelier-Du-Maker" -#define BLEDIS_MODEL "ADM_B_NRF52840_1" +#define BLEDIS_MANUFACTURER "Atelier-Du-Maker" +#define BLEDIS_MODEL "ADM_B_NRF52840_1" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x009F -#define USB_DESC_CDC_ONLY_PID 0x009F +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x009F +#define USB_DESC_CDC_ONLY_PID 0x009F //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "AtelierDuMaker NRF52840 Breakout" -#define UF2_VOLUME_LABEL "ADM840BOOT" -#define UF2_BOARD_ID "ADM_B_NRF52840_1" -#define UF2_INDEX_URL "https://github.com/Atelier-Du-Maker/HolyIoT_NRF52840" +#define UF2_PRODUCT_NAME "AtelierDuMaker NRF52840 Breakout" +#define UF2_VOLUME_LABEL "ADM840BOOT" +#define UF2_BOARD_ID "ADM_B_NRF52840_1" +#define UF2_INDEX_URL "https://github.com/Atelier-Du-Maker/HolyIoT_NRF52840" #endif // ADM_B_NRF52840_1_H diff --git a/src/boards/ae_bl652_bo/board.h b/src/boards/ae_bl652_bo/board.h index c4b78db..77232d8 100644 --- a/src/boards/ae_bl652_bo/board.h +++ b/src/boards/ae_bl652_bo/board.h @@ -28,27 +28,26 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 17 // LED1 -#define LED_SECONDARY_PIN 19 // LED2 -#define LED_STATE_ON 1 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 17 // LED1 +#define LED_SECONDARY_PIN 19 // LED2 +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 11 // BTN1 -#define BUTTON_2 15 // BTN2 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU 11 // BTN1 +#define BUTTON_DFU_OTA 15 // BTN2 +#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 +#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/aramcon2_badge/board.h b/src/boards/aramcon2_badge/board.h index f651915..cf61be9 100644 --- a/src/boards/aramcon2_badge/board.h +++ b/src/boards/aramcon2_badge/board.h @@ -25,41 +25,38 @@ #ifndef _ARAMCON2_BADGE_H #define _ARAMCON2_BADGE_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 11) // Red +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 11) // Red -#define LED_NEOPIXEL _PINNUM(0, 8) -#define NEOPIXELS_NUMBER 2 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(0, 8) +#define NEOPIXELS_NUMBER 2 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 2) // left Button -#define BUTTON_2 _PINNUM(0, 29) // middle button -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 2) // left Button +#define BUTTON_DFU_OTA PINNUM(0, 29) // middle button +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP // Used as model string in OTA mode -#define BLEDIS_MANUFACTURER "ARAMCON Badge Team" -#define BLEDIS_MODEL "ARAMCON2 Badge" +#define BLEDIS_MANUFACTURER "ARAMCON Badge Team" +#define BLEDIS_MODEL "ARAMCON2 Badge" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x007B -#define USB_DESC_CDC_ONLY_PID 0x007B +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x007B +#define USB_DESC_CDC_ONLY_PID 0x007B //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "ARAMCON2 Badge" -#define UF2_VOLUME_LABEL "ARAMBOOT" -#define UF2_BOARD_ID "nrf52840-ARAMCON2-Badge" -#define UF2_INDEX_URL "https://github.com/aramcon-badge" +#define UF2_PRODUCT_NAME "ARAMCON2 Badge" +#define UF2_VOLUME_LABEL "ARAMBOOT" +#define UF2_BOARD_ID "nrf52840-ARAMCON2-Badge" +#define UF2_INDEX_URL "https://github.com/aramcon-badge" #endif // _ARAMCON2_BADGE_H diff --git a/src/boards/aramcon_badge_2019/board.h b/src/boards/aramcon_badge_2019/board.h index 3dc666d..b81fdbd 100644 --- a/src/boards/aramcon_badge_2019/board.h +++ b/src/boards/aramcon_badge_2019/board.h @@ -26,43 +26,40 @@ #ifndef _ARAMCON_BADGE_2019_H #define _ARAMCON_BADGE_2019_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 11) // Red +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 11) // Red -#define LED_NEOPIXEL _PINNUM(0, 8) -#define NEOPIXELS_NUMBER 4 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(0, 8) +#define NEOPIXELS_NUMBER 4 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 2) // left Button -#define BUTTON_2 _PINNUM(0, 29) // middle button -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 2) // left Button +#define BUTTON_DFU_OTA PINNUM(0, 29) // middle button +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "ARAMCON Badge Team" -#define BLEDIS_MODEL "ARAMCON Badge 2019" +#define BLEDIS_MANUFACTURER "ARAMCON Badge Team" +#define BLEDIS_MODEL "ARAMCON Badge 2019" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0079 -#define USB_DESC_CDC_ONLY_PID 0x0079 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0079 +#define USB_DESC_CDC_ONLY_PID 0x0079 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "ARAMCON Badge 2019" -#define UF2_VOLUME_LABEL "ARAMBOOT" -#define UF2_BOARD_ID "nrf52840-ARAMCON-Badge-2019" -#define UF2_INDEX_URL "https://github.com/aramcon-badge" +#define UF2_PRODUCT_NAME "ARAMCON Badge 2019" +#define UF2_VOLUME_LABEL "ARAMBOOT" +#define UF2_BOARD_ID "nrf52840-ARAMCON-Badge-2019" +#define UF2_INDEX_URL "https://github.com/aramcon-badge" #endif // _ARAMCON_BADGE_2019_H diff --git a/src/boards/arcade_feather_nrf52840_express/board.h b/src/boards/arcade_feather_nrf52840_express/board.h deleted file mode 100644 index aed04ed..0000000 --- a/src/boards/arcade_feather_nrf52840_express/board.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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 _ARCARDE_FEATHER_NRF52840_H -#define _ARCARDE_FEATHER_NRF52840_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 nRF52840 Express" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0029 -#define USB_DESC_CDC_ONLY_PID 0x002A - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Express" -#define UF2_VOLUME_LABEL "ARCADE-N4" -#define UF2_BOARD_ID "nRF52840-Feather-revD" -#define UF2_INDEX_URL "https://www.adafruit.com/product/4062" - -#endif // _ARCARDE_FEATHER_NRF52840_H - diff --git a/src/boards/arcade_feather_nrf52840_express/pinconfig.c b/src/boards/arcade_feather_nrf52840_express/pinconfig.c deleted file mode 100644 index 5424d86..0000000 --- a/src/boards/arcade_feather_nrf52840_express/pinconfig.c +++ /dev/null @@ -1,62 +0,0 @@ -#include "boards.h" - -__attribute__((used, section(".bootloaderConfig"))) -const uint32_t bootloaderConfig[] = { - /* CF2 START */ - 513675505, 539130489, // magic - 49, 100, // used entries, total entries - 4, 0x18, // PIN_BTN_A = PIN_RX - 5, 0xa, // PIN_BTN_B = PIN_D2 - 13, 0x29, // PIN_LED = PIN_D13 - 18, 0xf, // PIN_MISO = PA15 - 19, 0xd, // PIN_MOSI = PA13 - 20, 0x23, // PIN_NEOPIXEL = PB03 - 21, 0x18, // PIN_RX = PA24 - 23, 0xe, // PIN_SCK = PA14 - 24, 0xb, // PIN_SCL = PA11 - 25, 0xc, // PIN_SDA = PA12 - 28, 0x19, // PIN_TX = PA25 - 32, 0xe, // PIN_DISPLAY_SCK = PIN_SCK - 34, 0xd, // PIN_DISPLAY_MOSI = PIN_MOSI - 35, 0x1e, // PIN_DISPLAY_CS = PIN_A2 - 36, 0x1c, // PIN_DISPLAY_DC = PIN_A3 - 37, 0xa0, // DISPLAY_WIDTH = 160 - 38, 0x80, // DISPLAY_HEIGHT = 128 - 39, 0x80, // DISPLAY_CFG0 = 0x80 - 40, 0x603, // DISPLAY_CFG1 = 0x603 - 41, 0x20, // DISPLAY_CFG2 = 0x20 - 43, 0x2, // PIN_DISPLAY_RST = PIN_A4 - 44, 0x3, // PIN_DISPLAY_BL = PIN_A5 - 47, 0x6, // PIN_BTN_LEFT = PIN_D11 - 48, 0x1a, // PIN_BTN_RIGHT = PIN_D9 - 49, 0x1b, // PIN_BTN_UP = PIN_D10 - 50, 0x7, // PIN_BTN_DOWN = PIN_D6 - 51, 0x8, // PIN_BTN_MENU = PIN_D12 - 56, 0x2a, // PIN_LED2 = PB10 - 60, 0x19, // PIN_JACK_TX = PIN_TX - 100, 0x4, // PIN_A0 = PA04 - 101, 0x5, // PIN_A1 = PA05 - 102, 0x1e, // PIN_A2 = PA30 - 103, 0x1c, // PIN_A3 = PA28 - 104, 0x2, // PIN_A4 = PA02 - 105, 0x3, // PIN_A5 = PA03 - 152, 0xa, // PIN_D2 = PA10 - 155, 0x28, // PIN_D5 = PB08 - 156, 0x7, // PIN_D6 = PA07 - 159, 0x1a, // PIN_D9 = PA26 - 160, 0x1b, // PIN_D10 = PA27 - 161, 0x6, // PIN_D11 = PA06 - 162, 0x8, // PIN_D12 = PA08 - 163, 0x29, // PIN_D13 = PB09 - 200, 0x1, // NUM_NEOPIXELS = 1 - 204, 0x100000, // FLASH_BYTES = 0x100000 - 205, 0x40000, // RAM_BYTES = 0x40000 - 208, 0xd7688ea1, // BOOTLOADER_BOARD_ID = 0xd7688ea1 - 209, 0xada52840, // UF2_FAMILY = 0xada52840 - 210, 0x20, // PINS_PORT_SIZE = PA_32 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - /* CF2 END */ -}; diff --git a/src/boards/arduino_nano_33_ble/board.h b/src/boards/arduino_nano_33_ble/board.h index 00fb2ef..79e32fc 100644 --- a/src/boards/arduino_nano_33_ble/board.h +++ b/src/boards/arduino_nano_33_ble/board.h @@ -25,40 +25,37 @@ #ifndef _ARDUINOBLE33_NRF52840_H #define _ARDUINOBLE33_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 // red LED -#define LED_PRIMARY_PIN _PINNUM(0, 24) -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 // red LED +#define LED_PRIMARY_PIN PINNUM(0, 24) +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(1, 11) // D2 switch -#define BUTTON_2 _PINNUM(1, 12) // D3 switch -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 11) // D2 switch +#define BUTTON_DFU_OTA PINNUM(1, 12) // D3 switch +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Arduino" -#define BLEDIS_MODEL "Nano 33 BLE" +#define BLEDIS_MANUFACTURER "Arduino" +#define BLEDIS_MODEL "Nano 33 BLE" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0063 -#define USB_DESC_CDC_ONLY_PID 0x0064 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0063 +#define USB_DESC_CDC_ONLY_PID 0x0064 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Arduino Nano 33 BLE" -#define UF2_VOLUME_LABEL "NANO33BOOT" -#define UF2_BOARD_ID "nRF52840-Nano-33" -#define UF2_INDEX_URL "https://www.arduino.cc/" +#define UF2_PRODUCT_NAME "Arduino Nano 33 BLE" +#define UF2_VOLUME_LABEL "NANO33BOOT" +#define UF2_BOARD_ID "nRF52840-Nano-33" +#define UF2_INDEX_URL "https://www.arduino.cc/" #endif // _ITSY_NRF52840_H diff --git a/src/boards/bast_ble/board.h b/src/boards/bast_ble/board.h index fb6e8cb..68a1ea7 100644 --- a/src/boards/bast_ble/board.h +++ b/src/boards/bast_ble/board.h @@ -25,40 +25,38 @@ #ifndef _BASTBLE_NRF52840_H #define _BASTBLE_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 // red LED -#define LED_PRIMARY_PIN _PINNUM(0, 24) -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 // red LED +#define LED_PRIMARY_PIN PINNUM(0, 24) +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 05) -#define BUTTON_2 _PINNUM(0, 10) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 05) +#define BUTTON_DFU_OTA PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "ElectronicCats" -#define BLEDIS_MODEL "BastBLE" +#define BLEDIS_MANUFACTURER "ElectronicCats" +#define BLEDIS_MODEL "BastBLE" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ // Shared VID/PID with Feather nRF52840, will be disabled for building in the future -#define USB_DESC_VID 0x1209 -#define USB_DESC_UF2_PID 0x805A -#define USB_DESC_CDC_ONLY_PID 0x805A +#define USB_DESC_VID 0x1209 +#define USB_DESC_UF2_PID 0x805A +#define USB_DESC_CDC_ONLY_PID 0x805A -#define UF2_PRODUCT_NAME "Bast BLE" -#define UF2_VOLUME_LABEL "BASTBLE" -#define UF2_BOARD_ID "Bast-ble-v1" -#define UF2_INDEX_URL "https://www.electroniccats.com" +#define UF2_PRODUCT_NAME "Bast BLE" +#define UF2_VOLUME_LABEL "BASTBLE" +#define UF2_BOARD_ID "Bast-ble-v1" +#define UF2_INDEX_URL "https://www.electroniccats.com" #endif // _BASTBLE_NRF52840_H diff --git a/src/boards/bluemicro_nrf52833/board.h b/src/boards/bluemicro_nrf52833/board.h index 9b647c3..454d340 100644 --- a/src/boards/bluemicro_nrf52833/board.h +++ b/src/boards/bluemicro_nrf52833/board.h @@ -25,45 +25,42 @@ #ifndef _BLUEMICRO_NRF52833_H #define _BLUEMICRO_NRF52833_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 4) -#define LED_SECONDARY_PIN _PINNUM(0, 25) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN PINNUM(1, 4) +#define LED_SECONDARY_PIN PINNUM(0, 25) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(0, 7) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(0, 7) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 // none connected at all -#define BUTTON_1 _PINNUM(0, 18) // unusable: RESET -#define BUTTON_2 _PINNUM(1, 1) // no connection on E73-2G4M08S1E Module -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 18) // unusable: RESET +#define BUTTON_DFU_OTA PINNUM(1, 1) // no connection on E73-2G4M08S1E Module +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "BlueMicro" -#define BLEDIS_MODEL "BlueMicro 833" +#define BLEDIS_MANUFACTURER "BlueMicro" +#define BLEDIS_MODEL "BlueMicro 833" //--------------------------------------------------------------------+ // USB PID from openmoko: // PR https://github.com/openmoko/openmoko-usb-oui/pull/34 //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1d50 -#define USB_DESC_UF2_PID 0x616f -#define USB_DESC_CDC_ONLY_PID 0x616f +#define USB_DESC_VID 0x1d50 +#define USB_DESC_UF2_PID 0x616f +#define USB_DESC_CDC_ONLY_PID 0x616f -#define UF2_PRODUCT_NAME "BlueMicro" -#define UF2_VOLUME_LABEL "BLUEMICRO" -#define UF2_BOARD_ID "nRF52833-BlueMicro-v1" -#define UF2_INDEX_URL "http://bluemicro.jpconstantineau.com/" +#define UF2_PRODUCT_NAME "BlueMicro" +#define UF2_VOLUME_LABEL "BLUEMICRO" +#define UF2_BOARD_ID "nRF52833-BlueMicro-v1" +#define UF2_INDEX_URL "http://bluemicro.jpconstantineau.com/" #endif // _BLUEMICRO_H diff --git a/src/boards/bluemicro_nrf52840/board.h b/src/boards/bluemicro_nrf52840/board.h index 393e538..46a2ef0 100644 --- a/src/boards/bluemicro_nrf52840/board.h +++ b/src/boards/bluemicro_nrf52840/board.h @@ -25,41 +25,38 @@ #ifndef _BLUEMICRO_NRF52840_H #define _BLUEMICRO_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 4) -#define LED_SECONDARY_PIN _PINNUM(1, 10) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN PINNUM(1, 4) +#define LED_SECONDARY_PIN PINNUM(1, 10) +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 // none connected at all -#define BUTTON_1 _PINNUM(0, 18) // unusable: RESET -#define BUTTON_2 _PINNUM(1, 1) // no connection on E73-2G4M08S1C Module -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 18) // unusable: RESET +#define BUTTON_DFU_OTA PINNUM(1, 1) // no connection on E73-2G4M08S1C Module +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "BlueMicro" -#define BLEDIS_MODEL "BlueMicro 840" +#define BLEDIS_MANUFACTURER "BlueMicro" +#define BLEDIS_MODEL "BlueMicro 840" //--------------------------------------------------------------------+ // USB PID from openmoko: // Approved PR https://github.com/openmoko/openmoko-usb-oui/pull/20 //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1d50 -#define USB_DESC_UF2_PID 0x6160 -#define USB_DESC_CDC_ONLY_PID 0x6160 +#define USB_DESC_VID 0x1d50 +#define USB_DESC_UF2_PID 0x6160 +#define USB_DESC_CDC_ONLY_PID 0x6160 -#define UF2_PRODUCT_NAME "BlueMicro" -#define UF2_VOLUME_LABEL "BLUEMICRO" -#define UF2_BOARD_ID "nRF52840-BlueMicro-v1" -#define UF2_INDEX_URL "http://bluemicro.jpconstantineau.com/" +#define UF2_PRODUCT_NAME "BlueMicro" +#define UF2_VOLUME_LABEL "BLUEMICRO" +#define UF2_BOARD_ID "nRF52840-BlueMicro-v1" +#define UF2_INDEX_URL "http://bluemicro.jpconstantineau.com/" #endif // _BLUEMICRO_H diff --git a/src/boards/boards.c b/src/boards/boards.c index 87842a3..c02a278 100644 --- a/src/boards/boards.c +++ b/src/boards/boards.c @@ -50,6 +50,7 @@ void SysTick_Handler(void) { led_tick(); } +#if defined(BUTTON_DFU) || defined(BUTTON_DFU_OTA) void button_init(uint32_t pin) { if (BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN) { nrf_gpio_cfg_sense_input(pin, BUTTON_PULL, NRF_GPIO_PIN_SENSE_HIGH); @@ -62,6 +63,7 @@ bool button_pressed(uint32_t pin) { uint32_t const active_state = (BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN ? 1 : 0); return nrf_gpio_pin_read(pin) == active_state; } +#endif // This is declared so that a board specific init can be called from here. void __attribute__((weak)) board_init2(void) {} @@ -74,8 +76,12 @@ void board_init(void) { NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_RC; NRF_CLOCK->TASKS_LFCLKSTART = 1UL; +#ifdef BUTTON_DFU button_init(BUTTON_DFU); - button_init(BUTTON_FRESET); +#endif +#ifdef BUTTON_DFU_OTA + button_init(BUTTON_DFU_OTA); +#endif NRFX_DELAY_US(100); // wait for the pin state is stable #if LEDS_NUMBER > 0 diff --git a/src/boards/boards.h b/src/boards/boards.h index 26a3e13..8600119 100644 --- a/src/boards/boards.h +++ b/src/boards/boards.h @@ -31,20 +31,13 @@ #include "nrf.h" #include "nrf_gpio.h" +#define PINNUM(port, pin) ((port) * 32 + (pin)) #include "board.h" #ifndef UF2_VOLUME_LABEL #define UF2_VOLUME_LABEL "NRF52BOOT " #endif -#ifndef BUTTON_DFU -#define BUTTON_DFU BUTTON_1 -#endif - -#ifndef BUTTON_FRESET -#define BUTTON_FRESET BUTTON_2 -#endif - // The primary LED is usually Red but not in all cases. #define LED_PRIMARY 0 // The secondary LED, when available, is usually blue. @@ -104,13 +97,10 @@ void led_tick(void); //--------------------------------------------------------------------+ // BUTTONS //--------------------------------------------------------------------+ -// Make sure we have at least two buttons (DFU + FRESET since DFU+FRST=OTA) -#if BUTTONS_NUMBER < 2 -#error "At least two buttons required in the BSP (see 'BUTTONS_NUMBER')" -#endif - +#if defined(BUTTON_DFU) || defined(BUTTON_DFU_OTA) void button_init(uint32_t pin); bool button_pressed(uint32_t pin); +#endif bool is_ota(void); diff --git a/src/boards/challenger_840_ble/board.h b/src/boards/challenger_840_ble/board.h index 371be08..7be348c 100644 --- a/src/boards/challenger_840_ble/board.h +++ b/src/boards/challenger_840_ble/board.h @@ -1,73 +1,70 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Ha Thach for Adafruit Industries, 2022 Invector Labs - * - * 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 _CHALLENGER_840_BLE_H -#define _CHALLENGER_840_BLE_H - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 12) -#define LED_STATE_ON 1 - -#define LED_NEOPIXEL _PINNUM(1, 8) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 19) -#define BUTTON_2 _PINNUM(0, 8) // Pulls flash cs high -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -/*------------------------------------------------------------------*/ -/* On board LDO control - *------------------------------------------------------------------*/ -#define LDO_CONTROL_PIN _PINNUM(1, 9) // Enables external pwr - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Invector Labs" -#define BLEDIS_MODEL "Challenger 840 BLE" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1209 -#define USB_DESC_UF2_PID 0x7380 -#define USB_DESC_CDC_ONLY_PID 0x7381 - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "ILabs Challenger 840" -#define UF2_VOLUME_LABEL "CH840BOOT" -#define UF2_BOARD_ID "nRF52840-Challenger-840" -#define UF2_INDEX_URL "https://www.ilabs.se" - -#endif // _CHALLENGER_840_BLE_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries, 2022 Invector Labs + * + * 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 _CHALLENGER_840_BLE_H +#define _CHALLENGER_840_BLE_H + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 12) +#define LED_STATE_ON 1 + +#define LED_NEOPIXEL PINNUM(1, 8) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_DFU PINNUM(0, 19) +#define BUTTON_DFU_OTA PINNUM(0, 8) // Pulls flash cs high +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +/*------------------------------------------------------------------*/ +/* On board LDO control + *------------------------------------------------------------------*/ +#define LDO_CONTROL_PIN PINNUM(1, 9) // Enables external pwr + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Invector Labs" +#define BLEDIS_MODEL "Challenger 840 BLE" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x1209 +#define USB_DESC_UF2_PID 0x7380 +#define USB_DESC_CDC_ONLY_PID 0x7381 + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "ILabs Challenger 840" +#define UF2_VOLUME_LABEL "CH840BOOT" +#define UF2_BOARD_ID "nRF52840-Challenger-840" +#define UF2_INDEX_URL "https://www.ilabs.se" + +#endif // _CHALLENGER_840_BLE_H diff --git a/src/boards/circuitplayground_nrf52840/board.h b/src/boards/circuitplayground_nrf52840/board.h index 5544502..82a9bbf 100644 --- a/src/boards/circuitplayground_nrf52840/board.h +++ b/src/boards/circuitplayground_nrf52840/board.h @@ -25,44 +25,41 @@ #ifndef _CPLAY_NRF52840_H #define _CPLAY_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 14) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 14) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(0, 13) -#define NEOPIXELS_NUMBER 10 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(0, 13) +#define NEOPIXELS_NUMBER 10 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(1, 02) // left button -#define BUTTON_2 _PINNUM(1, 15) // right button -#define BUTTON_PULL NRF_GPIO_PIN_PULLDOWN +#define BUTTON_DFU PINNUM(1, 02) // left button +#define BUTTON_DFU_OTA PINNUM(1, 15) // right button +#define BUTTON_PULL NRF_GPIO_PIN_PULLDOWN //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "Circuit Playground nRF52840" +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "Circuit Playground nRF52840" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0045 -#define USB_DESC_CDC_ONLY_PID 0x0045 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0045 +#define USB_DESC_CDC_ONLY_PID 0x0045 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit Circuit Playground nRF52840" -#define UF2_VOLUME_LABEL "CPLAYBTBOOT" -#define UF2_BOARD_ID "nRF52840-CircuitPlayground-revD" -#define UF2_INDEX_URL "https://www.adafruit.com/product/4333" +#define UF2_PRODUCT_NAME "Adafruit Circuit Playground nRF52840" +#define UF2_VOLUME_LABEL "CPLAYBTBOOT" +#define UF2_BOARD_ID "nRF52840-CircuitPlayground-revD" +#define UF2_INDEX_URL "https://www.adafruit.com/product/4333" #endif // _CPLAY_NRF52840_H diff --git a/src/boards/clue_nrf52840/board.h b/src/boards/clue_nrf52840/board.h index 818f2f4..91b8f56 100644 --- a/src/boards/clue_nrf52840/board.h +++ b/src/boards/clue_nrf52840/board.h @@ -25,70 +25,67 @@ #ifndef _CLUE_NRF52840_H #define _CLUE_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 01) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 01) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(0, 16) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#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) // left button -#define BUTTON_2 _PINNUM(1, 10) // right button -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 02) // left button +#define BUTTON_DFU_OTA PINNUM(1, 10) // right button +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // Display //--------------------------------------------------------------------+ #define DISPLAY_CONTROLLER_ST7789 -#define DISPLAY_PIN_SCK _PINNUM(0, 14) -#define DISPLAY_PIN_MOSI _PINNUM(0, 15) +#define DISPLAY_PIN_SCK PINNUM(0, 14) +#define DISPLAY_PIN_MOSI PINNUM(0, 15) -#define DISPLAY_PIN_CS _PINNUM(0, 12) -#define DISPLAY_PIN_DC _PINNUM(0, 13) -#define DISPLAY_PIN_RST _PINNUM(1, 3) -#define DISPLAY_PIN_BL _PINNUM(1, 5) -#define DISPLAY_BL_ON 1 // GPIO state to enable back light +#define DISPLAY_PIN_CS PINNUM(0, 12) +#define DISPLAY_PIN_DC PINNUM(0, 13) +#define DISPLAY_PIN_RST PINNUM(1, 3) +#define DISPLAY_PIN_BL PINNUM(1, 5) +#define DISPLAY_BL_ON 1 // GPIO state to enable back light -#define DISPLAY_WIDTH 240 -#define DISPLAY_HEIGHT 240 +#define DISPLAY_WIDTH 240 +#define DISPLAY_HEIGHT 240 -#define DISPLAY_COL_OFFSET 0 -#define DISPLAY_ROW_OFFSET 80 +#define DISPLAY_COL_OFFSET 0 +#define DISPLAY_ROW_OFFSET 80 // Memory Data Access Control & // Vertical Scroll Start Address -#define DISPLAY_MADCTL (TFT_MADCTL_MY) -#define DISPLAY_VSCSAD 0 +#define DISPLAY_MADCTL (TFT_MADCTL_MY) +#define DISPLAY_VSCSAD 0 -#define DISPLAY_TITLE "CLUE" +#define DISPLAY_TITLE "CLUE" //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "CLUE nRF52840" +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "CLUE nRF52840" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0071 -#define USB_DESC_CDC_ONLY_PID 0x0071 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0071 +#define USB_DESC_CDC_ONLY_PID 0x0071 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit CLUE nRF52840" -#define UF2_VOLUME_LABEL "CLUEBOOT" -#define UF2_BOARD_ID "nRF52840-CLUE-revA" -#define UF2_INDEX_URL "https://www.adafruit.com/product/4500" +#define UF2_PRODUCT_NAME "Adafruit CLUE nRF52840" +#define UF2_VOLUME_LABEL "CLUEBOOT" +#define UF2_BOARD_ID "nRF52840-CLUE-revA" +#define UF2_INDEX_URL "https://www.adafruit.com/product/4500" #endif // _CLUE_NRF52840_H diff --git a/src/boards/ebyte_e104_bt5032a/board.h b/src/boards/ebyte_e104_bt5032a/board.h index da20812..983f5ff 100644 --- a/src/boards/ebyte_e104_bt5032a/board.h +++ b/src/boards/ebyte_e104_bt5032a/board.h @@ -1,66 +1,66 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 Pierre Constantineau - * - * 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 _EBYTE_E104_BT5032A_H -#define _EBYTE_E104_BT5032A_H - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 31 // Red - named "Data" -#define LED_SECONDARY_PIN 30 // Blue - named "Link" (also a red one on the Test Board) -#define LED_STATE_ON 0 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 29 // DISC Button on E104-BT5032A-TB Test Board - // BUTTON_1 is DFU. The module does not have reset circuitry. - // The Test Board from Ebyte (E104-BT5032A-TB) also does not have reset circuitry - // To be able to upload using the Arduino IDE, (To enter DFU mode) - // Press "DISC", press and release "RST", then release "DISC" -#define BUTTON_2 28 // No button - WKP pin -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 14 -#define TX_PIN_NUMBER 18 -#define CTS_PIN_NUMBER 20 -#define RTS_PIN_NUMBER 19 -#define HWFC false // leaving it false to make GPIO available - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "CDEBYTE" -#define BLEDIS_MODEL "E104-BT5032A" - -#define UF2_PRODUCT_NAME "Ebyte E104-BT5032A nRF52832" -#define UF2_INDEX_URL "https://www.ebyte.com/en/product-view-news.html?id=756" - -#endif // _EBYTE_E104_BT5032A_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2021 Pierre Constantineau + * + * 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 _EBYTE_E104_BT5032A_H +#define _EBYTE_E104_BT5032A_H + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 31 // Red - named "Data" +#define LED_SECONDARY_PIN 30 // Blue - named "Link" (also a red one on the Test Board) +#define LED_STATE_ON 0 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_DFU \ + 29 // DISC Button on E104-BT5032A-TB Test Board + // BUTTON_DFU is DFU. The module does not have reset circuitry. + // The Test Board from Ebyte (E104-BT5032A-TB) also does not have reset circuitry + // To be able to upload using the Arduino IDE, (To enter DFU mode) + // Press "DISC", press and release "RST", then release "DISC" +#define BUTTON_DFU_OTA 28 // No button - WKP pin +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +/*------------------------------------------------------------------*/ +/* UART (only used by nRF52832) + *------------------------------------------------------------------*/ +#define RX_PIN_NUMBER 14 +#define TX_PIN_NUMBER 18 +#define CTS_PIN_NUMBER 20 +#define RTS_PIN_NUMBER 19 +#define HWFC false // leaving it false to make GPIO available + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "CDEBYTE" +#define BLEDIS_MODEL "E104-BT5032A" + +#define UF2_PRODUCT_NAME "Ebyte E104-BT5032A nRF52832" +#define UF2_INDEX_URL "https://www.ebyte.com/en/product-view-news.html?id=756" + +#endif // _EBYTE_E104_BT5032A_H diff --git a/src/boards/ebyte_e73_tbb/board.h b/src/boards/ebyte_e73_tbb/board.h index 30976e6..bd522c5 100644 --- a/src/boards/ebyte_e73_tbb/board.h +++ b/src/boards/ebyte_e73_tbb/board.h @@ -1,67 +1,67 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 Pierre Constantineau - * - * 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 _EBYTE_E73_TBB_H -#define _EBYTE_E73_TBB_H - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 17 // Red - named "LED1" -#define LED_SECONDARY_PIN 18 // Blue - named "LED2" (also a red one on the Test Board) -#define LED_STATE_ON 0 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 14 // BUTTON_1 is DFU. SW1 on E73-TBB Test Board. - // This Test board uses the E73-2G4M04S1B module which contains a nrf52832. - // The module does not have reset circuitry. - // The Test Board from Ebyte (E73-TBB) also does not have reset circuitry - // To be able to upload using the Arduino IDE, (To enter DFU mode) - // Press "SW1", momentarily ground "RST/P0.21", then release "SW1" -#define BUTTON_2 13 // SW2 on board -#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 5 -#define RTS_PIN_NUMBER 7 -#define HWFC false // leaving it false to make GPIO available - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "CDEBYTE" -#define BLEDIS_MODEL "E73-TBB" - -#define UF2_PRODUCT_NAME "Ebyte E73-TBB nRF52832" -#define UF2_INDEX_URL "https://www.ebyte.com/en/product-view-news.aspx?id=889" - -#endif // _EBYTE_E73_TBB_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2021 Pierre Constantineau + * + * 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 _EBYTE_E73_TBB_H +#define _EBYTE_E73_TBB_H + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 17 // Red - named "LED1" +#define LED_SECONDARY_PIN 18 // Blue - named "LED2" (also a red one on the Test Board) +#define LED_STATE_ON 0 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_DFU \ + 14 // BUTTON_DFU is DFU. SW1 on E73-TBB Test Board. + // This Test board uses the E73-2G4M04S1B module which contains a nrf52832. + // The module does not have reset circuitry. + // The Test Board from Ebyte (E73-TBB) also does not have reset circuitry + // To be able to upload using the Arduino IDE, (To enter DFU mode) + // Press "SW1", momentarily ground "RST/P0.21", then release "SW1" +#define BUTTON_DFU_OTA 13 // SW2 on board +#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 5 +#define RTS_PIN_NUMBER 7 +#define HWFC false // leaving it false to make GPIO available + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "CDEBYTE" +#define BLEDIS_MODEL "E73-TBB" + +#define UF2_PRODUCT_NAME "Ebyte E73-TBB nRF52832" +#define UF2_INDEX_URL "https://www.ebyte.com/en/product-view-news.aspx?id=889" + +#endif // _EBYTE_E73_TBB_H diff --git a/src/boards/electronut_labs_papyr/board.h b/src/boards/electronut_labs_papyr/board.h index 2dd931c..69ce72f 100644 --- a/src/boards/electronut_labs_papyr/board.h +++ b/src/boards/electronut_labs_papyr/board.h @@ -30,10 +30,10 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 13 -#define LED_SECONDARY_PIN 14 -#define LED_STATE_ON 0 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 13 +#define LED_SECONDARY_PIN 14 +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON @@ -42,26 +42,25 @@ // App can trigger OTA bootloader by writing DFU_MAGIC_OTA_APPJUM to // GPREGRET register if softdevice is not initialized; or by // writing DFU_MAGIC_OTA_RESET in case softdevice is initialized. -#define BUTTONS_NUMBER 2 -#define BUTTON_1 18 // RESET also by default -#define BUTTON_2 1 // P0.1 not exposed anywhere, FRST n/a -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU 18 // RESET also by default +#define BUTTON_DFU_OTA 1 // P0.1 not exposed anywhere, FRST n/a +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Electronut Labs" -#define BLEDIS_MODEL "Papyr" +#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" +#define UF2_PRODUCT_NAME "Electronut Labs Papyr" +#define UF2_BOARD_ID "nRF52840-Papyr-v1" +#define UF2_INDEX_URL "https://docs.electronut.in/papyr" -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x003B -#define USB_DESC_CDC_ONLY_PID 0x003B +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x003B +#define USB_DESC_CDC_ONLY_PID 0x003B #endif // PPAPYR_H diff --git a/src/boards/feather_nrf52832/board.h b/src/boards/feather_nrf52832/board.h index a31bafa..5e280a1 100644 --- a/src/boards/feather_nrf52832/board.h +++ b/src/boards/feather_nrf52832/board.h @@ -1,62 +1,61 @@ -/* - * 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_NRF52832_H -#define _FEATHER_NRF52832_H - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 17 // Red -#define LED_SECONDARY_PIN 19 // Blue -#define LED_STATE_ON 1 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 20 -#define BUTTON_2 22 -#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 -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "Feather nRF52832" - -#define UF2_PRODUCT_NAME "Adafruit Feather nRF52832" -#define UF2_INDEX_URL "https://www.adafruit.com/product/3406" - -#endif // _FEATHER_NRF52832_H +/* + * 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_NRF52832_H +#define _FEATHER_NRF52832_H + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 17 // Red +#define LED_SECONDARY_PIN 19 // Blue +#define LED_STATE_ON 1 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_DFU 20 +#define BUTTON_DFU_OTA 22 +#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 +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "Feather nRF52832" + +#define UF2_PRODUCT_NAME "Adafruit Feather nRF52832" +#define UF2_INDEX_URL "https://www.adafruit.com/product/3406" + +#endif // _FEATHER_NRF52832_H diff --git a/src/boards/feather_nrf52833_express/board.cmake b/src/boards/feather_nrf52833_express/board.cmake deleted file mode 100644 index cb4f2f9..0000000 --- a/src/boards/feather_nrf52833_express/board.cmake +++ /dev/null @@ -1 +0,0 @@ -set(MCU_VARIANT nrf52833) diff --git a/src/boards/feather_nrf52833_express/board.h b/src/boards/feather_nrf52833_express/board.h deleted file mode 100644 index af0e1ec..0000000 --- a/src/boards/feather_nrf52833_express/board.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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 deleted file mode 100644 index d60ac48..0000000 --- a/src/boards/feather_nrf52833_express/board.mk +++ /dev/null @@ -1 +0,0 @@ -MCU_SUB_VARIANT = nrf52833 diff --git a/src/boards/feather_nrf52840_express/board.h b/src/boards/feather_nrf52840_express/board.h index 49994f0..4fa7c98 100644 --- a/src/boards/feather_nrf52840_express/board.h +++ b/src/boards/feather_nrf52840_express/board.h @@ -1,70 +1,68 @@ -/* - * 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_NRF52840_H -#define _FEATHER_NRF52840_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 NEOPIXEL_POWER_PIN _PINNUM(1, 14) -#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 nRF52840 Express" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0029 -#define USB_DESC_CDC_ONLY_PID 0x002A - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Express" -#define UF2_VOLUME_LABEL "FTHR840BOOT" -#define UF2_BOARD_ID "nRF52840-Feather-revE" -#define UF2_INDEX_URL "https://www.adafruit.com/product/4062" - -#endif // _FEATHER_NRF52840_H +/* + * 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_NRF52840_H +#define _FEATHER_NRF52840_H + + +/*------------------------------------------------------------------*/ +/* 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 NEOPIXEL_POWER_PIN PINNUM(1, 14) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_DFU PINNUM(1, 02) +#define BUTTON_DFU_OTA PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "Feather nRF52840 Express" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0029 +#define USB_DESC_CDC_ONLY_PID 0x002A + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Express" +#define UF2_VOLUME_LABEL "FTHR840BOOT" +#define UF2_BOARD_ID "nRF52840-Feather-revE" +#define UF2_INDEX_URL "https://www.adafruit.com/product/4062" + +#endif // _FEATHER_NRF52840_H diff --git a/src/boards/feather_nrf52840_sense/board.h b/src/boards/feather_nrf52840_sense/board.h index fbaf9bc..e0740fd 100644 --- a/src/boards/feather_nrf52840_sense/board.h +++ b/src/boards/feather_nrf52840_sense/board.h @@ -25,45 +25,42 @@ #ifndef _FEATHER_NRF52840_SENSE_H #define _FEATHER_NRF52840_SENSE_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 9) -#define LED_SECONDARY_PIN _PINNUM(1, 10) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN PINNUM(1, 9) +#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 +#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 +#define BUTTON_DFU PINNUM(1, 02) +#define BUTTON_DFU_OTA PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "Feather nRF52840 Sense" +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "Feather nRF52840 Sense" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0087 -#define USB_DESC_CDC_ONLY_PID 0x0088 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0087 +#define USB_DESC_CDC_ONLY_PID 0x0088 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Sense" -#define UF2_VOLUME_LABEL "FTHRSNSBOOT" -#define UF2_BOARD_ID "nRF52840-Feather-Sense" -#define UF2_INDEX_URL "https://www.adafruit.com/product/4516" +#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Sense" +#define UF2_VOLUME_LABEL "FTHRSNSBOOT" +#define UF2_BOARD_ID "nRF52840-Feather-Sense" +#define UF2_INDEX_URL "https://www.adafruit.com/product/4516" #endif // _FEATHER_NRF52840_SENSE_H diff --git a/src/boards/feather_nrf52840_sense_tft/board.h b/src/boards/feather_nrf52840_sense_tft/board.h index 1fa03bd..2e97e02 100644 --- a/src/boards/feather_nrf52840_sense_tft/board.h +++ b/src/boards/feather_nrf52840_sense_tft/board.h @@ -25,76 +25,73 @@ #ifndef _FEATHER_NRF52840_SENSE_TFT_H #define _FEATHER_NRF52840_SENSE_TFT_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 11) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 11) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(1, 8) -#define NEOPIXEL_POWER_PIN _PINNUM(1, 2) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(1, 8) +#define NEOPIXEL_POWER_PIN PINNUM(1, 2) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(1, 6) -#define BUTTON_2 _PINNUM(1, 10) // DFU pin -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 6) +#define BUTTON_DFU_OTA PINNUM(1, 10) // DFU pin +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // Display //--------------------------------------------------------------------+ // VSensor required to power the display -#define DISPLAY_VSENSOR_PIN _PINNUM(1, 7) -#define DISPLAY_VSENSOR_ON 1 +#define DISPLAY_VSENSOR_PIN PINNUM(1, 7) +#define DISPLAY_VSENSOR_ON 1 #define DISPLAY_CONTROLLER_ST7789 -#define DISPLAY_PIN_SCK _PINNUM(0, 26) -#define DISPLAY_PIN_MOSI _PINNUM(0, 5) +#define DISPLAY_PIN_SCK PINNUM(0, 26) +#define DISPLAY_PIN_MOSI PINNUM(0, 5) -#define DISPLAY_PIN_CS _PINNUM(1, 5) -#define DISPLAY_PIN_DC _PINNUM(1, 1) -#define DISPLAY_PIN_RST _PINNUM(1, 3) -#define DISPLAY_PIN_BL _PINNUM(0, 27) -#define DISPLAY_BL_ON 1 // GPIO state to enable back light +#define DISPLAY_PIN_CS PINNUM(1, 5) +#define DISPLAY_PIN_DC PINNUM(1, 1) +#define DISPLAY_PIN_RST PINNUM(1, 3) +#define DISPLAY_PIN_BL PINNUM(0, 27) +#define DISPLAY_BL_ON 1 // GPIO state to enable back light -#define DISPLAY_WIDTH 240 -#define DISPLAY_HEIGHT 135 +#define DISPLAY_WIDTH 240 +#define DISPLAY_HEIGHT 135 -#define DISPLAY_COL_OFFSET 53 -#define DISPLAY_ROW_OFFSET 40 +#define DISPLAY_COL_OFFSET 53 +#define DISPLAY_ROW_OFFSET 40 // Memory Data Access Control & // Vertical Scroll Start Address -#define DISPLAY_MADCTL (TFT_MADCTL_MX) -#define DISPLAY_VSCSAD 0 +#define DISPLAY_MADCTL (TFT_MADCTL_MX) +#define DISPLAY_VSCSAD 0 -#define DISPLAY_TITLE "Sense TFT" +#define DISPLAY_TITLE "Sense TFT" //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "Feather nRF52840 Sense TFT" +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "Feather nRF52840 Sense TFT" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0087 -#define USB_DESC_CDC_ONLY_PID 0x0088 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0087 +#define USB_DESC_CDC_ONLY_PID 0x0088 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Sense TFT" -#define UF2_VOLUME_LABEL "SENSTFTBOOT" -#define UF2_BOARD_ID "nRF52840-FeatherSenseTFT-revA" -#define UF2_INDEX_URL "https://www.adafruit.com/product/" +#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Sense TFT" +#define UF2_VOLUME_LABEL "SENSTFTBOOT" +#define UF2_BOARD_ID "nRF52840-FeatherSenseTFT-revA" +#define UF2_INDEX_URL "https://www.adafruit.com/product/" #endif diff --git a/src/boards/ikigaisense_vita/board.h b/src/boards/ikigaisense_vita/board.h index dab28e3..1c95347 100644 --- a/src/boards/ikigaisense_vita/board.h +++ b/src/boards/ikigaisense_vita/board.h @@ -1,69 +1,66 @@ -/* - * 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 _IKIGAISENSE_VITA_NRF52840_H -#define _IKIGAISENSE_VITA_NRF52840_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 "IkigaiSense Technologies" -#define BLEDIS_MODEL "Vita nRF52840" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0093 -#define USB_DESC_CDC_ONLY_PID 0x0093 - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "IkigaiSense Vita nRF52840" -#define UF2_VOLUME_LABEL "ISVITABoot" -#define UF2_BOARD_ID "nRF52840-isVITA-revA" -#define UF2_INDEX_URL "https://github.com/ikigaisense/vita" - -#endif // _IKIGAISENSE_VITA_NRF52840_H +/* + * 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 _IKIGAISENSE_VITA_NRF52840_H +#define _IKIGAISENSE_VITA_NRF52840_H + +/*------------------------------------------------------------------*/ +/* 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 BUTTON_DFU PINNUM(1, 02) +#define BUTTON_DFU_OTA PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "IkigaiSense Technologies" +#define BLEDIS_MODEL "Vita nRF52840" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0093 +#define USB_DESC_CDC_ONLY_PID 0x0093 + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "IkigaiSense Vita nRF52840" +#define UF2_VOLUME_LABEL "ISVITABoot" +#define UF2_BOARD_ID "nRF52840-isVITA-revA" +#define UF2_INDEX_URL "https://github.com/ikigaisense/vita" + +#endif // _IKIGAISENSE_VITA_NRF52840_H diff --git a/src/boards/itsybitsy_nrf52840_express/board.h b/src/boards/itsybitsy_nrf52840_express/board.h index a3b6c08..563d5d5 100644 --- a/src/boards/itsybitsy_nrf52840_express/board.h +++ b/src/boards/itsybitsy_nrf52840_express/board.h @@ -25,30 +25,26 @@ #ifndef _ITSYBITSY_NRF52840_H #define _ITSYBITSY_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ #define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 6) +#define LED_PRIMARY_PIN PINNUM(0, 6) #define LED_STATE_ON 1 -#define LED_APA102_CLK _PINNUM(1, 9) -#define LED_APA102_DATA _PINNUM(0, 8) +#define LED_APA102_CLK PINNUM(1, 9) +#define LED_APA102_DATA PINNUM(0, 8) #define LED_APA102_BRIGHTNESS 0x1 #define APA102_NUMBER 1 // For dotstart set to max for colour information is not masked off #define BOARD_RGB_BRIGHTNESS 0xffffffff - /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 29) // user switch -#define BUTTON_2 _PINNUM(1, 02) // D2 breakout +#define BUTTON_DFU PINNUM(0, 29) // user switch +#define BUTTON_DFU_OTA PINNUM(1, 02) // D2 breakout #define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ @@ -68,6 +64,6 @@ #define UF2_PRODUCT_NAME "Adafruit ItsyBitsy nRF52840 Express" #define UF2_VOLUME_LABEL "ITSY840BOOT" #define UF2_BOARD_ID "nRF52840-ItsyBitsy-revA" -#define UF2_INDEX_URL "https://www.adafruit.com/" +#define UF2_INDEX_URL "https://www.adafruit.com/product/4481" -#endif // _ITSY_NRF52840_H +#endif diff --git a/src/boards/ledglasses_nrf52840/board.h b/src/boards/ledglasses_nrf52840/board.h index dd676d7..714fe94 100644 --- a/src/boards/ledglasses_nrf52840/board.h +++ b/src/boards/ledglasses_nrf52840/board.h @@ -25,44 +25,41 @@ #ifndef _LEDGLASSES_NRF52840_H #define _LEDGLASSES_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 31) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 31) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(1, 15) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(1, 15) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 30) // user switch -#define BUTTON_2 _PINNUM(0, 28) // NC -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 30) // user switch +#define BUTTON_DFU_OTA PINNUM(0, 28) // NC +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "LED Glasses Driver nRF52840" +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "LED Glasses Driver nRF52840" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x010D -#define USB_DESC_CDC_ONLY_PID 0x010E +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x010D +#define USB_DESC_CDC_ONLY_PID 0x010E //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit LED Glasses Driver nRF52840" -#define UF2_VOLUME_LABEL "GLASSESBOOT" -#define UF2_BOARD_ID "nRF52840-LedGlasses-revA" -#define UF2_INDEX_URL "https://www.adafruit.com/product/5217" +#define UF2_PRODUCT_NAME "Adafruit LED Glasses Driver nRF52840" +#define UF2_VOLUME_LABEL "GLASSESBOOT" +#define UF2_BOARD_ID "nRF52840-LedGlasses-revA" +#define UF2_INDEX_URL "https://www.adafruit.com/product/5217" #endif // _LEDGLASSES_NRF52840_H diff --git a/src/boards/m60_keyboard/board.h b/src/boards/m60_keyboard/board.h index 77371b1..057f1e3 100644 --- a/src/boards/m60_keyboard/board.h +++ b/src/boards/m60_keyboard/board.h @@ -25,52 +25,49 @@ #ifndef _MAKERDIARY_M60_KEYBOARD_H_ #define _MAKERDIARY_M60_KEYBOARD_H_ -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 30) // Red -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 30) // Red +#define LED_STATE_ON 0 -#define LED_RGB_RED_PIN _PINNUM(0, 30) -#define LED_RGB_GREEN_PIN _PINNUM(0, 29) -#define LED_RGB_BLUE_PIN _PINNUM(0, 31) -#define BOARD_RGB_BRIGHTNESS 0x404040 +#define LED_RGB_RED_PIN PINNUM(0, 30) +#define LED_RGB_GREEN_PIN PINNUM(0, 29) +#define LED_RGB_BLUE_PIN PINNUM(0, 31) +#define BOARD_RGB_BRIGHTNESS 0x404040 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 27) -#define BUTTON_2 _PINNUM(0, 19) // ESC -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 27) +#define BUTTON_DFU_OTA PINNUM(0, 19) // ESC +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP /*------------------------------------------------------------------*/ /* On board regulator control *------------------------------------------------------------------*/ -#define LDO_CONTROL_PIN _PINNUM(0, 28) // Enables external pwr +#define LDO_CONTROL_PIN PINNUM(0, 28) // Enables external pwr //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Makerdiary" -#define BLEDIS_MODEL "M60 Mechanical Keyboard" +#define BLEDIS_MANUFACTURER "Makerdiary" +#define BLEDIS_MODEL "M60 Mechanical Keyboard" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x2886 -#define USB_DESC_UF2_PID 0xF00F -#define USB_DESC_CDC_ONLY_PID 0xF00F +#define USB_DESC_VID 0x2886 +#define USB_DESC_UF2_PID 0xF00F +#define USB_DESC_CDC_ONLY_PID 0xF00F //--------------------------------------------------------------------+ // UF2 //--------------------------------------------------------------------+ -#define UF2_PRODUCT_NAME "MakerDiary M60 Mechanical Keyboard" -#define UF2_VOLUME_LABEL "M60KEYBOARD" -#define UF2_BOARD_ID "M60KEYBOARD" -#define UF2_INDEX_URL "https://wiki.makerdiary.com/m60/" +#define UF2_PRODUCT_NAME "MakerDiary M60 Mechanical Keyboard" +#define UF2_VOLUME_LABEL "M60KEYBOARD" +#define UF2_BOARD_ID "M60KEYBOARD" +#define UF2_INDEX_URL "https://wiki.makerdiary.com/m60/" #endif /* _MAKERDIARY_M60_KEYBOARD_H_ */ diff --git a/src/boards/m60_keyboard/pinconfig.c b/src/boards/m60_keyboard/pinconfig.c index 1df7a6f..d831386 100644 --- a/src/boards/m60_keyboard/pinconfig.c +++ b/src/boards/m60_keyboard/pinconfig.c @@ -2,56 +2,60 @@ #include "board.h" #include "uf2/configkeys.h" -__attribute__((used, section(".bootloaderConfig"))) -const uint32_t bootloaderConfig[] = -{ +__attribute__((used, section(".bootloaderConfig"))) const uint32_t bootloaderConfig[] = { /* CF2 START */ - CFG_MAGIC0, CFG_MAGIC1, // magic - 5, 100, // used entries, total entries + CFG_MAGIC0, + CFG_MAGIC1, // magic + 5, + 100, // used entries, total entries - 204, 0x100000, // FLASH_BYTES = 0x100000 - 205, 0x40000, // RAM_BYTES = 0x40000 - 208, (USB_DESC_VID << 16) | USB_DESC_UF2_PID, // BOOTLOADER_BOARD_ID = USB VID+PID, used for verification when updating bootloader via uf2 - 209, 0xada52840, // UF2_FAMILY = 0xada52840 - 210, 0x20, // PINS_PORT_SIZE = PA_32 + 204, + 0x100000, // FLASH_BYTES = 0x100000 + 205, + 0x40000, // RAM_BYTES = 0x40000 + 208, + (USB_DESC_VID << 16) | + USB_DESC_UF2_PID, // BOOTLOADER_BOARD_ID = USB VID+PID, used for verification when updating bootloader via uf2 + 209, + 0xada52840, // UF2_FAMILY = 0xada52840 + 210, + 0x20, // PINS_PORT_SIZE = PA_32 - 0, 0, 0, 0, 0, 0, 0, 0 + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 /* CF2 END */ }; -static void power_on(void) -{ +static void power_on(void) { // Turn on the regulator nrf_gpio_cfg_output(LDO_CONTROL_PIN); nrf_gpio_pin_write(LDO_CONTROL_PIN, 1); } -void board_init2(void) -{ +void board_init2(void) { power_on(); - // configure P0.05 for ESC/BUTTON_2 + // configure P0.05 for ESC/BUTTON_DFU_OTA // P0.05 --- |<- --- / --- P0.19 // diode sw(esc) // mode: output, push-pull, low - nrf_gpio_cfg( - _PINNUM(0, 5), - NRF_GPIO_PIN_DIR_OUTPUT, - NRF_GPIO_PIN_INPUT_DISCONNECT, - NRF_GPIO_PIN_NOPULL, - NRF_GPIO_PIN_H0D1, - NRF_GPIO_PIN_NOSENSE - ); - nrf_gpio_pin_write(_PINNUM(0, 5), 0); + nrf_gpio_cfg(PINNUM(0, 5), NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, + NRF_GPIO_PIN_H0D1, NRF_GPIO_PIN_NOSENSE); + nrf_gpio_pin_write(PINNUM(0, 5), 0); // Wait the buttons stable. // This is mandatory, or the keyboard will enter bootloader whenever - // booted by pressing the button at back (same with BUTTON_1) + // booted by pressing the button at back (same with BUTTON_DFU) NRFX_DELAY_MS(300); } -void board_teardown2(void) -{ +void board_teardown2(void) { // re-enable the battery power_on(); -} \ No newline at end of file +} diff --git a/src/boards/mbn52832dk/board.h b/src/boards/mbn52832dk/board.h index c9fda30..0e38c19 100644 --- a/src/boards/mbn52832dk/board.h +++ b/src/boards/mbn52832dk/board.h @@ -1,63 +1,62 @@ -/* - * 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 _MBN52832DK_H -#define _MBN52832DK_H - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 17 // LED1 -#define LED_SECONDARY_PIN 18 // LED2 -#define LED_STATE_ON 1 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 13 -#define BUTTON_2 14 -#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 -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Murata" -#define BLEDIS_MODEL "MBN52832DK" - -#define UF2_BOARD_ID "nRF52832-MBN52832DK-v1" -#define UF2_PRODUCT_NAME "Murata MBN52832DK" -#define UF2_INDEX_URL "https://www.murata.com/ja-jp/products/connectivitymodule/bluetooth/overview/lineup/mbn52832" - -#endif // _MBN52832DK_H +/* + * 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 _MBN52832DK_H +#define _MBN52832DK_H + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 17 // LED1 +#define LED_SECONDARY_PIN 18 // LED2 +#define LED_STATE_ON 1 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_DFU 13 +#define BUTTON_DFU_OTA 14 +#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 +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Murata" +#define BLEDIS_MODEL "MBN52832DK" + +#define UF2_BOARD_ID "nRF52832-MBN52832DK-v1" +#define UF2_PRODUCT_NAME "Murata MBN52832DK" +#define UF2_INDEX_URL "https://www.murata.com/ja-jp/products/connectivitymodule/bluetooth/overview/lineup/mbn52832" + +#endif // _MBN52832DK_H diff --git a/src/boards/mdk_nrf52840_dongle/board.h b/src/boards/mdk_nrf52840_dongle/board.h index 6528451..ab5d0e1 100644 --- a/src/boards/mdk_nrf52840_dongle/board.h +++ b/src/boards/mdk_nrf52840_dongle/board.h @@ -25,48 +25,45 @@ #ifndef _MDK_NRF52840_DONGLE_H_ #define _MDK_NRF52840_DONGLE_H_ -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 // TODO(gpshead): support 0. -#define LED_PRIMARY_PIN _PINNUM(0, 23) // Red -#define LED_SECONDARY_PIN _PINNUM(0, 24) // Blue -#define LED_STATE_ON 0 +#define LEDS_NUMBER 2 // TODO(gpshead): support 0. +#define LED_PRIMARY_PIN PINNUM(0, 23) // Red +#define LED_SECONDARY_PIN PINNUM(0, 24) // Blue +#define LED_STATE_ON 0 -//#define LED_RGB_RED_PIN _PINNUM(0, 23) -//#define LED_RGB_GREEN_PIN _PINNUM(0, 22) -//#define LED_RGB_BLUE_PIN _PINNUM(0, 24) -#define BOARD_RGB_BRIGHTNESS 0x404040 +// #define LED_RGB_RED_PIN PINNUM(0, 23) +// #define LED_RGB_GREEN_PIN PINNUM(0, 22) +// #define LED_RGB_BLUE_PIN PINNUM(0, 24) +#define BOARD_RGB_BRIGHTNESS 0x404040 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ // TODO(gpshead): simplify, have code support 0. double reset only. -#define BUTTONS_NUMBER 2 // none connected at all -#define BUTTON_1 _PINNUM(0, 18) // unusable: RESET -#define BUTTON_2 _PINNUM(0, 19) // no connection -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 18) // unusable: RESET +#define BUTTON_DFU_OTA PINNUM(0, 19) // no connection +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "MakerDiary" -#define BLEDIS_MODEL "nRF52840 Micro Dev Kit USB Dongle" +#define BLEDIS_MANUFACTURER "MakerDiary" +#define BLEDIS_MODEL "nRF52840 Micro Dev Kit USB Dongle" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ // Shared VID/PID with Feather nRF52840, will be disabled for building in the future -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0029 -#define USB_DESC_CDC_ONLY_PID 0x0029 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0029 +#define USB_DESC_CDC_ONLY_PID 0x0029 -#define UF2_PRODUCT_NAME "MDK nRF52840 USB Dongle" -#define UF2_VOLUME_LABEL "MDK840DONGL" -#define UF2_BOARD_ID "nRF52840-Dongle-v1" -#define UF2_INDEX_URL "https://wiki.makerdiary.com/nrf52840-mdk-usb-dongle/" +#define UF2_PRODUCT_NAME "MDK nRF52840 USB Dongle" +#define UF2_VOLUME_LABEL "MDK840DONGL" +#define UF2_BOARD_ID "nRF52840-Dongle-v1" +#define UF2_INDEX_URL "https://wiki.makerdiary.com/nrf52840-mdk-usb-dongle/" #endif /* _MDK_NRF52840_DONGLE_H_ */ diff --git a/src/boards/metro_nrf52840_express/board.h b/src/boards/metro_nrf52840_express/board.h index 0b47a1c..0c05838 100644 --- a/src/boards/metro_nrf52840_express/board.h +++ b/src/boards/metro_nrf52840_express/board.h @@ -25,46 +25,43 @@ #ifndef _METRO_NRF52840_H_ #define _METRO_NRF52840_H_ -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 13) -#define LED_SECONDARY_PIN _PINNUM(1, 15) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN PINNUM(1, 13) +#define LED_SECONDARY_PIN PINNUM(1, 15) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(0, 13) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(0, 13) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(1, 0) -#define BUTTON_2 _PINNUM(2, 2) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 0) +#define BUTTON_DFU_OTA PINNUM(2, 2) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "Metro nRF52840 Express" +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "Metro nRF52840 Express" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x003F -#define USB_DESC_CDC_ONLY_PID 0x0040 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x003F +#define USB_DESC_CDC_ONLY_PID 0x0040 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit Metro nRF52840 Express" -#define UF2_VOLUME_LABEL "METR840BOOT" -#define UF2_BOARD_ID "nRF52840-Metro-revA" +#define UF2_PRODUCT_NAME "Adafruit Metro nRF52840 Express" +#define UF2_VOLUME_LABEL "METR840BOOT" +#define UF2_BOARD_ID "nRF52840-Metro-revA" -#define UF2_INDEX_URL "https://www.adafruit.com/" +#define UF2_INDEX_URL "https://www.adafruit.com/" #endif /* _METRO_NRF52840_H_ */ diff --git a/src/boards/mikoto/board.h b/src/boards/mikoto/board.h index 6431f67..9882893 100644 --- a/src/boards/mikoto/board.h +++ b/src/boards/mikoto/board.h @@ -25,41 +25,38 @@ #ifndef _MIKOTO_H #define _MIKOTO_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - #define UICR_REGOUT0_VALUE UICR_REGOUT0_VOUT_3V3 /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 15) // Blue -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 15) // Blue +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 // none connected at all -#define BUTTON_1 _PINNUM(0, 18) // unusable: RESET -#define BUTTON_2 _PINNUM(0, 19) // no connection -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 18) // unusable: RESET +#define BUTTON_DFU_OTA PINNUM(0, 19) // no connection +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "zhiayang" -#define BLEDIS_MODEL "mikoto" +#define BLEDIS_MANUFACTURER "zhiayang" +#define BLEDIS_MODEL "mikoto" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1209 -#define USB_DESC_UF2_PID 0x7A01 -#define USB_DESC_CDC_ONLY_PID 0x7A01 +#define USB_DESC_VID 0x1209 +#define USB_DESC_UF2_PID 0x7A01 +#define USB_DESC_CDC_ONLY_PID 0x7A01 -#define UF2_PRODUCT_NAME "Mikoto nRF52840" -#define UF2_VOLUME_LABEL "MIKOTO-BOOT" -#define UF2_BOARD_ID "nRF52840-mikoto-rev520" -#define UF2_INDEX_URL "https://github.com/zhiayang/mikoto" +#define UF2_PRODUCT_NAME "Mikoto nRF52840" +#define UF2_VOLUME_LABEL "MIKOTO-BOOT" +#define UF2_BOARD_ID "nRF52840-mikoto-rev520" +#define UF2_INDEX_URL "https://github.com/zhiayang/mikoto" #endif // _MIKOTO_H diff --git a/src/boards/nRF52840_connect_kit/board.h b/src/boards/nRF52840_connect_kit/board.h index 3740928..9bb02ab 100644 --- a/src/boards/nRF52840_connect_kit/board.h +++ b/src/boards/nRF52840_connect_kit/board.h @@ -25,47 +25,44 @@ #ifndef _MAKERDIARY_NRF82540_CONNECT_KIT_H_ #define _MAKERDIARY_NRF82540_CONNECT_KIT_H_ -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 15) // Green -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 15) // Green +#define LED_STATE_ON 0 -#define LED_RGB_RED_PIN _PINNUM(1, 10) -#define LED_RGB_GREEN_PIN _PINNUM(1, 11) -#define LED_RGB_BLUE_PIN _PINNUM(1, 12) -#define BOARD_RGB_BRIGHTNESS 0x404040 +#define LED_RGB_RED_PIN PINNUM(1, 10) +#define LED_RGB_GREEN_PIN PINNUM(1, 11) +#define LED_RGB_BLUE_PIN PINNUM(1, 12) +#define BOARD_RGB_BRIGHTNESS 0x404040 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(1, 0) // P1.00: User Button -#define BUTTON_2 _PINNUM(1, 7) // P1.07: NC -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 0) // P1.00: User Button +#define BUTTON_DFU_OTA PINNUM(1, 7) // P1.07: NC +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Makerdiary" -#define BLEDIS_MODEL "nRF52840 Connect Kit" +#define BLEDIS_MANUFACTURER "Makerdiary" +#define BLEDIS_MODEL "nRF52840 Connect Kit" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x2886 -#define USB_DESC_UF2_PID 0xF00F -#define USB_DESC_CDC_ONLY_PID 0xF00F +#define USB_DESC_VID 0x2886 +#define USB_DESC_UF2_PID 0xF00F +#define USB_DESC_CDC_ONLY_PID 0xF00F //--------------------------------------------------------------------+ // UF2 //--------------------------------------------------------------------+ -#define UF2_PRODUCT_NAME "nRF52840 Connect Kit" -#define UF2_VOLUME_LABEL "CONNECTKIT" -#define UF2_BOARD_ID "nRF52840-Connect-Kit" -#define UF2_INDEX_URL "https://wiki.makerdiary.com/nrf52840-connectkit/" +#define UF2_PRODUCT_NAME "nRF52840 Connect Kit" +#define UF2_VOLUME_LABEL "CONNECTKIT" +#define UF2_BOARD_ID "nRF52840-Connect-Kit" +#define UF2_INDEX_URL "https://wiki.makerdiary.com/nrf52840-connectkit/" #endif /* _MAKERDIARY_NRF82540_CONNECT_KIT_H_ */ diff --git a/src/boards/nice_nano/board.h b/src/boards/nice_nano/board.h index 0ec4cde..3196ae1 100644 --- a/src/boards/nice_nano/board.h +++ b/src/boards/nice_nano/board.h @@ -25,41 +25,36 @@ #ifndef _NICENANO_H #define _NICENANO_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - #define UICR_REGOUT0_VALUE UICR_REGOUT0_VOUT_3V3 /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 15) // Blue -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 15) // Blue +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 // none connected at all -#define BUTTON_1 _PINNUM(0, 18) // unusable: RESET -#define BUTTON_2 _PINNUM(0, 19) // no connection -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +// This board has no buttons //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Nice Keyboards" -#define BLEDIS_MODEL "nice!nano" +#define BLEDIS_MANUFACTURER "Nice Keyboards" +#define BLEDIS_MODEL "nice!nano" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x00B3 -#define USB_DESC_CDC_ONLY_PID 0x00B3 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x00B3 +#define USB_DESC_CDC_ONLY_PID 0x00B3 -#define UF2_PRODUCT_NAME "nice!nano" -#define UF2_VOLUME_LABEL "NICENANO" -#define UF2_BOARD_ID "nRF52840-nicenano" -#define UF2_INDEX_URL "https://nicekeyboards.com/docs/nice-nano" +#define UF2_PRODUCT_NAME "nice!nano" +#define UF2_VOLUME_LABEL "NICENANO" +#define UF2_BOARD_ID "nRF52840-nicenano" +#define UF2_INDEX_URL "https://nicekeyboards.com/docs/nice-nano" #endif // _NICENANO_H diff --git a/src/boards/nrf52840_bboard/board.h b/src/boards/nrf52840_bboard/board.h index 515201d..2c1977e 100644 --- a/src/boards/nrf52840_bboard/board.h +++ b/src/boards/nrf52840_bboard/board.h @@ -25,14 +25,12 @@ #ifndef _NRF52840_BBOARD_H #define _NRF52840_BBOARD_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 7) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 7) +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON @@ -41,28 +39,27 @@ // App can trigger OTA bootloader by writing DFU_MAGIC_OTA_APPJUM to // GPREGRET register if softdevice is not initialized; or by // writing DFU_MAGIC_OTA_RESET in case softdevice is initialized. -#define BUTTONS_NUMBER 2 -#define BUTTON_1 18 // RESET also by default -#define BUTTON_2 1 // P0.1 not exposed anywhere, FRST n/a -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU 18 // RESET also by default +#define BUTTON_DFU_OTA 1 // P0.1 not exposed anywhere, FRST n/a +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "ddB0515" -#define BLEDIS_MODEL "nRF52840 BBoard" +#define BLEDIS_MANUFACTURER "ddB0515" +#define BLEDIS_MODEL "nRF52840 BBoard" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1d50 -#define USB_DESC_UF2_PID 0x6157 -#define USB_DESC_CDC_ONLY_PID 0x6157 +#define USB_DESC_VID 0x1d50 +#define USB_DESC_UF2_PID 0x6157 +#define USB_DESC_CDC_ONLY_PID 0x6157 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "nRF52840 BBoard" -#define UF2_VOLUME_LABEL "BBOARDBOOT" -#define UF2_BOARD_ID "nRF52840-BBoard-rev2" -#define UF2_INDEX_URL "https://github.com/ddB0515/nRF52840-BBoard" +#define UF2_PRODUCT_NAME "nRF52840 BBoard" +#define UF2_VOLUME_LABEL "BBOARDBOOT" +#define UF2_BOARD_ID "nRF52840-BBoard-rev2" +#define UF2_INDEX_URL "https://github.com/ddB0515/nRF52840-BBoard" #endif // _NRF52840_BBOARD_H diff --git a/src/boards/nrf52840_m2/board.h b/src/boards/nrf52840_m2/board.h index 57265ab..c093f5d 100644 --- a/src/boards/nrf52840_m2/board.h +++ b/src/boards/nrf52840_m2/board.h @@ -25,48 +25,45 @@ #ifndef _MAKERDIARY_NRF52840_M2_H_ #define _MAKERDIARY_NRF52840_M2_H_ -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 30) // Red -#define LED_DOCK_GREEN_PIN _PINNUM(1, 7) // Only available on the M.2 Dock -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 30) // Red +#define LED_DOCK_GREEN_PIN PINNUM(1, 7) // Only available on the M.2 Dock +#define LED_STATE_ON 0 -#define LED_RGB_RED_PIN _PINNUM(0, 30) -#define LED_RGB_GREEN_PIN _PINNUM(0, 29) -#define LED_RGB_BLUE_PIN _PINNUM(0, 31) -#define BOARD_RGB_BRIGHTNESS 0x404040 +#define LED_RGB_RED_PIN PINNUM(0, 30) +#define LED_RGB_GREEN_PIN PINNUM(0, 29) +#define LED_RGB_BLUE_PIN PINNUM(0, 31) +#define BOARD_RGB_BRIGHTNESS 0x404040 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 19) -#define BUTTON_2 _PINNUM(1, 7) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 19) +#define BUTTON_DFU_OTA PINNUM(1, 7) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Makerdiary" -#define BLEDIS_MODEL "nRF52840 M.2" +#define BLEDIS_MANUFACTURER "Makerdiary" +#define BLEDIS_MODEL "nRF52840 M.2" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x2886 -#define USB_DESC_UF2_PID 0xF00F -#define USB_DESC_CDC_ONLY_PID 0xF00F +#define USB_DESC_VID 0x2886 +#define USB_DESC_UF2_PID 0xF00F +#define USB_DESC_CDC_ONLY_PID 0xF00F //--------------------------------------------------------------------+ // UF2 //--------------------------------------------------------------------+ -#define UF2_PRODUCT_NAME "MakerDiary nRF52840 M.2 Module" -#define UF2_VOLUME_LABEL "nRF52840M2" -#define UF2_BOARD_ID "nRF52840M2" -#define UF2_INDEX_URL "https://wiki.makerdiary.com/nrf52840-m2" +#define UF2_PRODUCT_NAME "MakerDiary nRF52840 M.2 Module" +#define UF2_VOLUME_LABEL "nRF52840M2" +#define UF2_BOARD_ID "nRF52840M2" +#define UF2_INDEX_URL "https://wiki.makerdiary.com/nrf52840-m2" #endif /* _MAKERDIARY_NRF52840_M2_H_ */ diff --git a/src/boards/nrfmicro/board.h b/src/boards/nrfmicro/board.h index c6b2528..78507e3 100644 --- a/src/boards/nrfmicro/board.h +++ b/src/boards/nrfmicro/board.h @@ -1,66 +1,63 @@ -/* - * 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 _NRFMICRO_NRF52840 -#define _NRFMICRO_NRF52840 - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 10) -#define LED_STATE_ON 1 // State when LED is lit (active HIGH) - -#define NEOPIXELS_NUMBER 0 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(1, 2) // DFU -#define BUTTON_2 _PINNUM(0, 12) // FRST -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "nRFMicro" -#define BLEDIS_MODEL "nRFMicro nRF52840" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1209 -#define USB_DESC_UF2_PID 0x5284 -#define USB_DESC_CDC_ONLY_PID 0x5284 - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "nRFMicro" -#define UF2_VOLUME_LABEL "NRFMICRO" -#define UF2_BOARD_ID "nRF52840-nRFMicro-v0" -#define UF2_INDEX_URL "https://github.com/joric/nrfmicro/wiki" - -#endif // _NRFMICRO_NRF52840 +/* + * 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 _NRFMICRO_NRF52840 +#define _NRFMICRO_NRF52840 + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 10) +#define LED_STATE_ON 1 // State when LED is lit (active HIGH) + +#define NEOPIXELS_NUMBER 0 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_DFU PINNUM(1, 2) // DFU +#define BUTTON_DFU_OTA PINNUM(0, 12) // FRST +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "nRFMicro" +#define BLEDIS_MODEL "nRFMicro nRF52840" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x1209 +#define USB_DESC_UF2_PID 0x5284 +#define USB_DESC_CDC_ONLY_PID 0x5284 + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "nRFMicro" +#define UF2_VOLUME_LABEL "NRFMICRO" +#define UF2_BOARD_ID "nRF52840-nRFMicro-v0" +#define UF2_INDEX_URL "https://github.com/joric/nrfmicro/wiki" + +#endif // _NRFMICRO_NRF52840 diff --git a/src/boards/ohs2020_badge/board.h b/src/boards/ohs2020_badge/board.h index 1a62811..a6cc943 100644 --- a/src/boards/ohs2020_badge/board.h +++ b/src/boards/ohs2020_badge/board.h @@ -26,40 +26,37 @@ #ifndef _OHS2020_BADGE_H #define _OHS2020_BADGE_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 04) // fake LED since we have none -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 04) // fake LED since we have none +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 29) // SW2 -#define BUTTON_2 _PINNUM(0, 03) // SW1 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 29) // SW2 +#define BUTTON_DFU_OTA PINNUM(0, 03) // SW1 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "OSHWA" -#define BLEDIS_MODEL "OHS2020 Badge" +#define BLEDIS_MANUFACTURER "OSHWA" +#define BLEDIS_MODEL "OHS2020 Badge" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x007F -#define USB_DESC_CDC_ONLY_PID 0x007F +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x007F +#define USB_DESC_CDC_ONLY_PID 0x007F //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "OHS2020 Badge" -#define UF2_VOLUME_LABEL "BADGEBOOT" -#define UF2_BOARD_ID "OHS2020-Badge-revA" -#define UF2_INDEX_URL "https://2020.oshwa.org/" +#define UF2_PRODUCT_NAME "OHS2020 Badge" +#define UF2_VOLUME_LABEL "BADGEBOOT" +#define UF2_BOARD_ID "OHS2020-Badge-revA" +#define UF2_INDEX_URL "https://2020.oshwa.org/" #endif // _OHS2020_BADGE_H diff --git a/src/boards/omnimo_nrf52840/board.h b/src/boards/omnimo_nrf52840/board.h index 0a3b710..c26c811 100644 --- a/src/boards/omnimo_nrf52840/board.h +++ b/src/boards/omnimo_nrf52840/board.h @@ -1,72 +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 _OMNIMO_NRF52840_H -#define _OMNIMO_NRF52840_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(1, 07) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "eAFAQ" -#define BLEDIS_MODEL "OMNIMO nRF52840" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ - -//Shared VID/PID with pca10056 -#define USB_DESC_VID 0x1209 -#define USB_DESC_UF2_PID 0xCECE -#define USB_DESC_CDC_ONLY_PID 0xCECE - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Omnimo nRF52840" -#define UF2_VOLUME_LABEL "OMNIn52BOOT" -#define UF2_BOARD_ID "nRF52840-Omnimo" -#define UF2_INDEX_URL "https://www.crowdsupply.com/eafaq/omnimo-nrf52840" - -#endif // _OMNIMO_NRF52840_H +/* + * 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 _OMNIMO_NRF52840_H +#define _OMNIMO_NRF52840_H + +/*------------------------------------------------------------------*/ +/* 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 BUTTON_DFU PINNUM(1, 02) +#define BUTTON_DFU_OTA PINNUM(1, 07) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "eAFAQ" +#define BLEDIS_MODEL "OMNIMO nRF52840" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ + +// Shared VID/PID with pca10056 +#define USB_DESC_VID 0x1209 +#define USB_DESC_UF2_PID 0xCECE +#define USB_DESC_CDC_ONLY_PID 0xCECE + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "Omnimo nRF52840" +#define UF2_VOLUME_LABEL "OMNIn52BOOT" +#define UF2_BOARD_ID "nRF52840-Omnimo" +#define UF2_INDEX_URL "https://www.crowdsupply.com/eafaq/omnimo-nrf52840" + +#endif // _OMNIMO_NRF52840_H diff --git a/src/boards/particle_argon/board.h b/src/boards/particle_argon/board.h index 1f31d93..b210606 100644 --- a/src/boards/particle_argon/board.h +++ b/src/boards/particle_argon/board.h @@ -1,70 +1,67 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 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. - */ - -#ifndef _PARTICLE_ARGON_H -#define _PARTICLE_ARGON_H - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#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 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_DFU _PINNUM(0, 11) -#define BUTTON_FRESET _PINNUM(0, 03) // A0 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Particle Industries" -#define BLEDIS_MODEL "Argon" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ - -// Shared VID/PID with pca10056 -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x00DA -#define USB_DESC_CDC_ONLY_PID 0x00DA - -#define UF2_PRODUCT_NAME "Particle Argon" -#define UF2_VOLUME_LABEL "ARGONBOOT " -#define UF2_BOARD_ID "nRF52840-Argon-v1" -#define UF2_INDEX_URL "https://www.particle.io/mesh/" - -#endif // _PARTICLE_ARGON_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 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. + */ + +#ifndef _PARTICLE_ARGON_H +#define _PARTICLE_ARGON_H + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#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 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_DFU PINNUM(0, 11) +#define BUTTON_DFU_OTA PINNUM(0, 03) // A0 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Particle Industries" +#define BLEDIS_MODEL "Argon" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ + +// Shared VID/PID with pca10056 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x00DA +#define USB_DESC_CDC_ONLY_PID 0x00DA + +#define UF2_PRODUCT_NAME "Particle Argon" +#define UF2_VOLUME_LABEL "ARGONBOOT " +#define UF2_BOARD_ID "nRF52840-Argon-v1" +#define UF2_INDEX_URL "https://www.particle.io/mesh/" + +#endif // _PARTICLE_ARGON_H diff --git a/src/boards/particle_boron/board.h b/src/boards/particle_boron/board.h index ee5236a..49cc6d5 100644 --- a/src/boards/particle_boron/board.h +++ b/src/boards/particle_boron/board.h @@ -1,70 +1,67 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 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. - */ - -#ifndef _PARTICLE_BORON_H -#define _PARTICLE_BORON_H - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#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 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_DFU _PINNUM(0, 11) -#define BUTTON_FRESET _PINNUM(0, 03) // A0 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Particle Industries" -#define BLEDIS_MODEL "Boron" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ - -// Shared VID/PID with pca10056 -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x00DA -#define USB_DESC_CDC_ONLY_PID 0x00DA - -#define UF2_PRODUCT_NAME "Particle Boron" -#define UF2_VOLUME_LABEL "BORONBOOT " -#define UF2_BOARD_ID "nRF52840-Boron-v1" -#define UF2_INDEX_URL "https://www.particle.io/mesh/" - -#endif // _PARTICLE_BORON_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 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. + */ + +#ifndef _PARTICLE_BORON_H +#define _PARTICLE_BORON_H + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#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 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_DFU PINNUM(0, 11) +#define BUTTON_DFU_OTA PINNUM(0, 03) // A0 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Particle Industries" +#define BLEDIS_MODEL "Boron" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ + +// Shared VID/PID with pca10056 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x00DA +#define USB_DESC_CDC_ONLY_PID 0x00DA + +#define UF2_PRODUCT_NAME "Particle Boron" +#define UF2_VOLUME_LABEL "BORONBOOT " +#define UF2_BOARD_ID "nRF52840-Boron-v1" +#define UF2_INDEX_URL "https://www.particle.io/mesh/" + +#endif // _PARTICLE_BORON_H diff --git a/src/boards/particle_xenon/board.h b/src/boards/particle_xenon/board.h index 3c77828..5584bad 100644 --- a/src/boards/particle_xenon/board.h +++ b/src/boards/particle_xenon/board.h @@ -1,70 +1,67 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 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. - */ - -#ifndef _PARTICLE_XENON_H -#define _PARTICLE_XENON_H - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#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 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_DFU _PINNUM(0, 11) -#define BUTTON_FRESET _PINNUM(0, 03) // A0 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Particle Industries" -#define BLEDIS_MODEL "Xenon" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ - -// Shared VID/PID with pca10056 -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x00DA -#define USB_DESC_CDC_ONLY_PID 0x00DA - -#define UF2_PRODUCT_NAME "Particle Xenon" -#define UF2_VOLUME_LABEL "XENONBOOT " -#define UF2_BOARD_ID "nRF52840-Xenon-v1" -#define UF2_INDEX_URL "https://www.particle.io/mesh/" - -#endif // _PARTICLE_XENON_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 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. + */ + +#ifndef _PARTICLE_XENON_H +#define _PARTICLE_XENON_H + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#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 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_DFU PINNUM(0, 11) +#define BUTTON_DFU_OTA PINNUM(0, 03) // A0 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Particle Industries" +#define BLEDIS_MODEL "Xenon" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ + +// Shared VID/PID with pca10056 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x00DA +#define USB_DESC_CDC_ONLY_PID 0x00DA + +#define UF2_PRODUCT_NAME "Particle Xenon" +#define UF2_VOLUME_LABEL "XENONBOOT " +#define UF2_BOARD_ID "nRF52840-Xenon-v1" +#define UF2_INDEX_URL "https://www.particle.io/mesh/" + +#endif // _PARTICLE_XENON_H diff --git a/src/boards/pca10056/board.h b/src/boards/pca10056/board.h index 51dc2fb..08269bf 100644 --- a/src/boards/pca10056/board.h +++ b/src/boards/pca10056/board.h @@ -28,36 +28,35 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 13 -#define LED_SECONDARY_PIN 14 -#define LED_STATE_ON 0 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 13 +#define LED_SECONDARY_PIN 14 +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 11 -#define BUTTON_2 12 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU 11 +#define BUTTON_DFU_OTA 12 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Nordic" -#define BLEDIS_MODEL "PCA10056" +#define BLEDIS_MANUFACTURER "Nordic" +#define BLEDIS_MODEL "PCA10056" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ // Shared VID/PID with Feather nRF52840, will be disabled for building in the future -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x00DA -#define USB_DESC_CDC_ONLY_PID 0x00DA +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x00DA +#define USB_DESC_CDC_ONLY_PID 0x00DA -#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" +#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" #endif // PCA10056_H diff --git a/src/boards/pca10059/board.h b/src/boards/pca10059/board.h index 8b2d89d..88c2f41 100644 --- a/src/boards/pca10059/board.h +++ b/src/boards/pca10059/board.h @@ -25,42 +25,39 @@ #ifndef PCA10059_H #define PCA10059_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ #define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 6 // Red +#define LED_PRIMARY_PIN 6 // Red #define LED_SECONDARY_PIN 12 // Blue #define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(1, 6) -#define BUTTON_2 _PINNUM(1, 10) +#define BUTTON_DFU PINNUM(1, 6) +#define BUTTON_DFU_OTA PINNUM(1, 10) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Nordic" -#define BLEDIS_MODEL "PCA10059" +#define BLEDIS_MANUFACTURER "Nordic" +#define BLEDIS_MODEL "PCA10059" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ // Shared VID/PID with Feather nRF52840, will be disabled for building in the future -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0029 -#define USB_DESC_CDC_ONLY_PID 0x0029 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0029 +#define USB_DESC_CDC_ONLY_PID 0x0029 -#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" +#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" #endif // PCA10059_H diff --git a/src/boards/pca10100/board.h b/src/boards/pca10100/board.h index e96b11c..5be1366 100644 --- a/src/boards/pca10100/board.h +++ b/src/boards/pca10100/board.h @@ -28,35 +28,34 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 13 -#define LED_SECONDARY_PIN 14 -#define LED_STATE_ON 0 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 13 +#define LED_SECONDARY_PIN 14 +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 11 -#define BUTTON_2 12 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU 11 +#define BUTTON_DFU_OTA 12 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Nordic" -#define BLEDIS_MODEL "PCA10100" +#define BLEDIS_MANUFACTURER "Nordic" +#define BLEDIS_MODEL "PCA10100" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x00D8 -#define USB_DESC_CDC_ONLY_PID 0x00D8 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x00D8 +#define USB_DESC_CDC_ONLY_PID 0x00D8 -#define UF2_PRODUCT_NAME "Nordic nRF52833 DK" -#define UF2_VOLUME_LABEL "NRF833BOOT" -#define UF2_BOARD_ID "nRF52833-pca10100-v1" -#define UF2_INDEX_URL "https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52833-DK" +#define UF2_PRODUCT_NAME "Nordic nRF52833 DK" +#define UF2_VOLUME_LABEL "NRF833BOOT" +#define UF2_BOARD_ID "nRF52833-pca10100-v1" +#define UF2_INDEX_URL "https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52833-DK" #endif // PCA10100_H diff --git a/src/boards/pillbug/board.h b/src/boards/pillbug/board.h index 7acb62c..1d442c5 100644 --- a/src/boards/pillbug/board.h +++ b/src/boards/pillbug/board.h @@ -25,41 +25,38 @@ #ifndef _PillBug_H #define _PillBug_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - #define UICR_REGOUT0_VALUE UICR_REGOUT0_VOUT_3V3 /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 20) // Blue -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 20) // Blue +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 // none connected at all -#define BUTTON_1 _PINNUM(0, 18) // unusable: RESET -#define BUTTON_2 _PINNUM(0, 21) // no connection -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 18) // unusable: RESET +#define BUTTON_DFU_OTA PINNUM(0, 21) // no connection +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "MechWild" -#define BLEDIS_MODEL "PillBug" +#define BLEDIS_MANUFACTURER "MechWild" +#define BLEDIS_MODEL "PillBug" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x16D0 -#define USB_DESC_UF2_PID 0x10ED -#define USB_DESC_CDC_ONLY_PID 0x10ED +#define USB_DESC_VID 0x16D0 +#define USB_DESC_UF2_PID 0x10ED +#define USB_DESC_CDC_ONLY_PID 0x10ED -#define UF2_PRODUCT_NAME "PillBug" -#define UF2_VOLUME_LABEL "PillBug" -#define UF2_BOARD_ID "nRF52840-PillBug" -#define UF2_INDEX_URL "https://mechwild.com" +#define UF2_PRODUCT_NAME "PillBug" +#define UF2_VOLUME_LABEL "PillBug" +#define UF2_BOARD_ID "nRF52840-PillBug" +#define UF2_INDEX_URL "https://mechwild.com" #endif // _PillBug_H diff --git a/src/boards/pitaya_go/board.h b/src/boards/pitaya_go/board.h index 9480a93..fd0b994 100644 --- a/src/boards/pitaya_go/board.h +++ b/src/boards/pitaya_go/board.h @@ -25,47 +25,44 @@ #ifndef _MAKERDIARY_PITAYA_GO_H_ #define _MAKERDIARY_PITAYA_GO_H_ -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 10) // Red -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 10) // Red +#define LED_STATE_ON 0 -#define LED_RGB_RED_PIN _PINNUM(1, 10) -#define LED_RGB_GREEN_PIN _PINNUM(1, 11) -#define LED_RGB_BLUE_PIN _PINNUM(1, 12) -#define BOARD_RGB_BRIGHTNESS 0x404040 +#define LED_RGB_RED_PIN PINNUM(1, 10) +#define LED_RGB_GREEN_PIN PINNUM(1, 11) +#define LED_RGB_BLUE_PIN PINNUM(1, 12) +#define BOARD_RGB_BRIGHTNESS 0x404040 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(1, 0) // P1.00: User Button -#define BUTTON_2 _PINNUM(1, 7) // P1.07: NC -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 0) // P1.00: User Button +#define BUTTON_DFU_OTA PINNUM(1, 7) // P1.07: NC +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Makerdiary" -#define BLEDIS_MODEL "Pitaya Go" +#define BLEDIS_MANUFACTURER "Makerdiary" +#define BLEDIS_MODEL "Pitaya Go" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x2886 -#define USB_DESC_UF2_PID 0xF00E -#define USB_DESC_CDC_ONLY_PID 0xF00E +#define USB_DESC_VID 0x2886 +#define USB_DESC_UF2_PID 0xF00E +#define USB_DESC_CDC_ONLY_PID 0xF00E //--------------------------------------------------------------------+ // UF2 //--------------------------------------------------------------------+ -#define UF2_PRODUCT_NAME "Pitaya Go" -#define UF2_VOLUME_LABEL "PITAYAGO" -#define UF2_BOARD_ID "PITAYAGO" -#define UF2_INDEX_URL "https://wiki.makerdiary.com/pitaya-go" +#define UF2_PRODUCT_NAME "Pitaya Go" +#define UF2_VOLUME_LABEL "PITAYAGO" +#define UF2_BOARD_ID "PITAYAGO" +#define UF2_INDEX_URL "https://wiki.makerdiary.com/pitaya-go" #endif /* _MAKERDIARY_PITAYA_GO_H_ */ diff --git a/src/boards/raytac_mdbt50q_db_40/board.h b/src/boards/raytac_mdbt50q_db_40/board.h index 81e07db..2d26a3c 100644 --- a/src/boards/raytac_mdbt50q_db_40/board.h +++ b/src/boards/raytac_mdbt50q_db_40/board.h @@ -25,31 +25,25 @@ #ifndef RAYTAC_MDBT50Q_DB_40_H #define RAYTAC_MDBT50Q_DB_40_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ #define LEDS_NUMBER 3 -/* This is the Green led marked D1 on the board */ -#define LED_PRIMARY_PIN _PINNUM(1, 13) -/* This is the Red led marked D2 on the board */ -#define LED_SECONDARY_PIN _PINNUM(1, 14) -/* This is the Blue led marked D3 on the board */ -#define LED_TERTIARY_PIN _PINNUM(1, 15) -/* There are one more unpopulated LEDs, but for the purposes of bootloader that - * doesn't matter. */ +#define LED_PRIMARY_PIN PINNUM(1, 13) /* Green led marked D1 on the board */ +#define LED_SECONDARY_PIN PINNUM(1, 14) /* Red led marked D2 on the board */ +#define LED_TERTIARY_PIN PINNUM(1, 15) /* Blue led marked D3 on the board */ + +/* There are one more unpopulated LEDs, but for the purposes of bootloader that doesn't matter. */ #define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 4 -#define BUTTON_1 _PINNUM(0, 11) -#define BUTTON_2 _PINNUM(0, 12) -#define BUTTON_3 _PINNUM(0, 24) -#define BUTTON_4 _PINNUM(0, 25) +#define BUTTON_DFU PINNUM(0, 11) +#define BUTTON_DFU_OTA PINNUM(0, 12) +#define BUTTON_3 PINNUM(0, 24) +#define BUTTON_4 PINNUM(0, 25) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ diff --git a/src/boards/raytac_mdbt50q_rx/board.h b/src/boards/raytac_mdbt50q_rx/board.h index 1436d8b..76a178b 100644 --- a/src/boards/raytac_mdbt50q_rx/board.h +++ b/src/boards/raytac_mdbt50q_rx/board.h @@ -25,42 +25,39 @@ #ifndef RAYTAC_MDBT50Q_RX_H #define RAYTAC_MDBT50Q_RX_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 13) -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 13) +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 15) -#define BUTTON_2 _PINNUM(0, 10) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 15) +#define BUTTON_DFU_OTA PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Raytac" -#define BLEDIS_MODEL "MDBT50Q-RX" +#define BLEDIS_MANUFACTURER "Raytac" +#define BLEDIS_MODEL "MDBT50Q-RX" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x010B -#define USB_DESC_CDC_ONLY_PID 0x010B +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x010B +#define USB_DESC_CDC_ONLY_PID 0x010B //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Raytac MDBT50Q-RX" -#define UF2_VOLUME_LABEL "MDBT50QBOOT" -#define UF2_BOARD_ID "nRF52840-MDBT50Q_RX-verD" -#define UF2_INDEX_URL "https://www.adafruit.com/product/5199" +#define UF2_PRODUCT_NAME "Raytac MDBT50Q-RX" +#define UF2_VOLUME_LABEL "MDBT50QBOOT" +#define UF2_BOARD_ID "nRF52840-MDBT50Q_RX-verD" +#define UF2_INDEX_URL "https://www.adafruit.com/product/5199" #endif // RAYTAC_MDBT50Q_RX_H diff --git a/src/boards/sparkfun_nrf52840_micromod/board.h b/src/boards/sparkfun_nrf52840_micromod/board.h index bf43912..11692a4 100644 --- a/src/boards/sparkfun_nrf52840_micromod/board.h +++ b/src/boards/sparkfun_nrf52840_micromod/board.h @@ -26,41 +26,38 @@ #ifndef _SPARKFUN_NRF52840_MICROMOD_H_ #define _SPARKFUN_NRF52840_MICROMOD_H_ -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 13) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 13) +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 7) -#define BUTTON_2 _PINNUM(0, 10) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 7) +#define BUTTON_DFU_OTA PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "SparkFun" -#define BLEDIS_MODEL "MicroMod nRF52840" +#define BLEDIS_MANUFACTURER "SparkFun" +#define BLEDIS_MODEL "MicroMod nRF52840" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1B4F -#define USB_DESC_UF2_PID 0x0022 -#define USB_DESC_CDC_ONLY_PID 0x0023 +#define USB_DESC_VID 0x1B4F +#define USB_DESC_UF2_PID 0x0022 +#define USB_DESC_CDC_ONLY_PID 0x0023 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "SparkFun MicroMod nRF52840" -#define UF2_VOLUME_LABEL "SFMM852BOOT" -#define UF2_BOARD_ID "nRF52840-micromod-v10" +#define UF2_PRODUCT_NAME "SparkFun MicroMod nRF52840" +#define UF2_VOLUME_LABEL "SFMM852BOOT" +#define UF2_BOARD_ID "nRF52840-micromod-v10" -#define UF2_INDEX_URL "https://www.sparkfun.com/products/16984" +#define UF2_INDEX_URL "https://www.sparkfun.com/products/16984" #endif /* _SPARKFUN_NRF52840_MICROMOD_H_ */ diff --git a/src/boards/arcade_feather_nrf52840_express/board.cmake b/src/boards/syldra/board.cmake similarity index 100% rename from src/boards/arcade_feather_nrf52840_express/board.cmake rename to src/boards/syldra/board.cmake diff --git a/src/boards/syldra/board.h b/src/boards/syldra/board.h new file mode 100644 index 0000000..61539f8 --- /dev/null +++ b/src/boards/syldra/board.h @@ -0,0 +1,61 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2026 Ambraglow + * + * 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 _SYLDRA_H +#define _SYLDRA_H + +//------------------------------------------------------------------// +// LED +//------------------------------------------------------------------// +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 17) // AD10 LED +#define LED_STATE_ON 1 + +//------------------------------------------------------------------// +// BUTTON +//------------------------------------------------------------------// +#define BUTTON_DFU PINNUM(0, 24) // AD20 -- DFU +#define BUTTON_DFU_OTA PINNUM(1, 00) // AD22 -- OTA + +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//-------------------------------------------------------------------// +// BLE OTA +//-------------------------------------------------------------------// +#define BLEDIS_MANUFACTURER "Ambraglow-&-localcc" +#define BLEDIS_MODEL "Syldra_dev_r1" + +//--------------------------------------------------------------------+ +// USB - using test PIDs +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x1209 +#define USB_DESC_UF2_PID 0x0001 +#define USB_DESC_CDC_ONLY_PID 0x7A01 + +#define UF2_PRODUCT_NAME "Syldra nrf52840 Development Board" +#define UF2_VOLUME_LABEL "Syldra-boot" +#define UF2_BOARD_ID "nRF52840-Syldra-dev-v1" +#define UF2_INDEX_URL "https://github.com/ambraglow/nonorf" + +#endif \ No newline at end of file diff --git a/src/boards/arcade_feather_nrf52840_express/board.mk b/src/boards/syldra/board.mk similarity index 65% rename from src/boards/arcade_feather_nrf52840_express/board.mk rename to src/boards/syldra/board.mk index 9d29ac6..befd7cb 100644 --- a/src/boards/arcade_feather_nrf52840_express/board.mk +++ b/src/boards/syldra/board.mk @@ -1 +1,2 @@ MCU_SUB_VARIANT = nrf52840 +SD_NAME = s140 \ No newline at end of file diff --git a/src/boards/feather_nrf52833_express/pinconfig.c b/src/boards/syldra/pinconfig.c similarity index 71% rename from src/boards/feather_nrf52833_express/pinconfig.c rename to src/boards/syldra/pinconfig.c index 72308c4..2a592df 100644 --- a/src/boards/feather_nrf52833_express/pinconfig.c +++ b/src/boards/syldra/pinconfig.c @@ -8,12 +8,12 @@ const uint32_t bootloaderConfig[] = CFG_MAGIC0, CFG_MAGIC1, // magic 5, 100, // used entries, total entries - 204, 0x80000, // FLASH_BYTES - 205, 0x20000, // RAM_BYTES + 204, 0x100000, // FLASH_BYTES = 0x100000 + 205, 0x40000, // RAM_BYTES = 0x40000 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 + 209, 0xada52840, // UF2_FAMILY = 0xada52840 210, 0x20, // PINS_PORT_SIZE = PA_32 0, 0, 0, 0, 0, 0, 0, 0 /* CF2 END */ -}; +}; \ No newline at end of file diff --git a/src/boards/t1000_e/board.h b/src/boards/t1000_e/board.h index 1a08741..58a52c9 100644 --- a/src/boards/t1000_e/board.h +++ b/src/boards/t1000_e/board.h @@ -25,43 +25,40 @@ #ifndef _T1000_E_H #define _T1000_E_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 24) // Green -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 24) // Green +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 6) // Primary Button -#define BUTTON_2 _PINNUM(0, 18) // unusable: RESET -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 6) // Primary Button +#define BUTTON_DFU_OTA PINNUM(0, 18) // unusable: RESET +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Seeed Studio" -#define BLEDIS_MODEL "T1000-E" +#define BLEDIS_MANUFACTURER "Seeed Studio" +#define BLEDIS_MODEL "T1000-E" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x2886 -#define USB_DESC_UF2_PID 0x0057 -#define USB_DESC_CDC_ONLY_PID 0x0057 +#define USB_DESC_VID 0x2886 +#define USB_DESC_UF2_PID 0x0057 +#define USB_DESC_CDC_ONLY_PID 0x0057 //--------------------------------------------------------------------+ // UF2 //--------------------------------------------------------------------+ -#define UF2_PRODUCT_NAME "Seeed T1000-E for Meshtastic" -#define UF2_VOLUME_LABEL "T1000-E" -#define UF2_BOARD_ID "nRF52840-T1000-E-v1" -#define UF2_INDEX_URL "https://www.seeedstudio.com/SenseCAP-Card-Tracker-T1000-E-for-Meshtastic-p-5913.html" +#define UF2_PRODUCT_NAME "Seeed T1000-E for Meshtastic" +#define UF2_VOLUME_LABEL "T1000-E" +#define UF2_BOARD_ID "nRF52840-T1000-E-v1" +#define UF2_INDEX_URL "https://www.seeedstudio.com/SenseCAP-Card-Tracker-T1000-E-for-Meshtastic-p-5913.html" #endif /* _T1000_E_H */ diff --git a/src/boards/waveshare_nrf52840_eval/board.h b/src/boards/waveshare_nrf52840_eval/board.h index 27991df..d66a785 100644 --- a/src/boards/waveshare_nrf52840_eval/board.h +++ b/src/boards/waveshare_nrf52840_eval/board.h @@ -23,50 +23,47 @@ #ifndef _WAVESHARE_NRF52840_H #define _WAVESHARE_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 +#define LEDS_NUMBER 2 /* This is led marked LED1 on the board */ -#define LED_PRIMARY_PIN _PINNUM(0, 13) +#define LED_PRIMARY_PIN PINNUM(0, 13) /* This is led marked LED2 on the board */ -#define LED_SECONDARY_PIN _PINNUM(0, 14) +#define LED_SECONDARY_PIN PINNUM(0, 14) /* There are two more LEDs, but for the purposes of bootloader that * doesn't matter. */ -#define LED_STATE_ON 0 +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 /* This is the 'KEY1' in top left of the board under RESET key. * It is used to remain in bootloader mode after reset. */ -#define BUTTON_1 _PINNUM(0, 11) +#define BUTTON_DFU PINNUM(0, 11) /* Pin below is in the bottom left of PCB, and can be shorted to GND * with a regular 2.54mm jumper or tweezers. This pin is used to * clear user firmware and remain in bootloader mode. */ -#define BUTTON_2 _PINNUM(0, 29) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU_OTA PINNUM(0, 29) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Waveshare" -#define BLEDIS_MODEL "nRF52840 Eval" +#define BLEDIS_MANUFACTURER "Waveshare" +#define BLEDIS_MODEL "nRF52840 Eval" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0029 -#define USB_DESC_CDC_ONLY_PID 0x002A +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0029 +#define USB_DESC_CDC_ONLY_PID 0x002A //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Waveshare nRF52840 Eval" -#define UF2_VOLUME_LABEL "WS52840EVK" -#define UF2_BOARD_ID "WS-nRF52840-EVK" -#define UF2_INDEX_URL "https://www.waveshare.com/wiki/NRF52840_Eval_Kit" +#define UF2_PRODUCT_NAME "Waveshare nRF52840 Eval" +#define UF2_VOLUME_LABEL "WS52840EVK" +#define UF2_BOARD_ID "WS-nRF52840-EVK" +#define UF2_INDEX_URL "https://www.waveshare.com/wiki/NRF52840_Eval_Kit" #endif // _WAVESHARE_NRF52840_H diff --git a/src/boards/xiao_nrf52840_ble/board.h b/src/boards/xiao_nrf52840_ble/board.h index 9f4c45e..eacabd2 100644 --- a/src/boards/xiao_nrf52840_ble/board.h +++ b/src/boards/xiao_nrf52840_ble/board.h @@ -1,68 +1,65 @@ -/* - * 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 _XIAO_BLE -#define _XIAO_BLE - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -// The board has 3 leds, but changing the number here causes OTA issues. -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 26) -#define LED_STATE_ON 0 - -#define NEOPIXELS_NUMBER 0 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 18) -// Button 2 is defined as D1 from expansion board. -#define BUTTON_2 _PINNUM(0, 3) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Seeed" -#define BLEDIS_MODEL "XIAO nRF52840" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x2886 -#define USB_DESC_UF2_PID 0x0044 -#define USB_DESC_CDC_ONLY_PID 0x0044 - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Seeed XIAO nRF52840" -#define UF2_VOLUME_LABEL "XIAO-BOOT" -#define UF2_BOARD_ID "nRF52840-SeeedXiao-v1" -#define UF2_INDEX_URL "https://www.seeedstudio.com/" - -#endif // _XIAO_BLE +/* + * 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 _XIAO_BLE +#define _XIAO_BLE + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +// The board has 3 leds, but changing the number here causes OTA issues. +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 26) +#define LED_STATE_ON 0 + +#define NEOPIXELS_NUMBER 0 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_DFU PINNUM(0, 18) +// Button 2 is defined as D1 from expansion board. +#define BUTTON_DFU_OTA PINNUM(0, 3) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Seeed" +#define BLEDIS_MODEL "XIAO nRF52840" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x2886 +#define USB_DESC_UF2_PID 0x0044 +#define USB_DESC_CDC_ONLY_PID 0x0044 + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "Seeed XIAO nRF52840" +#define UF2_VOLUME_LABEL "XIAO-BOOT" +#define UF2_BOARD_ID "nRF52840-SeeedXiao-v1" +#define UF2_INDEX_URL "https://www.seeedstudio.com/" + +#endif // _XIAO_BLE diff --git a/src/boards/xiao_nrf52840_ble_sense/board.h b/src/boards/xiao_nrf52840_ble_sense/board.h index e512c1b..ff0c204 100644 --- a/src/boards/xiao_nrf52840_ble_sense/board.h +++ b/src/boards/xiao_nrf52840_ble_sense/board.h @@ -1,68 +1,65 @@ -/* - * 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 _XIAO_BLE_SENSE -#define _XIAO_BLE_SENSE - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -// The board has 3 leds, but changing the number here causes OTA issues. -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 26) -#define LED_STATE_ON 0 - -#define NEOPIXELS_NUMBER 0 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 18) -// Button 2 is defined as D1 from expansion board. -#define BUTTON_2 _PINNUM(0, 3) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Seeed" -#define BLEDIS_MODEL "XIAO nRF52840 Sense" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x2886 -#define USB_DESC_UF2_PID 0x0045 -#define USB_DESC_CDC_ONLY_PID 0x0045 - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Seeed XIAO nRF52840" -#define UF2_VOLUME_LABEL "XIAO-SENSE" -#define UF2_BOARD_ID "nRF52840-SeeedXiaoSense-v1" -#define UF2_INDEX_URL "https://www.seeedstudio.com/" - -#endif // _XIAO_BLE_SENSE +/* + * 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 _XIAO_BLE_SENSE +#define _XIAO_BLE_SENSE + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +// The board has 3 leds, but changing the number here causes OTA issues. +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 26) +#define LED_STATE_ON 0 + +#define NEOPIXELS_NUMBER 0 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_DFU PINNUM(0, 18) +// Button 2 is defined as D1 from expansion board. +#define BUTTON_DFU_OTA PINNUM(0, 3) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Seeed" +#define BLEDIS_MODEL "XIAO nRF52840 Sense" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x2886 +#define USB_DESC_UF2_PID 0x0045 +#define USB_DESC_CDC_ONLY_PID 0x0045 + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "Seeed XIAO nRF52840" +#define UF2_VOLUME_LABEL "XIAO-SENSE" +#define UF2_BOARD_ID "nRF52840-SeeedXiaoSense-v1" +#define UF2_INDEX_URL "https://www.seeedstudio.com/" + +#endif // _XIAO_BLE_SENSE diff --git a/src/dfu_init.c b/src/dfu_init.c index e19cffa..612fed9 100644 --- a/src/dfu_init.c +++ b/src/dfu_init.c @@ -66,16 +66,24 @@ * If the init packet is signed by a trusted source, it must be decrypted before it can be * processed. */ - + #include "dfu_init.h" #include #include #include #include "nrf_error.h" + +#ifndef SIGNED_FW #include "crc16.h" +#else +#include +#include +#include +#include +#endif /* ADAFRUIT - * - All firmware init data must has Device Type ADAFRUIT_DEVICE_TYPE (nrf52832 and nrf52840) + * - All firmware init data must have Device Type ADAFRUIT_DEVICE_TYPE (nrf52832 and nrf52840) * - SD + Bootloader upgrade must have correct Device Revision to make sure bootloader is not flashed * on the wrong device (e.g flah nRF52832's bootloader on nRF52840 board and vice versa) * - nrf52832 dev-rev is 0xADAF @@ -93,122 +101,230 @@ #error Unknown MCU #endif +#ifdef SIGNED_FW +// The following is the layout of the extended init packet if using image length and sha256 to validate image +// and NIST P-256 + SHA256 to sign the init_package including the extended part +#define DFU_INIT_PACKET_POS_EXT_IDENTIFIER 0 //< Position of the identifier for the ext package +#define DFU_INIT_PACKET_POS_EXT_IMAGE_LENGTH 4 //< Position of the image length +#define DFU_INIT_PACKET_POS_EXT_IMAGE_HASH256 8 //< Position of the 256 +#define DFU_INIT_PACKET_POS_EXT_INIT_SIGNATURE_R 40 //< Position of the Signature R +#define DFU_INIT_PACKET_POS_EXT_INIT_SIGNATURE_S 72 //< Position of the Signature S +#define DFU_INIT_PACKET_EXT_LENGTH_SIGNED 40 //< Length of the extended init packet that is part of the signed data +#define DFU_INIT_PACKET_EXT_BEGIN -#define DFU_INIT_PACKET_EXT_LENGTH_MIN 2 //< Minimum length of the extended init packet. The extended init packet may contain a CRC, a HASH, or other data. This value must be changed according to the requirements of the system. The template uses a minimum value of two in order to hold a CRC. */ -#define DFU_INIT_PACKET_EXT_LENGTH_MAX 10 //< Maximum length of the extended init packet. The extended init packet may contain a CRC, a HASH, or other data. This value must be changed according to the requirements of the system. The template uses a maximum value of 10 in order to hold a CRC and any padded data on transport layer without overflow. */ +#define DFU_SHA256_DIGEST_LENGTH 32 //< Length of SHA-256 digest +#define DFU_SIGNATURE_R_LENGTH 32 //< Length of the signature part r +#define DFU_SIGNATURE_S_LENGTH 32 //< Length of the signature part s + +#define DFU_INIT_PACKET_USES_CRC16 (0) +#define DFU_INIT_PACKET_USES_HASH (1) +#define DFU_INIT_PACKET_USES_ECDS (2) + +#if !defined(SIGNED_FW_QX) || !defined(SIGNED_FW_QY) +# error Missing definitions for SIGNED_FW_QX and/or SIGNED_FW_QY required for signed firmware verification +#endif + +/** @snippet [DFU BLE Signing public key curve points] */ +static const uint8_t pk[] = { + /* x-coord : static uint8_t Qx[] = {*/ + SIGNED_FW_QX + /* 0x39, 0xb0, 0x58, 0x3d, 0x27, 0x07, 0x91, 0x38, + 0x6a, 0xa3, 0x36, 0x0f, 0xa2, 0xb5, 0x86, 0x7e, + 0xae, 0xba, 0xf7, 0xa3, 0xf4, 0x81, 0x5f, 0x78, + 0x02, 0xf2, 0xa1, 0x21, 0xd5, 0x21, 0x84, 0x12 */ + /* };*/ + , + /* y-coord : static uint8_t Qy[] = {*/ + SIGNED_FW_QY + /* 0x4a, 0x0d, 0xfe, 0xa4, 0x77, 0x50, 0xb1, 0xb5, 0x26, 0xc0, 0x9d, 0xdd, 0xf0, 0x24, 0x90, 0x57, 0x6c, 0x64, 0x3b, 0xd3, 0xdf, 0x92, 0x3b, 0xb3, 0x47, 0x97, 0x83, 0xd4, 0xfc, 0x76, 0xf5, 0x9d */ + /* };*/ +}; +/** @snippet [DFU BLE Signing public key curve points] */ + +// Helper macros for stringification +//#define VSTRINGIFY(...) #__VA_ARGS__ +//#define TO_STRING(...) VSTRINGIFY(__VA_ARGS__) +//#pragma message ("Qx: " TO_STRING(SIGNED_FW_QX)) +//#pragma message ("Qy: " TO_STRING(SIGNED_FW_QY)) + +_Static_assert(sizeof(pk) == 64, "Public key must be 64 bytes in size"); + +#endif + +#define DFU_INIT_PACKET_EXT_LENGTH_MIN 2 //< Minimum length of the extended init packet. Init packet and CRC16 +#define DFU_INIT_PACKET_EXT_LENGTH_MAX 104 //< Identifier (4 bytes) + Image length (4 bytes) + SHA-256 digest (32 bytes) + NIST P-256 using SHA-256 (64 bytes) static uint8_t m_extended_packet[DFU_INIT_PACKET_EXT_LENGTH_MAX]; //< Data array for storage of the extended data received. The extended data follows the normal init data of type \ref dfu_init_packet_t. Extended data can be used for a CRC, hash, signature, or other data. */ static uint8_t m_extended_packet_length; //< Length of the extended data received with init packet. */ - uint32_t dfu_init_prevalidate(uint8_t * p_init_data, uint32_t init_data_len, uint8_t image_type) { - uint32_t i = 0; - - // In order to support signing or encryption then any init packet decryption function / library - // should be called from here or implemented at this location. + uint32_t i = 0; + + // In order to support signing or encryption then any init packet decryption function / library + // should be called from here or implemented at this location. - // Length check to ensure valid data are parsed. - if (init_data_len < sizeof(dfu_init_packet_t)) - { - return NRF_ERROR_INVALID_LENGTH; - } + // Length check to ensure valid data are parsed. + if (init_data_len < sizeof(dfu_init_packet_t)) + { + return NRF_ERROR_INVALID_LENGTH; + } - // Current template uses clear text data so they can be casted for pre-check. - dfu_init_packet_t * p_init_packet = (dfu_init_packet_t *)p_init_data; + // Current template uses clear text data so they can be casted for pre-check. + dfu_init_packet_t * p_init_packet = (dfu_init_packet_t *)p_init_data; - m_extended_packet_length = ((uint32_t)p_init_data + init_data_len) - - (uint32_t)&p_init_packet->softdevice[p_init_packet->softdevice_len]; - if (m_extended_packet_length < DFU_INIT_PACKET_EXT_LENGTH_MIN) - { - return NRF_ERROR_INVALID_LENGTH; - } + m_extended_packet_length = ((uint32_t)p_init_data + init_data_len) - + (uint32_t)&p_init_packet->softdevice[p_init_packet->softdevice_len]; + if (m_extended_packet_length < DFU_INIT_PACKET_EXT_LENGTH_MIN) + { + return NRF_ERROR_INVALID_LENGTH; + } - if (((uint32_t)p_init_data + init_data_len) < - (uint32_t)&p_init_packet->softdevice[p_init_packet->softdevice_len]) - { - return NRF_ERROR_INVALID_LENGTH; - } + if (((uint32_t)p_init_data + init_data_len) < + (uint32_t)&p_init_packet->softdevice[p_init_packet->softdevice_len]) + { + return NRF_ERROR_INVALID_LENGTH; + } - memcpy(m_extended_packet, - &p_init_packet->softdevice[p_init_packet->softdevice_len], - m_extended_packet_length); + memcpy(m_extended_packet, + &p_init_packet->softdevice[p_init_packet->softdevice_len], + m_extended_packet_length); - /** [DFU init application version] */ - // To support application versioning, this check should be updated. - // This template allows for any application to be installed. However, - // customers can place a revision number at the bottom of the application - // to be verified by the bootloader. This can be done at a location - // relative to the application, for example the application start - // address + 0x0100. - /** [DFU init application version] */ - - // First check to verify the image to be transfered matches the device type. - // If no Device type is present in DFU_DEVICE_INFO then any image will be accepted. + /** [DFU init application version] */ + // To support application versioning, this check should be updated. + // This template allows for any application to be installed. However, + // customers can place a revision number at the bottom of the application + // to be verified by the bootloader. This can be done at a location + // relative to the application, for example the application start + // address + 0x0100. + /** [DFU init application version] */ + + // First check to verify the image to be transfered matches the device type. + // If no Device type is present in DFU_DEVICE_INFO then any image will be accepted. // if ((DFU_DEVICE_INFO->device_type != DFU_DEVICE_TYPE_EMPTY) && // (p_init_packet->device_type != DFU_DEVICE_INFO->device_type)) // { // return NRF_ERROR_INVALID_DATA; // } - - // Second check to verify the image to be transfered matches the device revision. - // If no Device revision is present in DFU_DEVICE_INFO then any image will be accepted. - // if ((DFU_DEVICE_INFO->device_rev != DFU_DEVICE_REVISION_EMPTY) && - // (p_init_packet->device_rev != DFU_DEVICE_INFO->device_rev)) + + // Second check to verify the image to be transfered matches the device revision. + // If no Device revision is present in DFU_DEVICE_INFO then any image will be accepted. + // if ((DFU_DEVICE_INFO->device_rev != DFU_DEVICE_REVISION_EMPTY) && + // (p_init_packet->device_rev != DFU_DEVICE_INFO->device_rev)) - if ( p_init_packet->device_type != ADAFRUIT_DEVICE_TYPE ) - { - return NRF_ERROR_FORBIDDEN; - } + if ( p_init_packet->device_type != ADAFRUIT_DEVICE_TYPE ) + { + return NRF_ERROR_FORBIDDEN; + } - // Adafruit unlock code must match to upgrade SoftDevice and/or Bootloader - if ( image_type & (DFU_UPDATE_SD | DFU_UPDATE_BL) ) - { - if (p_init_packet->device_rev != ADAFRUIT_DEV_REV) - { - return NRF_ERROR_FORBIDDEN; - } - } + // Adafruit unlock code must match to upgrade SoftDevice and/or Bootloader + if ( image_type & (DFU_UPDATE_SD | DFU_UPDATE_BL) ) + { + if (p_init_packet->device_rev != ADAFRUIT_DEV_REV) + { + return NRF_ERROR_FORBIDDEN; + } + } - // Third check: Check the array of supported SoftDevices by this application. - // If the installed SoftDevice does not match any SoftDevice in the list then an - // error is returned. - while (i < p_init_packet->softdevice_len) - { - if (p_init_packet->softdevice[i] == DFU_SOFTDEVICE_ANY || - p_init_packet->softdevice[i++] == SD_FWID_GET(MBR_SIZE)) - { - return NRF_SUCCESS; - } - } - - // No matching SoftDevice found - Return NRF_ERROR_INVALID_DATA. - return NRF_ERROR_INVALID_DATA; + // Third check: Check the array of supported SoftDevices by this application. + // If the installed SoftDevice does not match any SoftDevice in the list then an + // error is returned. + while (i < p_init_packet->softdevice_len) + { + if (p_init_packet->softdevice[i] == DFU_SOFTDEVICE_ANY || + p_init_packet->softdevice[i] == SD_FWID_GET(MBR_SIZE)) + { + // Found a match. Break the loop. + break; + } + ++i; + } + + // No matching SoftDevice found - Return NRF_ERROR_INVALID_DATA. + if (i >= p_init_packet->softdevice_len) + return NRF_ERROR_INVALID_DATA; + +#ifndef SIGNED_FW + return NRF_SUCCESS; +#else + // Check that we have the correct identifier indicating that ECDS is used + if(*(uint32_t*)&m_extended_packet[DFU_INIT_PACKET_POS_EXT_IDENTIFIER] != DFU_INIT_PACKET_USES_ECDS) + { + return NRF_ERROR_INVALID_DATA; + } + + uint8_t* msg = p_init_data; + size_t msg_len = (init_data_len - m_extended_packet_length) + DFU_INIT_PACKET_EXT_LENGTH_SIGNED; + + // Create a sha256 digest + struct tc_sha256_state_struct state = {0}; + uint8_t digest[TC_SHA256_DIGEST_SIZE]; + if (tc_sha256_init(&state) != TC_CRYPTO_SUCCESS) return NRF_ERROR_INVALID_DATA; + if (tc_sha256_update(&state,msg,msg_len) != TC_CRYPTO_SUCCESS) return NRF_ERROR_INVALID_DATA; + if (tc_sha256_final(digest,&state) != TC_CRYPTO_SUCCESS) return NRF_ERROR_INVALID_DATA; + + // And verify signature + const struct uECC_Curve_t * curve = uECC_secp256r1(); + if (uECC_valid_public_key(pk, curve) != 0) + return NRF_ERROR_INVALID_DATA; + + unsigned char* sig = &m_extended_packet[DFU_INIT_PACKET_POS_EXT_INIT_SIGNATURE_R]; +# if (DFU_INIT_PACKET_POS_EXT_INIT_SIGNATURE_S - DFU_INIT_PACKET_POS_EXT_INIT_SIGNATURE_R) != DFU_SIGNATURE_R_LENGTH +# error Incorrect layout: r and s must be contiguous! +# endif + + return uECC_verify(pk, digest, sizeof(digest), sig, curve) == 1 ? NRF_SUCCESS : NRF_ERROR_INVALID_DATA; +#endif } uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len) { - uint16_t image_crc; - uint16_t received_crc; - - // In order to support hashing (and signing) then the (decrypted) hash should be fetched and - // the corresponding hash should be calculated over the image at this location. - // If hashing (or signing) is added to the system then the CRC validation should be removed. +#ifndef SIGNED_FW + uint16_t image_crc; + uint16_t received_crc; + + // calculate CRC from active block. + image_crc = crc16_compute(p_image, image_len, NULL); - // calculate CRC from active block. - image_crc = crc16_compute(p_image, image_len, NULL); + // Decode the received CRC from extended data. + received_crc = uint16_decode((uint8_t *)&m_extended_packet[0]); - // Decode the received CRC from extended data. - received_crc = uint16_decode((uint8_t *)&m_extended_packet[0]); + // Compare the received and calculated CRC. + if (image_crc != received_crc) + { + return NRF_ERROR_INVALID_DATA; + } - // Compare the received and calculated CRC. - if (image_crc != received_crc) - { - return NRF_ERROR_INVALID_DATA; - } + return NRF_SUCCESS; + +#else + + // Compare image size received with signed init_packet data + if(image_len != *(uint32_t*)&m_extended_packet[DFU_INIT_PACKET_POS_EXT_IMAGE_LENGTH]) + { + return NRF_ERROR_INVALID_DATA; + } - return NRF_SUCCESS; + uint8_t image_digest[DFU_SHA256_DIGEST_LENGTH]; + uint8_t * received_digest; + + // Create a sha256 digest + struct tc_sha256_state_struct state = {0}; + if (tc_sha256_init(&state) != TC_CRYPTO_SUCCESS) return NRF_ERROR_INVALID_DATA; + if (tc_sha256_update(&state, p_image, image_len) != TC_CRYPTO_SUCCESS) return NRF_ERROR_INVALID_DATA; + if (tc_sha256_final(image_digest, &state) != TC_CRYPTO_SUCCESS) return NRF_ERROR_INVALID_DATA; + + received_digest = &m_extended_packet[DFU_INIT_PACKET_POS_EXT_IMAGE_HASH256]; + + // Compare the received and calculated digests. + if (memcmp(&image_digest[0], received_digest, DFU_SHA256_DIGEST_LENGTH) != 0) + { + return NRF_ERROR_INVALID_DATA; + } + + return NRF_SUCCESS; +#endif } diff --git a/src/flash_nrf5x.c b/src/flash_nrf5x.c index 12c6797..ddea500 100644 --- a/src/flash_nrf5x.c +++ b/src/flash_nrf5x.c @@ -26,48 +26,88 @@ #include "nrf_sdm.h" #include "flash_nrf5x.h" #include "boards.h" +#include "dfu_types.h" -#define FLASH_PAGE_SIZE 4096 #define FLASH_CACHE_INVALID_ADDR 0xffffffff static uint32_t _fl_addr = FLASH_CACHE_INVALID_ADDR; -static uint8_t _fl_buf[FLASH_PAGE_SIZE] __attribute__((aligned(4))); +static uint8_t _fl_buf[CODE_PAGE_SIZE] __attribute__((aligned(4))); + +void flash_nrf5x_erase (uint32_t dst, uint32_t len) +{ + uint32_t page_addr = dst & ~(CODE_PAGE_SIZE - 1); + uint32_t const page_count = NRFX_CEIL_DIV(len, CODE_PAGE_SIZE); + for ( uint32_t i = 0; i < page_count; i++ ) + { + uint32_t const addr = page_addr + i * CODE_PAGE_SIZE; + PRINTF("Erase 0x%08lX\r\n", addr); + nrfx_nvmc_page_erase(addr); + } +} + void flash_nrf5x_flush (bool need_erase) { - if ( _fl_addr == FLASH_CACHE_INVALID_ADDR ) return; + if ( _fl_addr == FLASH_CACHE_INVALID_ADDR ) + return; - // skip the write if contents matches - if ( memcmp(_fl_buf, (void *) _fl_addr, FLASH_PAGE_SIZE) != 0 ) - { - // - nRF52832 dfu via uart can miss incoming byte when erasing because cpu is blocked for > 2ms. - // Since dfu_prepare_func_app_erase() already erase the page for us, we can skip it here. - // - nRF52840 dfu serial/uf2 are USB-based which are DMA and should have no problems. - // - // Note: MSC uf2 does not erase page in advance like dfu serial - if ( need_erase ) + // skip the write if contents matches + if ( memcmp(_fl_buf, (void *) _fl_addr, CODE_PAGE_SIZE) != 0 ) { - PRINTF("Erase and "); - nrfx_nvmc_page_erase(_fl_addr); + // - nRF52832 dfu via uart can miss incoming byte when erasing because cpu is blocked for > 2ms. + // Since dfu_prepare_func_app_erase() already erase the page for us, we can skip it here. + // - nRF52840 dfu serial/uf2 are USB-based which are DMA and should have no problems. + // + // Note: MSC uf2 does not erase page in advance like dfu serial + if ( need_erase ) + { + PRINTF("Erase and "); + nrfx_nvmc_page_erase(_fl_addr); + } + + PRINTF("Write 0x%08lX\r\n", _fl_addr); + nrfx_nvmc_words_write(_fl_addr, (uint32_t *) _fl_buf, CODE_PAGE_SIZE / 4); } - PRINTF("Write 0x%08lX\r\n", _fl_addr); - nrfx_nvmc_words_write(_fl_addr, (uint32_t *) _fl_buf, FLASH_PAGE_SIZE / 4); - } - - _fl_addr = FLASH_CACHE_INVALID_ADDR; + _fl_addr = FLASH_CACHE_INVALID_ADDR; } -void flash_nrf5x_write (uint32_t dst, void const *src, int len, bool need_erase) +void flash_nrf5x_write (uint32_t dst, void const *src, uint32_t len, bool need_erase) { - uint32_t newAddr = dst & ~(FLASH_PAGE_SIZE - 1); + // While something to write... + while (len > 0) { - if ( newAddr != _fl_addr ) - { - flash_nrf5x_flush(need_erase); - _fl_addr = newAddr; - memcpy(_fl_buf, (void *) newAddr, FLASH_PAGE_SIZE); - } - memcpy(_fl_buf + (dst & (FLASH_PAGE_SIZE - 1)), src, len); + // Align to start of page + uint32_t page_addr = dst & ~(CODE_PAGE_SIZE - 1); + + // If page changed, write modified contents + if ( page_addr != _fl_addr ) + { + flash_nrf5x_flush(need_erase); + + // Remember new page + _fl_addr = page_addr; + + // And read its contents + memcpy(_fl_buf, (void *) page_addr, CODE_PAGE_SIZE); + } + + // Compute the write offset into the current page + uint32_t offset_in_page = dst & (CODE_PAGE_SIZE - 1); + + // Compute how many bytes remaining to complete the page + uint32_t bytes_to_end = CODE_PAGE_SIZE - offset_in_page; + + // Limit the count to the available bytes in the current page + uint32_t max_bytes = bytes_to_end < len ? bytes_to_end : len; + + // Copy contents to our buffer + memcpy(_fl_buf + offset_in_page, src, max_bytes); + + // Update variables + len -= max_bytes; + dst += max_bytes; + src = (void const *) ((uint8_t*)src + max_bytes); + }; } diff --git a/src/flash_nrf5x.h b/src/flash_nrf5x.h index 9ab4619..d3fbb49 100644 --- a/src/flash_nrf5x.h +++ b/src/flash_nrf5x.h @@ -34,7 +34,8 @@ extern "C" { #endif -void flash_nrf5x_write (uint32_t dst, void const *src, int len, bool need_erase); +void flash_nrf5x_erase (uint32_t dst, uint32_t len); +void flash_nrf5x_write (uint32_t dst, void const *src, uint32_t len, bool need_erase); void flash_nrf5x_flush (bool need_erase); #ifdef __cplusplus diff --git a/src/main.c b/src/main.c index 9ebc9e9..c988ee4 100644 --- a/src/main.c +++ b/src/main.c @@ -39,7 +39,10 @@ #include #include "nrfx.h" +#include "nrf_clock.h" #include "nrfx_power.h" +#include "nrfx_pwm.h" + #include "sdk_common.h" #include "bootloader.h" #include "bootloader_util.h" @@ -48,7 +51,10 @@ #include "nrf_soc.h" #include "nrf_nvic.h" #include "app_error.h" +#include "nrf_gpio.h" #include "ble.h" +#include "nrf.h" +#include "ble_hci.h" #include "app_scheduler.h" #include "nrf_error.h" @@ -56,10 +62,12 @@ #include "pstorage_platform.h" #include "nrf_mbr.h" +#include "pstorage.h" #ifdef NRF_USBD #include "uf2/uf2.h" +#include "nrf_usbd.h" #include "tusb.h" void usb_init(bool cdc_only); @@ -114,12 +122,9 @@ extern void tusb_hal_nrf_power_event(uint32_t event); // DFU_DBL_RESET magic is used to determined which mode is entered #define APP_ASKS_FOR_SINGLE_TAP_RESET() (*((uint32_t*)(DFU_BANK_0_REGION_START + 0x200)) == 0x87eeb07c) -// These value must be the same with one in dfu_transport_ble.c -#define BLEGAP_EVENT_LENGTH 6 -#define BLEGATT_ATT_MTU_MAX 23 -enum { - BLE_CONN_CFG_HIGH_BANDWIDTH = 1 -}; +#define BLEGAP_EVENT_LENGTH 12 +#define BLEGATTS_HVN_QSIZE 12 +#define BLEGATTC_WRCMD_QSIZE 2 //--------------------------------------------------------------------+ // @@ -129,6 +134,7 @@ uint32_t* dbl_reset_mem = ((uint32_t*) DFU_DBL_RESET_MEM); // true if ble, false if serial bool _ota_dfu = false; bool _ota_connected = false; +bool _ota_was_connected = false; bool _sd_inited = false; bool is_ota(void) { @@ -187,6 +193,10 @@ int main(void) { // Return when DFU process is complete (or not entered at all) check_dfu_mode(); + // Check if we must reenter the bootloader after reset, instead of + // launching the user application + bool bootloader_must_be_reentered = bootloader_must_reset_to_self(); + // Reset peripherals board_teardown(); @@ -197,7 +207,9 @@ int main(void) { * - sd_softdevice_vector_table_base_set(APP_ADDR) * - jump to App reset */ - if (bootloader_app_is_valid() && !bootloader_dfu_sd_in_progress()) { + if (!bootloader_must_be_reentered && + bootloader_app_is_valid() && + !bootloader_dfu_sd_in_progress()) { PRINTF("App is valid\r\n"); if (is_sd_existed()) { // MBR forward IRQ to SD (if not already) @@ -215,6 +227,14 @@ int main(void) { bootloader_app_start(); } + // No application was loaded or we need to reenter the bootloader + + // Reset the system with the OTA DFU update in case we were in it, + // to allow completion of FLASHING, otherwise, default to normal reset + if (_ota_was_connected) { + NRF_POWER->GPREGRET = DFU_MAGIC_OTA_RESET; + } + NVIC_SystemReset(); } @@ -249,10 +269,15 @@ static void check_dfu_mode(void) { } /*------------- Determine DFU mode (Serial, OTA, FRESET or normal) -------------*/ - dfu_start = dfu_start || button_pressed(BUTTON_DFU); // DFU button pressed + // DFU button pressed +#if defined(BUTTON_DFU) + dfu_start = dfu_start || button_pressed(BUTTON_DFU); +#endif // DFU + FRESET are pressed --> OTA - _ota_dfu = _ota_dfu || (button_pressed(BUTTON_DFU) && button_pressed(BUTTON_FRESET)); +#if defined(BUTTON_DFU) && defined(BUTTON_DFU_OTA) + _ota_dfu = _ota_dfu || (button_pressed(BUTTON_DFU) && button_pressed(BUTTON_DFU_OTA)); +#endif bool const valid_app = bootloader_app_is_valid(); bool const just_start_app = valid_app && !dfu_start && (*dbl_reset_mem) == DFU_DBL_RESET_APP; @@ -261,6 +286,16 @@ static void check_dfu_mode(void) { dfu_start = 1; } +#ifdef DEFAULT_TO_OTA_DFU + // Default to OTA DFU mode, instead of Serial DFU mode, if there is no app present, + // because otherwise, if there is no application, it will restart in Serial DFU mode, + // making it IMPOSSIBLE to recover devices in the field if there are no user + // accessible USB ports + if (!valid_app || dfu_start) { + _ota_dfu = 1; + } +#endif + // App mode: Double Reset detection or DFU startup for nrf52832 if (!(just_start_app || dfu_start || !valid_app)) { #ifdef NRF52832_XXAA @@ -371,20 +406,100 @@ static uint32_t ble_stack_init(void) { blecfg.conn_cfg.params.gap_conn_cfg.event_length = BLEGAP_EVENT_LENGTH; sd_ble_cfg_set(BLE_CONN_CFG_GAP, &blecfg, ram_start); + // HVN queue size + varclr(&blecfg); + blecfg.conn_cfg.conn_cfg_tag = BLE_CONN_CFG_HIGH_BANDWIDTH; + blecfg.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = BLEGATTS_HVN_QSIZE; + sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &blecfg, ram_start); + + // WRITE COMMAND queue size + varclr(&blecfg); + blecfg.conn_cfg.conn_cfg_tag = BLE_CONN_CFG_HIGH_BANDWIDTH; + blecfg.conn_cfg.params.gattc_conn_cfg.write_cmd_tx_queue_size = BLEGATTC_WRCMD_QSIZE; + sd_ble_cfg_set(BLE_CONN_CFG_GATTC, &blecfg, ram_start); + // Enable BLE stack. // Note: Interrupt state (enabled, forwarding) is not work properly if not enable ble sd_ble_enable(&ram_start); -#if 0 +#if BLEGATT_ATT_MTU_MAX > 23 || defined(GPIO_PA_PIN) || defined(GPIO_LNA_PIN) ble_opt_t opt; +#endif + +#if BLEGATT_ATT_MTU_MAX > 23 varclr(&opt); opt.common_opt.conn_evt_ext.enable = 1; // enable Data Length Extension sd_ble_opt_set(BLE_COMMON_OPT_CONN_EVT_EXT, &opt); #endif +#if defined(GPIO_PA_LNA_MODE_PIN) + // Set PA / LNA Mode Pin: Low for Normal operation + nrf_gpio_cfg_output(GPIO_PA_LNA_MODE_PIN); + nrf_gpio_pin_clear(GPIO_PA_LNA_MODE_PIN); +#endif + +#if defined(GPIO_PA_LNA_SELECT_PIN) + // Set PA / LNA Select Pin: low for u.FL + nrf_gpio_cfg_output(GPIO_PA_LNA_SELECT_PIN); + nrf_gpio_pin_clear(GPIO_PA_LNA_SELECT_PIN); +#endif + + // Configure SoftDevice PA / LNA assist if required +#if defined(GPIO_PA_PIN) || defined(GPIO_LNA_PIN) + + static const uint32_t gpio_toggle_ch = 0; + static const uint32_t ppi_set_ch = 0; + static const uint32_t ppi_clr_ch = 1; + + varclr(&opt); + + // Common PA / LNA config + // GPIOTE channel + opt.common_opt.pa_lna.gpiote_ch_id = gpio_toggle_ch; + // PPI channel for pin learing + opt.common_opt.pa_lna.ppi_ch_id_clr = ppi_clr_ch; + // PPI channel for pin setting + opt.common_opt.pa_lna.ppi_ch_id_set = ppi_set_ch; + +# if defined(GPIO_PA_PIN) + // -- PA config -- + // Set the pin to be active high + opt.common_opt.pa_lna.pa_cfg.active_high = GPIO_PA_PIN_ACTIVE_STATE; + // Enable toggling + opt.common_opt.pa_lna.pa_cfg.enable = 1; + // The GPIO pin to toggle + opt.common_opt.pa_lna.pa_cfg.gpio_pin = GPIO_PA_PIN; +# endif + +# if defined(GPIO_LNA_PIN) + // -- LNA config -- + // Set the pin to be active high + opt.common_opt.pa_lna.lna_cfg.active_high = GPIO_LNA_PIN_ACTIVE_STATE; + // Enable toggling + opt.common_opt.pa_lna.lna_cfg.enable = 1; + + // The GPIO pin to toggle + opt.common_opt.pa_lna.lna_cfg.gpio_pin = GPIO_LNA_PIN; + sd_ble_opt_set(BLE_COMMON_OPT_PA_LNA, &opt); +# endif + + // Set TX power for scan responses + sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_SCAN_INIT, 0, RADIO_TXPOWER_TXPOWER_Neg8dBm); + + // Set TX power for advertisements + sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, 0, RADIO_TXPOWER_TXPOWER_Neg8dBm); + // (Tx power setting for connections inherit the scan or advertising power setting) + +#endif + return NRF_SUCCESS; } +/*------------------------------------------------------------------*/ +/* SoftDevice Event handler + *------------------------------------------------------------------*/ +extern void ble_evt_dispatch(ble_evt_t *p_ble_evt); + // Process BLE event from SD uint32_t proc_ble(void) { __ALIGN(4) uint8_t ev_buf[BLE_EVT_LEN_MAX(BLEGATT_ATT_MTU_MAX)]; @@ -400,10 +515,22 @@ uint32_t proc_ble(void) { // Handle valid event, ignore error if (NRF_SUCCESS == err) { switch (evt->header.evt_id) { - case BLE_GAP_EVT_CONNECTED: + case BLE_GAP_EVT_CONNECTED: { + // Try to enable 2M phy,if phone allows it + ble_gap_phys_t const phys = + { + .rx_phys = BLE_GAP_PHY_AUTO, + .tx_phys = BLE_GAP_PHY_AUTO, + }; + sd_ble_gap_phy_update(evt->evt.gap_evt.conn_handle, &phys); + _ota_connected = true; + + // Remember someone connected to BLE + _ota_was_connected = true; led_state(STATE_BLE_CONNECTED); break; + } case BLE_GAP_EVT_DISCONNECTED: _ota_connected = false; @@ -415,7 +542,6 @@ uint32_t proc_ble(void) { } // from dfu_transport_ble - extern void ble_evt_dispatch(ble_evt_t* p_ble_evt); ble_evt_dispatch(evt); } @@ -436,7 +562,9 @@ uint32_t proc_soc(void) { (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((uint32_t) usbevt); + if (usbevt >= 0) { + tusb_hal_nrf_power_event((uint32_t)usbevt); + } #endif } diff --git a/src/pstorage_platform.h b/src/pstorage_platform.h index bbc573c..959005c 100644 --- a/src/pstorage_platform.h +++ b/src/pstorage_platform.h @@ -78,7 +78,7 @@ static __INLINE uint32_t pstorage_flash_page_end() #define PSTORAGE_SWAP_ADDR PSTORAGE_DATA_END_ADDR #define PSTORAGE_MAX_BLOCK_SIZE PSTORAGE_FLASH_PAGE_SIZE /**< Maximum size of block that can be registered with the module. Should be configured based on system requirements. And should be greater than or equal to the minimum size. */ -#define PSTORAGE_CMD_QUEUE_SIZE 10 /**< Maximum number of flash access commands that can be maintained by the module for all applications. Configurable. */ +#define PSTORAGE_CMD_QUEUE_SIZE 18 /**< Maximum number of flash access commands that can be maintained by the module for all applications. Configurable. */ /**@breif Define this flag in case Raw access to persistent memory is to be enabled. Raw mode * unlike the data mode is for uses other than storing data from various mode. This mode is diff --git a/src/sdk_config.h b/src/sdk_config.h index 50e8196..b61b1f0 100644 --- a/src/sdk_config.h +++ b/src/sdk_config.h @@ -38,8 +38,6 @@ * */ - - #ifndef SDK_CONFIG_H #define SDK_CONFIG_H @@ -66,7 +64,7 @@ #define HCI_MEM_POOL_ENABLED 1 #define HCI_TX_BUF_SIZE 600 // not used #define HCI_RX_BUF_SIZE 600 -#define HCI_RX_BUF_QUEUE_SIZE 8 // must be power of 2 +#define HCI_RX_BUF_QUEUE_SIZE 16 // must be power of 2 //========================================================== // UART_ENABLED - nrf_drv_uart - UART/UARTE peripheral driver @@ -119,6 +117,12 @@ #define CRC16_ENABLED 1 #define NRF_STRERROR_ENABLED 1 +//--------------------------------------------------------------------+ +// +//--------------------------------------------------------------------+ +#define BLEGATT_ATT_MTU_MAX 247 +#define BLE_CONN_CFG_HIGH_BANDWIDTH 1 + #endif //SDK_CONFIG_H diff --git a/src/usb/msc_uf2.c b/src/usb/msc_uf2.c index 4b6817f..96d705b 100644 --- a/src/usb/msc_uf2.c +++ b/src/usb/msc_uf2.c @@ -171,6 +171,7 @@ void tud_msc_write10_complete_cb(uint8_t lun) dfu_update_status_t update_status; memset(&update_status, 0, sizeof(dfu_update_status_t )); update_status.status_code = DFU_RESET; + update_status.restart_into_bootloader = false; bootloader_dfu_update_process(update_status); @@ -195,9 +196,10 @@ void tud_msc_write10_complete_cb(uint8_t lun) { // update bootloader always end with reset update_status.status_code = DFU_RESET; + update_status.restart_into_bootloader = false; // Location of current stored new bootloader - uint32_t * new_bootloader = (uint32_t *) BOOTLOADER_ADDR_NEW_RECIEVED; + uint32_t * new_bootloader = (uint32_t *) BOOTLOADER_ADDR_NEW_RECEIVED; PRINT_HEX(new_bootloader); diff --git a/src/usb/tusb_config.h b/src/usb/tusb_config.h index b76c87b..e75a63d 100644 --- a/src/usb/tusb_config.h +++ b/src/usb/tusb_config.h @@ -53,7 +53,9 @@ //------------- Class enabled -------------// #define CFG_TUD_CDC 1 +#if !defined(SIGNED_FW) || defined(FORCE_UF2) #define CFG_TUD_MSC 1 +#endif /*------------------------------------------------------------------*/ /* CLASS DRIVER diff --git a/src/usb/uf2/ghostfat.c b/src/usb/uf2/ghostfat.c index d748904..97753ef 100644 --- a/src/usb/uf2/ghostfat.c +++ b/src/usb/uf2/ghostfat.c @@ -40,12 +40,19 @@ // //--------------------------------------------------------------------+ +// Add nonstring attribute if supported to avoid errors in GCC 15 +#if defined(__has_attribute) && __has_attribute(nonstring) + #define ATTR_NONSTRING __attribute__((nonstring)) +#else + #define ATTR_NONSTRING +#endif + typedef struct { uint8_t JumpInstruction[3]; - uint8_t OEMInfo[8]; - uint16_t SectorSize; - uint8_t SectorsPerCluster; - uint16_t ReservedSectors; + uint8_t OEMInfo[8] ATTR_NONSTRING; + uint16_t SectorSize; + uint8_t SectorsPerCluster; + uint16_t ReservedSectors; uint8_t FATCopies; uint16_t RootDirectoryEntries; uint16_t TotalSectors16; @@ -59,8 +66,8 @@ typedef struct { uint8_t Reserved; uint8_t ExtendedBootSig; uint32_t VolumeSerialNumber; - uint8_t VolumeLabel[11]; - uint8_t FilesystemIdentifier[8]; + uint8_t VolumeLabel[11] ATTR_NONSTRING; + uint8_t FilesystemIdentifier[8] ATTR_NONSTRING; } __attribute__((packed)) FAT_BootBlock; typedef struct { @@ -81,8 +88,8 @@ typedef struct { STATIC_ASSERT(sizeof(DirEntry) == 32); struct TextFile { - char const name[11]; - char const *content; + const char name[11] ATTR_NONSTRING; + const char *content; }; diff --git a/src/usb/uf2/uf2cfg.h b/src/usb/uf2/uf2cfg.h index e5a6398..c23a12e 100644 --- a/src/usb/uf2/uf2cfg.h +++ b/src/usb/uf2/uf2cfg.h @@ -32,4 +32,4 @@ #define BOOTLOADER_ADDR_END BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS // Address where new bootloader is written before activation (skip application data) -#define BOOTLOADER_ADDR_NEW_RECIEVED (USER_FLASH_END-DFU_BL_IMAGE_MAX_SIZE) +#define BOOTLOADER_ADDR_NEW_RECEIVED (USER_FLASH_END-DFU_BL_IMAGE_MAX_SIZE) diff --git a/src/usb/usb.c b/src/usb/usb.c index 30d91c0..ecc881b 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -94,7 +94,9 @@ void usb_init(bool cdc_only) { } usb_desc_init(cdc_only); +#if CFG_TUD_MSC uf2_init(); +#endif tusb_init(); #ifdef DISPLAY_PIN_SCK diff --git a/src/usb/usb_desc.c b/src/usb/usb_desc.c index ac1a8ac..4db68ec 100644 --- a/src/usb/usb_desc.c +++ b/src/usb/usb_desc.c @@ -33,8 +33,10 @@ enum { STRID_MSC }; +#if !defined(SIGNED_FW) || defined(FORCE_UF2) // CDC + MSC or CDC only mode static bool _cdc_only = false; +#endif // Serial is 64-bit DeviceID -> 16 chars len static char desc_str_serial[1+16]; @@ -84,6 +86,7 @@ enum { ITF_NUM_TOTAL }; +#if CFG_TUD_MSC uint8_t desc_configuration_cdc_msc[] = { // Interface count, string index, total length, attribute, power in mA @@ -95,6 +98,7 @@ uint8_t desc_configuration_cdc_msc[] = // Interface number, string index, EP Out & EP In address, EP size TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, STRID_MSC, 0x03, 0x83, 64), }; +#endif uint8_t desc_configuration_cdc_only[] = { @@ -112,15 +116,22 @@ uint8_t desc_configuration_cdc_only[] = uint8_t const * tud_descriptor_configuration_cb(uint8_t index) { (void) index; // for multiple configurations +#if CFG_TUD_MSC return _cdc_only ? desc_configuration_cdc_only : desc_configuration_cdc_msc; +#else + return desc_configuration_cdc_only; +#endif } // Enumerate as CDC + MSC or CDC only void usb_desc_init(bool cdc_only) { - _cdc_only = cdc_only; + (void)cdc_only; // for non MSC build +#if CFG_TUD_MSC + _cdc_only = cdc_only; if ( cdc_only ) +#endif { // Change PID to CDC only desc_device.idProduct = USB_DESC_CDC_ONLY_PID; @@ -154,7 +165,9 @@ char const* string_desc_arr [] = BLEDIS_MODEL, // 2: Product desc_str_serial, // 3: Serials, should use chip ID "nRF Serial", // 4: CDC Interface +#if CFG_TUD_MSC "nRF UF2", // 5: MSC Interface +#endif }; // up to 64 unicode characters diff --git a/supported_boards.md b/supported_boards.md new file mode 100644 index 0000000..82484fd --- /dev/null +++ b/supported_boards.md @@ -0,0 +1,59 @@ +# Supported Boards + +## Adafruit Boards + +| Board | Name | VID PID | URL | +| --- | --- | --- | --- | +| circuitplayground_nrf52840 | Adafruit Circuit Playground nRF52840 | 0x239A:0x0045 | https://www.adafruit.com/product/4333 | +| clue_nrf52840 | Adafruit CLUE nRF52840 | 0x239A:0x0071 | https://www.adafruit.com/product/4500 | +| feather_nrf52832 | Adafruit Feather nRF52832 | N/A | https://www.adafruit.com/product/3406 | +| feather_nrf52840_express | Adafruit Feather nRF52840 Express | 0x239A:0x0029 | https://www.adafruit.com/product/4062 | +| feather_nrf52840_sense | Adafruit Feather nRF52840 Sense | 0x239A:0x0087 | https://www.adafruit.com/product/4516 | +| feather_nrf52840_sense_tft | Adafruit Feather nRF52840 Sense TFT | 0x239A:0x0087 | https://www.adafruit.com/product/ | +| itsybitsy_nrf52840_express | Adafruit ItsyBitsy nRF52840 Express | 0x239A:0x0051 | https://www.adafruit.com/product/4481 | +| ledglasses_nrf52840 | Adafruit LED Glasses Driver nRF52840 | 0x239A:0x010D | https://www.adafruit.com/product/5217 | +| metro_nrf52840_express | Adafruit Metro nRF52840 Express | 0x239A:0x003F | https://www.adafruit.com/ | + +## 3rd Party Boards + +| Board | Name | VID PID | URL | +| --- | --- | --- | --- | +| adm_b_nrf52840_1 | AtelierDuMaker NRF52840 Breakout | 0x239A:0x009F | https://github.com/Atelier-Du-Maker/HolyIoT_NRF52840 | +| ae_bl652_bo | N/A | N/A | N/A | +| aramcon2_badge | ARAMCON2 Badge | 0x239A:0x007B | https://github.com/aramcon-badge | +| aramcon_badge_2019 | ARAMCON Badge 2019 | 0x239A:0x0079 | https://github.com/aramcon-badge | +| arduino_nano_33_ble | Arduino Nano 33 BLE | 0x239A:0x0063 | https://www.arduino.cc/ | +| bast_ble | Bast BLE | 0x1209:0x805A | https://www.electroniccats.com | +| bluemicro_nrf52833 | BlueMicro | 0x1D50:0x616F | http://bluemicro.jpconstantineau.com/ | +| bluemicro_nrf52840 | BlueMicro | 0x1D50:0x6160 | http://bluemicro.jpconstantineau.com/ | +| challenger_840_ble | ILabs Challenger 840 | 0x1209:0x7380 | https://www.ilabs.se | +| ebyte_e104_bt5032a | Ebyte E104-BT5032A nRF52832 | N/A | https://www.ebyte.com/en/product-view-news.html?id=756 | +| ebyte_e73_tbb | Ebyte E73-TBB nRF52832 | N/A | https://www.ebyte.com/en/product-view-news.aspx?id=889 | +| electronut_labs_papyr | Electronut Labs Papyr | 0x239A:0x003B | https://docs.electronut.in/papyr | +| ikigaisense_vita | IkigaiSense Vita nRF52840 | 0x239A:0x0093 | https://github.com/ikigaisense/vita | +| m60_keyboard | MakerDiary M60 Mechanical Keyboard | 0x2886:0xF00F | https://wiki.makerdiary.com/m60/ | +| mbn52832dk | Murata MBN52832DK | N/A | https://www.murata.com/ja-jp/products/connectivitymodule/bluetooth/overview/lineup/mbn52832 | +| mdk_nrf52840_dongle | MDK nRF52840 USB Dongle | 0x239A:0x0029 | https://wiki.makerdiary.com/nrf52840-mdk-usb-dongle/ | +| mikoto | Mikoto nRF52840 | 0x1209:0x7A01 | https://github.com/zhiayang/mikoto | +| nice_nano | nice!nano | 0x239A:0x00B3 | https://nicekeyboards.com/docs/nice-nano | +| nrf52840_bboard | nRF52840 BBoard | 0x1D50:0x6157 | https://github.com/ddB0515/nRF52840-BBoard | +| nRF52840_connect_kit | nRF52840 Connect Kit | 0x2886:0xF00F | https://wiki.makerdiary.com/nrf52840-connectkit/ | +| nrf52840_m2 | MakerDiary nRF52840 M.2 Module | 0x2886:0xF00F | https://wiki.makerdiary.com/nrf52840-m2 | +| nrfmicro | nRFMicro | 0x1209:0x5284 | https://github.com/joric/nrfmicro/wiki | +| ohs2020_badge | OHS2020 Badge | 0x239A:0x007F | https://2020.oshwa.org/ | +| omnimo_nrf52840 | Omnimo nRF52840 | 0x1209:0xCECE | https://www.crowdsupply.com/eafaq/omnimo-nrf52840 | +| particle_argon | Particle Argon | 0x239A:0x00DA | https://www.particle.io/mesh/ | +| particle_boron | Particle Boron | 0x239A:0x00DA | https://www.particle.io/mesh/ | +| particle_xenon | Particle Xenon | 0x239A:0x00DA | https://www.particle.io/mesh/ | +| pca10056 | Nordic nRF52840 DK | 0x239A:0x00DA | https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-DK | +| pca10059 | Nordic nRF52840 Dongle | 0x239A:0x0029 | https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-Dongle | +| pca10100 | Nordic nRF52833 DK | 0x239A:0x00D8 | https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52833-DK | +| pillbug | PillBug | 0x16D0:0x10ED | https://mechwild.com | +| pitaya_go | Pitaya Go | 0x2886:0xF00E | https://wiki.makerdiary.com/pitaya-go | +| raytac_mdbt50q_db_40 | Raytac MDBT50Q Demo Board 40 | 0x239A:0x00BB | https://www.raytac.com/product/ins.php?index_id=81 | +| raytac_mdbt50q_rx | Raytac MDBT50Q-RX | 0x239A:0x010B | https://www.adafruit.com/product/5199 | +| sparkfun_nrf52840_micromod | SparkFun MicroMod nRF52840 | 0x1B4F:0x0022 | https://www.sparkfun.com/products/16984 | +| t1000_e | Seeed T1000-E for Meshtastic | 0x2886:0x0057 | https://www.seeedstudio.com/SenseCAP-Card-Tracker-T1000-E-for-Meshtastic-p-5913.html | +| waveshare_nrf52840_eval | Waveshare nRF52840 Eval | 0x239A:0x0029 | https://www.waveshare.com/wiki/NRF52840_Eval_Kit | +| xiao_nrf52840_ble | Seeed XIAO nRF52840 | 0x2886:0x0044 | https://www.seeedstudio.com/ | +| xiao_nrf52840_ble_sense | Seeed XIAO nRF52840 | 0x2886:0x0045 | https://www.seeedstudio.com/ | diff --git a/tools/gen_boards.py b/tools/gen_boards.py new file mode 100644 index 0000000..140a0dd --- /dev/null +++ b/tools/gen_boards.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import argparse +import re +from pathlib import Path + + +BOARD_H_GLOB = "src/boards/*/board.h" + + +def _first_match(pattern: str, text: str) -> str | None: + match = re.search(pattern, text, flags=re.MULTILINE) + return match.group(1).strip() if match else None + + +def _parse_int(value: str | None) -> int | None: + if value is None: + return None + value = value.strip() + if value.lower().startswith("0x"): + try: + return int(value, 16) + except ValueError: + return None + try: + return int(value, 10) + except ValueError: + return None + + +def _fmt_vid_pid(vid: int | None, pid: int | None) -> str: + if vid is None or pid is None: + return "N/A" + return f"0x{vid:04X}:0x{pid:04X}" + + +def _escape_md(value: str) -> str: + return value.replace("|", "\\|") + + +def _load_board(board_h: Path, repo_root: Path) -> dict[str, str]: + text = board_h.read_text(errors="ignore") + board = board_h.parent.name + name = _first_match(r'^\s*#define\s+UF2_PRODUCT_NAME\s+"([^"]+)"', text) + url = _first_match(r'^\s*#define\s+UF2_INDEX_URL\s+"([^"]+)"', text) + vid = _parse_int(_first_match(r"^\s*#define\s+USB_DESC_VID\s+([0-9A-Fa-fxX]+)", text)) + pid = _parse_int( + _first_match(r"^\s*#define\s+USB_DESC_UF2_PID\s+([0-9A-Fa-fxX]+)", text) + ) + + return { + "board": board, + "name": name or "N/A", + "vid_pid": _fmt_vid_pid(vid, pid), + "url": url or "N/A", + } + + +def generate(repo_root: Path, output: Path) -> None: + boards: list[dict[str, str]] = [] + for board_h in sorted(repo_root.glob(BOARD_H_GLOB)): + boards.append(_load_board(board_h, repo_root)) + + lines: list[str] = [] + lines.append("# Supported Boards") + lines.append("") + def _is_adafruit(entry: dict[str, str]) -> bool: + name = entry["name"].lower() + board = entry["board"].lower() + return name.startswith("adafruit") or board.startswith("adafruit") + + def _render_table(entries: list[dict[str, str]]) -> None: + lines.append("| Board | Name | VID PID | URL |") + lines.append("| --- | --- | --- | --- |") + for entry in sorted(entries, key=lambda e: e["board"].lower()): + lines.append( + f"| {_escape_md(entry['board'])} | {_escape_md(entry['name'])} | " + f"{_escape_md(entry['vid_pid'])} | {_escape_md(entry['url'])} |" + ) + lines.append("") + + adafruit = [entry for entry in boards if _is_adafruit(entry)] + third_party = [entry for entry in boards if not _is_adafruit(entry)] + + lines.append("## Adafruit Boards") + lines.append("") + _render_table(adafruit) + + lines.append("## 3rd Party Boards") + lines.append("") + _render_table(third_party) + + output.write_text("\n".join(lines)) + + +def main() -> None: + parser = argparse.ArgumentParser( + description="Generate supported_boards.md from src/boards/*/board.h" + ) + parser.add_argument( + "--output", + default="supported_boards.md", + help="Output markdown file (default: supported_boards.md)", + ) + args = parser.parse_args() + + repo_root = Path(__file__).resolve().parents[1] + output = Path(args.output) + if not output.is_absolute(): + output = repo_root / output + + generate(repo_root, output) + + +if __name__ == "__main__": + main()