Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: adafruit/Adafruit_nRF52_Bootloader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: moergo-sc/Adafruit_nRF52_Bootloader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 13 commits
  • 32 files changed
  • 3 contributors

Commits on May 29, 2022

  1. Add key matrix support

    moergo-sc authored and chrisandreae committed May 29, 2022
    Copy the full SHA
    a481855 View commit details
  2. Copy the full SHA
    fe3612a View commit details
  3. Copy the full SHA
    36abb1b View commit details

Commits on Jun 10, 2022

  1. Copy the full SHA
    c356f38 View commit details
  2. Update tinyusb

    moergo-sc committed Jun 10, 2022
    Copy the full SHA
    1d0c0cb View commit details
  3. Copy the full SHA
    2bdf34d View commit details

Commits on Jul 14, 2022

  1. Copy the full SHA
    3989b7c View commit details
  2. Update README.md

    moergo-sc authored Jul 14, 2022
    Copy the full SHA
    9d3bb3c View commit details

Commits on Aug 1, 2022

  1. Add post-upload delay

    When uploading concatenated UF2 files with different family ids, it's important
    that the bootloader continue receiving the rest of the file from the host, even
    if it knows that there's no more relevant blocks: otherwise the host operating
    system will assume an error and show the user a scary warning message.
    
    Wait a little bit after finishing the update process (and continue to process
    USB) to give this a chance to happen.
    chrisandreae committed Aug 1, 2022
    Copy the full SHA
    b232c40 View commit details
  2. Update nix shell: python 3.8

    Additionally, delete stray lorri envrc
    chrisandreae committed Aug 1, 2022
    Copy the full SHA
    c418e62 View commit details

Commits on Aug 7, 2022

  1. Copy the full SHA
    fea8f9b View commit details

Commits on Aug 19, 2022

  1. Copy the full SHA
    3a3d13b View commit details

Commits on Sep 23, 2024

  1. Pin to an older nixpkgs with a gcc-arm-embedded that builds

    To build with a newer gcc requires fixing `-Werror=array-bounds` issues in the bootloader.
    chrisandreae committed Sep 23, 2024
    Copy the full SHA
    bb68c75 View commit details
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -65,3 +65,5 @@ TAGS

.DS_Store
Makefile.user
workspace.code-workspace
.envrc
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -132,6 +132,7 @@ C_SRC += \
src/dfu_init.c \
src/flash_nrf5x.c \
src/main.c \
src/key_matrix.c

# all files in boards
C_SRC += src/boards/boards.c
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

[![Build Status](https://github.com/adafruit/Adafruit_nRF52_Bootloader/workflows/Build/badge.svg)](https://github.com/adafruit/Adafruit_nRF52_Bootloader/actions)

This is a CDC/DFU/UF2 bootloader for nRF52 boards.
This is a CDC/DFU/UF2 bootloader for nRF52 boards. It is further enhanced by [MoErgo](https://www.moergo.com) for additional key matrix support.

- [Adafruit CLUE](https://www.adafruit.com/product/4500)
- [Adafruit Circuit Playground Bluefruit](https://www.adafruit.com/product/4333)
@@ -22,6 +22,10 @@ This is a CDC/DFU/UF2 bootloader for nRF52 boards.
- Particle Boron
- Particle Xenon
- [SparkFun MicroMod nRF52840](https://www.sparkfun.com/products/16984)
- [Glove80 v0 Left Hand](https://www.moergo.com)
- [Glove80 v0 Right Hand](https://www.moergo.com)
- [Glove80 v1 Left Hand](https://www.moergo.com)
- [Glove80 v1 Right Hand](https://www.moergo.com)

UF2 is an easy-to-use bootloader that appears as a flash drive. You can just copy `.uf2`-format
application images to the flash drive to load new firmware. See https://github.com/Microsoft/uf2 and https://github.com/adafruit/uf2-samdx1 for more information.
@@ -46,6 +50,8 @@ git submodule update --init
- 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)
- (New) Key matrix support for entering DFU, and to wipe application configuration
- (New) Ability to define UF2 Application Family ID

## How to use

@@ -77,6 +83,30 @@ There is an adjacent ground pad.
For other boards, please check the board definition for details.
### Key Matrix Support
Added support for key matrix to scan for key presses at entry of bootloader.
If a combination of two keys is detected, it will enter DFU mode.
If another combination of two keys is detected, the application configuration area will be erased.
This feature is optional and must be configured in ```board.h```. An example definition is as follows:
```
//--------------------------------------------------------------------+
// KEY MATRIX
//--------------------------------------------------------------------+
#define ENABLE_KEY_MATRIX 1
#define KM_SCAN_DIR 0 // 1 = Scan with col pins, and read with row pins. 0 = Scan with row pins, and read with col pins
#define KM_COL_COUNT 7
#define KM_COL_PINS { _PINNUM(0, 2), _PINNUM(1, 4), _PINNUM(1, 6), _PINNUM(1, 7), _PINNUM(1, 5), _PINNUM(1, 3), _PINNUM(1, 1) }
#define KM_ROW_COUNT 6
#define KM_ROW_PINS { _PINNUM(0, 26), _PINNUM(0, 5), _PINNUM(0, 7), _PINNUM(1, 8), _PINNUM(0, 11), _PINNUM(0, 12) }
#define _KEYID(col_id, row_id) (col_id*KM_ROW_COUNT + row_id)
#define KM_COMBO_DFU {_KEYID(6, 5), _KEYID(3, 2)}
#define KM_COMBO_WIPE_CONFIG {_KEYID(6, 5), _KEYID(3, 1)}
#define KM_COMBO_COUNT 2
#define KM_COMBOS {KM_COMBO_DFU, KM_COMBO_WIPE_CONFIG}
```
### Making your own UF2
To create your own UF2 DFU update image, simply use the [Python conversion script](https://github.com/Microsoft/uf2/blob/master/utils/uf2conv.py) on a .bin file or .hex file, specifying the family as **0xADA52840** (nRF52840) or **0x621E937A** (nRF52833).
12 changes: 11 additions & 1 deletion lib/sdk11/components/libraries/bootloader_dfu/bootloader.c
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ typedef enum
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_PENDING_COMPLETE, /**< Bootloader status field for indicating that we are waiting for reset to give the USB MSC time to satisfy pending OS requests */
} 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. */
@@ -54,6 +55,13 @@ static bool m_cancel_timeout_on_usb; /**< If set the timeout is cancelled when U
APP_TIMER_DEF( _dfu_startup_timer );
volatile bool dfu_startup_packet_received = false;

static const uint32_t PENDING_COMPLETE_TIMEOUT_MS = 750;
APP_TIMER_DEF( _pending_complete_timer );

static void pending_complete_timer_handler(void * p_context) {
m_update_status = BOOTLOADER_COMPLETE;
}

/**@brief Function for handling callbacks from pstorage module.
*
* @details Handles pstorage results for clear and storage operation. For detailed description of
@@ -69,7 +77,9 @@ static void pstorage_callback_handler(pstorage_handle_t * p_handle,
// response then settings has been saved and update has completed.
if ((m_update_status == BOOTLOADER_SETTINGS_SAVING) && (op_code == PSTORAGE_STORE_OP_CODE))
{
m_update_status = BOOTLOADER_COMPLETE;
app_timer_create(&_pending_complete_timer, APP_TIMER_MODE_SINGLE_SHOT, pending_complete_timer_handler);
app_timer_start(_pending_complete_timer, APP_TIMER_TICKS(PENDING_COMPLETE_TIMEOUT_MS), NULL);
m_update_status = BOOTLOADER_PENDING_COMPLETE;
}

APP_ERROR_CHECK(result);
2 changes: 1 addition & 1 deletion lib/tinyusb
Submodule tinyusb updated 407 files
8 changes: 8 additions & 0 deletions linker/nrf52840.ld
Original file line number Diff line number Diff line change
@@ -21,6 +21,9 @@ MEMORY
/** Location of bootloader setting in flash. */
BOOTLOADER_SETTINGS (rw) : ORIGIN = 0xFF000, LENGTH = 0x1000

/** Location of flash with firmware cofiguration. */
FIRMWARE_CONFIG (rw) : ORIGIN = 0xEC000, LENGTH = 0x8000



/** RAM Region for bootloader. */
@@ -63,6 +66,11 @@ SECTIONS

} > BOOTLOADER_SETTINGS

/* Place the firmware configuration page in flash. */
.firmwareConfig(NOLOAD) :
{
} > FIRMWARE_CONFIG

/* Write the bootloader address in UICR. */
.uicrBootStartAddress :
{
20 changes: 20 additions & 0 deletions nix/adafruit-nrfutil.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ lib, buildPythonPackage, fetchPypi
, pyserial, click, ecdsa
}:

buildPythonPackage rec {
pname = "adafruit-nrfutil";
version = "0.5.3.post16";

src = fetchPypi {
inherit version pname;
sha256 = "1b941q13vcg31f6dy7ak2hbaq7b25ipjpz0jym8jkyahivf068dp";
};

propagatedBuildInputs = [
pyserial click ecdsa
];

doCheck = false;
# doInstallCheck = false;
}
4 changes: 4 additions & 0 deletions nix/pinned-nixpkgs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"url": "https://releases.nixos.org/nixpkgs/22.05-darwin/nixpkgs-darwin-22.05pre383202.058d97782ed/nixexprs.tar.xz",
"sha256": "0m00195y7l2b3mrzi26ljm32s24qp5paz15fqbd49iyfjzxv7xb8"
}
17 changes: 17 additions & 0 deletions nix/pinned-nixpkgs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ system ? builtins.currentSystem }:

let
pin = builtins.fromJSON (builtins.readFile ./pinned-nixpkgs.json);

nixpkgsSrc = builtins.fetchTarball {
inherit (pin) url sha256;
};
in

import nixpkgsSrc {
inherit system;
config = {
allowUnfree = true;
};
overlays = []; # prevent impure overlays
}
3 changes: 3 additions & 0 deletions segger/flash_placement.xml
Original file line number Diff line number Diff line change
@@ -28,6 +28,9 @@
<MemorySegment name="$(FLASH2_NAME:BOOTLOADER_SETTINGS)">
<ProgramSection alignment="4" load="No" name=".bootloaderSettings" />
</MemorySegment>
<MemorySegment name="$(FLASH6_NAME:FIRMWARE_CONFIG)">
<ProgramSection alignment="4" load="No" name=".firmwareConfig" />
</MemorySegment>
<MemorySegment name="$(FLASH3_NAME:MBR_PARAMS_PAGE)">
<ProgramSection alignment="4" load="No" name=".mbrParamsPage" keep="Yes" />
</MemorySegment>
15 changes: 15 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ pkgs ? (import ./nix/pinned-nixpkgs.nix {}) }:

with pkgs;
stdenv.mkDerivation {
name = "env";
buildInputs = [
gcc-arm-embedded
(
python3.withPackages(ps: [
ps.intelhex
(ps.callPackage ./nix/adafruit-nrfutil.nix {})
])
)
];
}
90 changes: 90 additions & 0 deletions src/boards/glove80_v0_lh/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2022 Stephen Cheng for Innaworks Development Limited
*
* 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 _GLOVE80_V0_LH_H
#define _GLOVE80_V0_LH_H

#define _PINNUM(port, pin) ((port)*32 + (pin))

/*------------------------------------------------------------------*/
/* Power Management
*------------------------------------------------------------------*/
// Enable DCDC for both REG0 and REG1 - see https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf52840%2Fpower.html&resultof=%22%44%43%44%43%45%4e%30%22%20%22%64%63%64%63%65%6e%30%22%20&anchor=unique_1227442007
#define ENABLE_DCDC_0 1
#define ENABLE_DCDC_1 1

// Set the RegOut0 voltage to be 2.4V
#define UICR_REGOUT0_VALUE UICR_REGOUT0_VOUT_2V4

/*------------------------------------------------------------------*/
/* LED
*------------------------------------------------------------------*/
#define LEDS_NUMBER 1
#define LED_PRIMARY_PIN _PINNUM(1, 10)
#define LED_STATE_ON 1

/*------------------------------------------------------------------*/
/* BUTTON
*------------------------------------------------------------------*/
#define BUTTONS_NUMBER 2
#define BUTTON_1 _PINNUM(1, 11) // SW3 CFG_FIRMWARE_UNLOCKED
#define BUTTON_2 _PINNUM(0, 10) // Not connected
#define BUTTON_PULL NRF_GPIO_PIN_PULLUP

//--------------------------------------------------------------------+
// BLE OTA
//--------------------------------------------------------------------+
#define BLEDIS_MANUFACTURER "MoErgo"
#define BLEDIS_MODEL "Glove80 LH"

//--------------------------------------------------------------------+
// USB
//--------------------------------------------------------------------+
#define USB_DESC_VID 0x239A
#define USB_DESC_UF2_PID 0x0029
#define USB_DESC_CDC_ONLY_PID 0x002A

//--------------------------------------------------------------------+
// KEY MATRIX
//--------------------------------------------------------------------+
#define ENABLE_KEY_MATRIX 1
#define KM_SCAN_DIR 0 // 1 = Scan with col pins, and read with row pins. 0 = Scan with row pins, and read with col pins
#define KM_COL_COUNT 7
#define KM_COL_PINS { _PINNUM(0, 2), _PINNUM(1, 4), _PINNUM(1, 6), _PINNUM(1, 7), _PINNUM(1, 5), _PINNUM(1, 3), _PINNUM(1, 1) }
#define KM_ROW_COUNT 6
#define KM_ROW_PINS { _PINNUM(0, 26), _PINNUM(0, 5), _PINNUM(0, 7), _PINNUM(1, 8), _PINNUM(0, 11), _PINNUM(0, 12) }
#define _KEYID(col_id, row_id) (col_id*KM_ROW_COUNT + row_id)
#define KM_COMBO_DFU {_KEYID(6, 6-1), _KEYID(3, 3-1)} // C6R6 + C3R3
#define KM_COMBO_WIPE_CONFIG {_KEYID(6, 6-1), _KEYID(3, 2-1)} // C6R6 + C3R2
#define KM_COMBO_COUNT 2
#define KM_COMBOS {KM_COMBO_DFU, KM_COMBO_WIPE_CONFIG}


//------------- UF2 -------------//
#define UF2_PRODUCT_NAME "Glove80 v0 LH"
#define UF2_VOLUME_LABEL "GLV80LHBOOT"
#define UF2_BOARD_ID "nRF52840-Glove80-LH-revA"
#define UF2_INDEX_URL "https://www.moergo.com"

#endif // _GLOVE80_V0_LH_H
1 change: 1 addition & 0 deletions src/boards/glove80_v0_lh/board.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MCU_SUB_VARIANT = nrf52840
19 changes: 19 additions & 0 deletions src/boards/glove80_v0_lh/pinconfig.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "boards.h"
#include "uf2/configkeys.h"

__attribute__((used, section(".bootloaderConfig")))
const uint32_t bootloaderConfig[] =
{
/* CF2 START */
CFG_MAGIC0, CFG_MAGIC1, // magic
5, 100, // used entries, total entries

204, 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
/* CF2 END */
};
Loading