Code Monkey home page Code Monkey logo

adafruit_nrf52_bootloader's Introduction

Adafruit nRF52 Bootloader

Build Status

A CDC/DFU/UF2 bootloader for Nordic nRF52 microcontroller. 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 for more information.

DFU via serial/CDC requires adafruit-nrfutil, a modified version of Nordic nrfutil. Install python3 if it is not installed already and run this command to install adafruit-nrfutil from PyPi:

$ pip3 install --user adafruit-nrfutil

Supported Boards

Officially supported boards are:

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.

Features

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

How to use

There are two pins, DFU and FRST that bootloader will check upon reset/power:

  • Double Reset Reset twice within 500 ms will enter DFU with UF2 and CDC support (only works with nRF52840)
  • DFU = LOW and FRST = HIGH: Enter bootloader with UF2 and CDC support
  • DFU = LOW and FRST = LOW: Enter bootloader with OTA, to upgrade with a mobile application such as Nordic nrfConnect/Toolbox
  • DFU = HIGH and FRST = LOW: Factory Reset mode: erase firmware application and its data
  • DFU = HIGH and FRST = HIGH: Go to application code if it is present, otherwise enter DFU with UF2
  • The GPREGRET register can also be set to force the bootloader can enter any of above modes (plus a CDC-only mode for Arduino). GPREGRET is set by the application before performing a soft reset.
#include "nrf_nvic.h"
void reset_to_uf2(void) {
  NRF_POWER->GPREGRET = 0x57; // 0xA8 OTA, 0x4e Serial
  NVIC_SystemReset();         // or sd_nvic_SystemReset();
}

On the Nordic PCA10056 DK board, DFU is connected to Button1, and FRST is connected to Button2. So holding down Button1 while clicking RESET will put the board into USB bootloader mode, with UF2 and CDC support. Holding down Button2 while clicking RESET will put the board into OTA (over-the-air) bootloader mode.

On the Nordic PCA10059 Dongle board, DFU is connected to the white button. FRST is connected to pin 1.10. Ground it to pull FRST low, as if you had pushed an FRST button. There is an adjacent ground pad.

For other boards, please check the board definition for details.

Making your own UF2

To create your own UF2 DFU update image, simply use the Python conversion script on a .bin file or .hex file, specifying the family as 0xADA52840 (nRF52840) or 0x621E937A (nRF52833).

nRF52840
uf2conv.py firmware.hex -c -f 0xADA52840

nRF52833
uf2conv.py firmware.hex -c -f 0x621E937A

If using a .bin file with the conversion script you must specify application address with the -b switch, this address depend on the SoftDevice size/version e.g S140 v6 is 0x26000, v7 is 0x27000

nRF52840
uf2conv.py firmware.bin -c -b 0x26000 -f 0xADA52840

nRF52833
uf2conv.py firmware.bin -c -b 0x27000 -f 0x621E937A

To create a UF2 image for bootloader from a .hex file using separated family of 0xd663823c

uf2conv.py bootloader.hex -c -f 0xd663823c

Burn & Upgrade with pre-built binaries

You can burn and/or upgrade the bootloader with either a J-link or DFU (serial) to a specific pre-built binary version without the hassle of installing a toolchain and compiling the code. This is preferred if you are not developing/customizing the bootloader. Pre-builtin binaries are available on GitHub releases

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

You should only continue if you are looking to develop bootloader for your own. You must have have a J-Link available to "unbrick" your device.

Prerequisites

Build:

Firstly clone this repo with following commands

git clone https://github.com/adafruit/Adafruit_nRF52_Bootloader
cd Adafruit_nRF52_Bootloader
git submodule update --init

Then build it with make BOARD={board} all, for example:

make BOARD=feather_nrf52840_express all

For the list of supported boards, run make without BOARD= :

$ make
You must provide a BOARD parameter with 'BOARD='
Supported boards are: feather_nrf52840_express feather_nrf52840_express pca10056
Makefile:90: *** BOARD not defined.  Stop

Flash

To flash the bootloader (without softdevice/mbr) using JLink:

make BOARD=feather_nrf52840_express flash

If you are using pyocd as debugger, add FLASHER=pyocd to make command:

make BOARD=feather_nrf52840_express FLASHER=pyocd flash

To upgrade the bootloader using DFU Serial via port /dev/ttyACM0

make BOARD=feather_nrf52840_express SERIAL=/dev/ttyACM0 flash-dfu

To flash SoftDevice (will also erase chip):

make BOARD=feather_nrf52840_express flash-sd

To flash MBR only

make BOARD=feather_nrf52840_express flash-mbr

Common makefile problems

arm-none-eabi-gcc: No such file or directory

If you get the following error ...

$ make BOARD=feather_nrf52840_express all
Compiling file: main.c
/bin/sh: /usr/bin/arm-none-eabi-gcc: No such file or directory
make: *** [_build/main.o] Error 127

... you may need to pass the location of the GCC ARM toolchain binaries to make using the variable CROSS_COMPILE as below:

$ make CROSS_COMPILE=/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi- BOARD=feather_nrf52832 all

For other compile errors, check the gcc version with arm-none-eabi-gcc --version to insure it is at least 9.x.

ModuleNotFoundError: No module named 'intelhex'

Install python-intelhex with

pip install intelhex

make: nrfjprog: No such file or directory

Make sure that nrfjprog is available from the command-line. This binary is part of Nordic's nRF5x Command Line Tools.

adafruit_nrf52_bootloader's People

Contributors

aovestdipaperino avatar bmeisels avatar ddb0515 avatar dhalbert avatar dumam avatar fanoush avatar gpshead avatar hathach avatar henrygab avatar hyx0329 avatar ikigaisense avatar jamesadevine avatar jpconstantineau avatar kbladewht avatar ladyada avatar lyusupov avatar markbirss avatar mdxs avatar microbuilder avatar mmoskal avatar montvydas avatar mrninhvn avatar nicell avatar nitz avatar ogatatsu avatar pontuso avatar sabas1080 avatar spegs21 avatar tannewt avatar y4m-y4m avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_nrf52_bootloader's Issues

1.8Volts on PCA10059 ("Dongle")

After flashing the bootloader to the "Dongle", the dongle's on-chip LDO regulator gets to the mode where he outputs 1.8Volts instead of the standard (when you buy it) of 3.3Volts.

This makes the device un-programable even with the j-link EDU (can be programmed with only the J-link PRO)

Circuit Playground Bluefruit forcing OTA DFU mode

After applying the latest precompiled bootloader + SD for the Circuit Playground Bluefruit (circuitplayground_nrf52840_bootloader-0.2.12_s140_6.1.1), the device forces itself into OTA DFU mode (purple neopixel ring).

Holding down either button while resetting allows the device to enter CDC/UF2 DFU mode. However, on subsequent resets the device forces itself back into OTA DFU mode so there doesn't seem to be a way to run application firmware after a reset.

Set up

  • Circuit Playground Bluefruit
  • Mac OSX 10.14.6

To Reproduce
Steps to reproduce the behavior:

  1. Place Circuit Playground Bluefruit in CDC/UF2 DFU bootloader mode
  2. Apply new bootloader + SD
    adafruit-nrfutil --verbose dfu serial --package circuitplayground_nrf52840_bootloader-0.2.12_s140_6.1.1.zip -p /dev/tty.usbmodemXX -b 115200 --singlebank --touch 1200
  3. After receiving success message, the device enters OTA DFU mode (purple neopixel ring)
Starting DFU upgrade of type 3, SoftDevice size: 151016, bootloader size: 29200, application size: 0
Sending DFU start packet
Sending DFU init packet
Sending firmware file
########################################
########################################
########################################
########################################
########################################
########################################
########################################
########################################
################################
Activating new firmware

DFU upgrade took 19.310901165008545s
Device programmed.
  1. Enter CDC/UF2 DFU mode by holding either button 1 or 2 and resetting the device.
  2. Apply application firmware using either CDC or UF2.
  3. The application runs properly.
  4. Reset the device. It enters OTA DFU mode.

UF2: mismatched media types

Issue:

From Microsoft FATGEN103.pdf: "Whatever is placed [in boot sector media descriptor] must also be put in the low byte of the FAT[0] entry"

From the UF2 exposed on a feather, using feather_nrf52840_express_bootloader-0.2.9_s140_6.1.1.hex:

Struct/Field Value Start Length Note
boot_sector.media_descriptor F8h 15h 1h Hard drive
boot_sector.drive_number 0h 24h 1h Corresponds to floppy
fat0.media_type FFF0h 200h 2h Floppy
fat1.media_type FFF0h 4200h 2h Floppy

Fix

PR request coming soon.

Automate builds

Hey Thach, since you're doing a ton of work in this repo would it be helpful to have automatic builds on commits via travis?

Dan & I could get that going for you so that the hex files appear on S3 - then you wouldn't have to keep committing binaries as you build and we would have less risk of out-of-sync bootloaders between this and circuitpython repo!

Please let us know :)

Support Uf2 family option

as discussed previously, family option is to prevent dragging the wrong uf2. @ladyada do you have any number in your mind for nrf52840 ? If not, 0xADA52840 is a good number

Generate separate "update bootloader" image

Right now the bootloader can self-update, but if there is no existing UF2 bootloader, or it's corrupted, you have to use the SWD interface to initially load the bootloader.

Generate an "update-bootloader" image that can be loaded with Nordic's bootloader or this bootloader, which will replace the existing bootloader.

https://github.com/adafruit/uf2-samdx1 provides this capability with the update-bootloader-*.{bin.uf2,ino} files it generates. See selfmain.c and the SELF targets in the Makefile for how it does this. The .ino is an Arduino sketch that does the same thing, so you can update the bootloader even if all you have is just the Arduino IDE and you don't know how to use the nrf command-line tools to load an image. That would be an optional feature for this issue.

Issue filed at @hathach 's request.

./usb/tusb_descriptors.c:74:1: error: missing braces around initializer

I'm getting this odd build error. I tried going back a few commits and it did not go away. Tried with arm-none-eabi-gcc 7.2.1 and 7.3.1.

halbert@salmonx:~/repos/adafruit/Adafruit_nRF52_Bootloader/src$ make
Making feather52840 board
----------------------
Compiling file: main.c
Compiling file: dfu_ble_svc.c
Compiling file: tusb_descriptors.c
./usb/tusb_descriptors.c:74:1: error: missing braces around initializer [-Werror=missing-braces]
 {
 ^
cc1: all warnings being treated as errors
Makefile:327: recipe for target '_build/tusb_descriptors.o' failed
make[1]: *** [_build/tusb_descriptors.o] Error 1
Makefile:268: recipe for target 'all' failed
make: *** [all] Error 2

Add UF2 build/generation information to Readme

The only Adafruit supplied information about how to build for UF2 that I could find is found here.

It says to start to the flash at 0x4000 for M4 boards, which this is. With the MBR and soft device that doesn't work. The flash needs to be placed at 0x26000 with a flash size of 0xda000. The example blinky_pca10059_mbr works fine when updating through UF2 just by changing this in the Section Placement Macros in SES.

Additionally, I had to dig through the issues to find the family code, 0xADA52840.

This information should be more easily accessible.

MSC/UF2 to upgrade bootloader + SD

So far only DFU Serial could upgrade Bootloader + SD combo, uf2 should also do this as well. With a set of specific requirement e.g

  • family option is different than one used by application firmware
  • SD + bootloader must be upgraded at the same time to make sure that are in sync and work as expected
  • SD data contains must be check to make sure it is S140
  • uf2 of bootloader contain VID/PID which is used to prevent upgrading to incompatible board.

Add basic project framework

Create an appropriate project structure with Makefile, src folder, etc., based on the following requirements:

  • All external dependencies should be kept as sub-modules in the /lib sub-folder (as much as possible)
  • Doxygen style headers should be added to every function since all repositories moving forward will be run through travis-ci for build tests, and documentation will be published to the gh-pages branch on the repo.
  • Basic blinky code should be present when the bootloader code is running
  • a Segger Embedded Studio project file should be included for debugging, in addition to a platform-agnostic makefile

Design Goals

The USB code should be kept as small as possible since this goes into the bootloader, and an efficient but hacky solution may be better than a massive all-encompassing USB stack.

nRF52840 Feather Express Pinout problem

Symptom: connect SPI device to MISO pin and restart Feather. Bootloader enters Mass Storage DFU mode.

Problem: In src/boards/feather_nrf52840_express.h, the following appears

#define BUTTON_1              _PINNUM(0, 15)
#define BUTTON_2              _PINNUM(0, 19)

This does not agree with Adafruit schematic which appears to require

#define BUTTON_1              _PINNUM(1, 02)
#define BUTTON_2              _PINNUM(0, 18)

Use without softdevice

Hello,

I am trying to adopt this bootloader for use in non-BLE application, without softdevice.
Mainly due to UF2.

By commenting out -DBLE_STACK_SUPPORT_REQD and -DSOFTDEVICE_PRESENT and excluding compilation of few BLE-specific binaries and wrapping in ifdef few BLE-specific calls I was able to compile it, but it doesn't work for me. (I test on nrf52840-DK with flashed MBR)
Looking that there are those defines, it looks like somebody had in mind use of this boot-loader in non-BLE application.
Were there attempts to run without softdevice? Any suggestions?

Thanks!

pca10059.h Proposed Changes

Proposing a few changes here since I don't have the tooling to compile the bootloader to test if any of the changes break anything.

1 - Change how the buttons are defined. Use _PINNUM() function instead of obscure binary shift notation. (I think there is an error on the pins used but I am not sure) P1.06 is the button and P1.10 is the pin for the "second" button

2 - Add PRODUCT_NAME and VOLUME_LABEL defines.
Suggesting "DONGLE_BOOT" or "PCA10059_BOOT" as VOLUME_LABEL

3 - Add RGB LED as second LED instead of secondary LED (similar to the particle boards)
#define LED_RGB_RED_PIN _PINNUM(0, 8)
#define LED_RGB_GREEN_PIN _PINNUM(1, 9)
#define LED_RGB_BLUE_PIN _PINNUM(0, 12)

Feature & Release checklist

MODE

There are 2 bootloader modes: DFU serial (default) and OTA. In both modes, msc uf2 is supported with nrf52840.

Serial + UF2

  • [Physical] DFU pin = low (short hold) , FRST pin = high
  • [PCdriver] [52840] disconnect serial at 1200bps (arduino friendly)
  • [PCdriver] [52840] a custom USB command with control endpoint
  • [Firmware] Application code make a request using power register GPREGRET = serial magic ( 0x4E )
  • [Auto] Serial mode entered when there is no valid application code
  • DFU = high, FRST = low: Factory Reset, erase Application Code & Application Data then continue to Serial mode.
  • [52832] DFU Startup: DFU Serial is automatically entered whenever power on (even without any DFU condition) for 1 seconds for uploading sketch from Arduino IDE

OTA + UF2

  • [Physical] DFU = low , FRST = low
  • [Physical] DFU = low with long holding (e.g 5 seconds) until BLUE LED is blinking
  • [PCdriver] [52840] disconnect serial at 2400 bps
  • [PCdriver] [52840] a custom USB command with control endpoint
  • [Firmware] Application code make a request using power register GPREGRET = ota magic ( 0xA8 )
  • [BLE Central] Write to BLE DFU service

INDICATOR

  • DFU Serial : LED_RED is blinking fast (200ms), and 2x (100ms) when uploading
  • DFU OTA : LED_RED & LED_BLUE are blinking fast, LED_BLUE stay on when connected, LED_RED blink 2x when uploading
  • Factory Reset: RED will blink 2x, BLUE is turn on when erasing (very brief).

BEHAVIOR

  • DFU OTA timeout is 300 seconds ~ 5 minutes
  • DFU OTA, Device Information should have
    • Adv Name is AdaDFU
    • Manufacture String is Adafruit Industries
    • Model String is Bluefruit Feather nRF528xx (xx is either 32 or 40)
    • Firmware String is SDname SDversion rRev e.g S132 6.1.0 r0
  • DFU (Serial & OTA) only accept firmware built for it
    • 840 reject 832's application
    • 840 reject 832's bootloader package (sd + boot)
    • 840 reject 832's application uf2
    • 832 reject 840's application
    • 832 reject 840's bootloader package (sd + boot)
  • Update zip file from iOS/Android
  • Test upgrading modified bootloader of the same SD version
  • Test upgrading to different SD major version e.g v5 to v6

IDE

  • Burn bootloader on OSX/Windows/Linux
  • Upload sketch on OS/Windows/Linux
  • Upload sketch with Serial opened on OS/Windows/Linux
  • Download sketch via OTA with OSX Reason: missing OTA CLI that support package zip file.
  • Test with latest Arduino IDE

Double tap to USB and OTA

Let's have the bootloader do DFU and USB loading all at the same time. That way we don't need to teach a separate process for loading code OTA.

Add support for the S340 (ANT + BLE) SoftDevice

Is your feature request related to a problem? Please describe.
Not a problem as such, but a blocked to write ANT and ANT+ code.

Describe the solution you'd like
Support for the S340 (ANT + BLE) SoftDevice. This SoftDevice profile must be downloaded from thisisant.com, and thus the hex file cannot be shared. However, apart from that, the linker script needs to be created.

The blocker for me is this linker script, as I have no idea how to get the values for BOOTLOADER_SETTINGS and MBR_PARAMS_PAGE.

Describe alternatives you've considered
No alternatives.

Additional context
This is the only SoftDevice which supports ANT for the nRF52840 series.

[Bug] only partial fix for known SDK11 bootloader bug when updating soft device

There is known bug in bootloader code when updating SoftDevice which is larger than previous one https://devzone.nordicsemi.com/f/nordic-q-a/16774/updating-from-s132-v2-0-x-to-s132-v3-0-0-with-dual-bank-bootloader-from-sdk-v11-0-0-does-not-work

You actually do have fix for this here
https://github.com/adafruit/Adafruit_nRF52_Bootloader/blob/master/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c#L686

however same block alignment fix should be also here
https://github.com/adafruit/Adafruit_nRF52_Bootloader/blob/master/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c#L792
this code is called only when recovering from power failure or reset so the chance of triggering this is low

And same fix should be in dual bank code.

Hardcoded RXD/TXD pin

For the serial bootloader mode the RXD and TXD pins are hardcoded in sdk_config.h and changes in the boards/ folder do not propagate to the nordic SDK part of the bootloader.
I propose using the RXD/TXD/RTS/CTS pin definitions from the board headers in the sdk_config.h

DFU OTA always fails (nRF52840 board)

Someone has an idea? Am I using the tools wrongly?

DFU OTA update over nRFutil always fails after

[DFU] Response received (Op Code = 2, Status = 6)
[DFU] Remote DFU error: OPERATION FAILED

Build environment:
Hex file is created with Arduino IDE V1.8.7
Adafruit nRF52 board version 0.9.1
Board has Bootloader/Softdevice pca10056_bootloader_s140_6.1.1r0
(Tried feather_nrf52840_express variant, but no difference)

Creation of DFU OTA package:
adafruit-nrfutil dfu genpkg --application PPG-Prod.ino.hex Raytac-Prod-52840.zip
Content of created manifest.json:

{
    "manifest": {
        "application": {
            "bin_file": "PPG-Prod.ino.bin",
            "dat_file": "PPG-Prod.ino.dat",
            "init_packet_data": {
                "application_version": 4294967295,
                "device_revision": 65535,
                "device_type": 65535,
                "firmware_crc16": 11098,
                "softdevice_req": [
                    65534
                ]
            }
        },
        "dfu_version": 0.5
    }
}

nRF52 log:

nRF Connect, 2018-12-12
PPG-1A0C7447CE724A66 (F3:5E:96:95:DF:3B)
V	19:37:45.216	Connecting to F3:5E:96:95:DF:3B...
D	19:37:45.216	gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferred PHY = LE 1M)
D	19:37:45.466	[Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
D	19:37:45.467	[Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
I	19:37:45.467	Connected to F3:5E:96:95:DF:3B
V	19:37:45.494	Discovering services...
D	19:37:45.510	gatt.discoverServices()
I	19:37:45.931	Connection parameters updated (interval: 30.0ms, latency: 0, timeout: 2000ms)
I	19:37:46.233	Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 5000ms)
D	19:37:46.711	[Callback] Services discovered with status: 0
I	19:37:46.711	Services discovered
V	19:37:46.777	Generic Access (0x1800)
- Device Name [R W] (0x2A00)
- Appearance [R] (0x2A01)
- Peripheral Preferred Connection Parameters [R] (0x2A04)
- Central Address Resolution [R] (0x2AA6)
Generic Attribute (0x1801)
- Service Changed [I] (0x2A05)
Client Characteristic Configuration (0x2902)
Device Firmware Update Service (00001530-1212-efde-1523-785feabcd123)
- DFU Packet [WNR] (00001532-1212-efde-1523-785feabcd123)
- DFU Control Point [N W] (00001531-1212-efde-1523-785feabcd123)
Client Characteristic Configuration (0x2902)
- DFU Version [R] (00001534-1212-efde-1523-785feabcd123)
Device Information (0x180A)
- Model Number String [R] (0x2A24)
- Serial Number String [R] (0x2A25)
- Firmware Revision String [R] (0x2A26)
- Software Revision String [R] (0x2A28)
- Manufacturer Name String [R] (0x2A29)
Nordic UART Service (6e400001-b5a3-f393-e0a9-e50e24dcca9e)
- TX Characteristic [N] (6e400003-b5a3-f393-e0a9-e50e24dcca9e)
Client Characteristic Configuration (0x2902)
Characteristic User Description (0x2901)
- RX Characteristic [W WNR] (6e400002-b5a3-f393-e0a9-e50e24dcca9e)
Characteristic User Description (0x2901)
Battery Service (0x180F)
- Battery Level [N R] (0x2A19)
Client Characteristic Configuration (0x2902)
Heart Rate (0x180D)
- Heart Rate Measurement [N R] (0x2A37)
Client Characteristic Configuration (0x2902)
- Body Sensor Location [R] (0x2A38)
D	19:37:46.777	gatt.setCharacteristicNotification(00002a05-0000-1000-8000-00805f9b34fb, true)
D	19:37:46.779	gatt.setCharacteristicNotification(00001531-1212-efde-1523-785feabcd123, true)
D	19:37:46.782	gatt.setCharacteristicNotification(6e400003-b5a3-f393-e0a9-e50e24dcca9e, true)
D	19:37:46.784	gatt.setCharacteristicNotification(00002a19-0000-1000-8000-00805f9b34fb, true)
D	19:37:46.785	gatt.setCharacteristicNotification(00002a37-0000-1000-8000-00805f9b34fb, true)
I	19:37:46.800	Connection parameters updated (interval: 30.0ms, latency: 0, timeout: 2000ms)
V	19:37:57.267	[DFU] DFU service started
V	19:37:57.267	[DFU] Opening file...
I	19:37:57.267	[DFU] Firmware file opened successfully
V	19:37:57.267	[DFU] Connecting to DFU target...
D	19:37:57.267	[DFU] gatt = device.connectGatt(autoConnect = false)
I	19:37:57.280	[DFU] Connected to F3:5E:96:95:DF:3B
V	19:37:57.281	[DFU] Discovering services...
D	19:37:57.281	[DFU] gatt.discoverServices()
I	19:37:57.288	[DFU] Services discovered
D	19:37:57.303	[DFU] wait(1000)
V	19:37:58.342	[DFU] Reading DFU version number...
D	19:37:58.342	[DFU] gatt.readCharacteristic(00001534-1212-efde-1523-785feabcd123)
I	19:37:58.463	[DFU] Read Response received from 00001534-1212-efde-1523-785feabcd123, value (0x): 01-00
A	19:37:58.463	[DFU] Version number read: 0.1
W	19:37:58.471	[DFU] Application with buttonless update found
V	19:37:58.471	[DFU] Jumping to the DFU Bootloader...
V	19:37:58.471	[DFU] Enabling notifications for 00001531-1212-efde-1523-785feabcd123
D	19:37:58.471	[DFU] gatt.setCharacteristicNotification(00001531-1212-efde-1523-785feabcd123, true)
D	19:37:58.474	[DFU] gatt.writeDescriptor(00002902-0000-1000-8000-00805f9b34fb, value=0x01-00)
I	19:37:58.523	[DFU] Data written to descr.00001531-1212-efde-1523-785feabcd123, value (0x): 01-00
V	19:37:58.523	[DFU] Notifications enabled for 00001531-1212-efde-1523-785feabcd123
A	19:37:58.523	[DFU] Notifications enabled
D	19:37:58.523	[DFU] wait(1000)
V	19:37:59.554	[DFU] Writing to characteristic 00001531-1212-efde-1523-785feabcd123
D	19:37:59.554	[DFU] gatt.writeCharacteristic(00001531-1212-efde-1523-785feabcd123)
D	19:38:01.596	[Callback] Connection state changed with status: 8 and new state: DISCONNECTED (0)
E	19:38:01.597	Error 8 (0x8): GATT CONN TIMEOUT
I	19:38:01.597	Disconnected
A	19:38:01.633	[DFU] Jump to bootloader sent (Op Code = 1, Upload Mode = 4)
I	19:38:01.633	[DFU] Disconnected by the remote device
D	19:38:01.633	[DFU] gatt.refresh() (hidden)
D	19:38:01.633	[Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED
D	19:38:01.636	[DFU] [Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED
D	19:38:01.683	[DFU] gatt.close()
V	19:38:01.694	[DFU] DFU service started
I	19:38:01.694	[DFU] Firmware file opened successfully
D	19:38:01.694	[DFU] wait(1000)
D	19:38:02.714	[DFU] wait(1000)
V	19:38:03.695	[DFU] Connecting to DFU target...
D	19:38:03.765	[DFU] gatt = device.connectGatt(autoConnect = false)
I	19:38:03.989	[DFU] Connected to F3:5E:96:95:DF:3B
D	19:38:03.990	[Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
V	19:38:04.016	[DFU] Discovering services...
D	19:38:04.016	[DFU] gatt.discoverServices()
D	19:38:04.016	[DFU] [Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
I	19:38:04.679	[DFU] Services discovered
D	19:38:04.704	[DFU] wait(1000)
V	19:38:05.693	[DFU] Reading DFU version number...
D	19:38:05.693	[DFU] gatt.readCharacteristic(00001534-1212-efde-1523-785feabcd123)
I	19:38:05.828	[DFU] Read Response received from 00001534-1212-efde-1523-785feabcd123, value (0x): 08-00
A	19:38:05.828	[DFU] Version number read: 0.8
D	19:38:05.829	[DFU] wait(1000)
V	19:38:06.830	[DFU] Enabling notifications for 00001531-1212-efde-1523-785feabcd123
D	19:38:06.830	[DFU] gatt.setCharacteristicNotification(00001531-1212-efde-1523-785feabcd123, true)
D	19:38:06.832	[DFU] gatt.writeDescriptor(00002902-0000-1000-8000-00805f9b34fb, value=0x01-00)
I	19:38:06.928	[DFU] Data written to descr.00001531-1212-efde-1523-785feabcd123, value (0x): 01-00
V	19:38:06.928	[DFU] Notifications enabled for 00001531-1212-efde-1523-785feabcd123
A	19:38:06.929	[DFU] Notifications enabled
D	19:38:06.929	[DFU] wait(1000)
V	19:38:07.930	[DFU] Writing to characteristic 00001531-1212-efde-1523-785feabcd123
D	19:38:07.931	[DFU] gatt.writeCharacteristic(00001531-1212-efde-1523-785feabcd123)
I	19:38:08.028	[DFU] Data written to 00001531-1212-efde-1523-785feabcd123, value (0x): 01-04
A	19:38:08.028	[DFU] DFU Start sent (Op Code = 1, Upload Mode = 4)
V	19:38:08.028	[DFU] Writing to characteristic 00001532-1212-efde-1523-785feabcd123
D	19:38:08.028	[DFU] gatt.writeCharacteristic(00001532-1212-efde-1523-785feabcd123)
I	19:38:08.030	[DFU] Data written to 00001532-1212-efde-1523-785feabcd123, value (0x): 00-00-00-00-00-00-00-00-44-36-01-00
A	19:38:08.030	[DFU] Firmware image size sent (0b, 0b, 79428b)
D	19:38:12.078	[Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
I	19:38:12.078	Connected to F3:5E:96:95:DF:3B
I	19:38:12.097	Notification received from 00001531-1212-efde-1523-785feabcd123, value: (0x) 10-01-01
A	19:38:12.097	"Response for: Start DFU
Value: Success" received
V	19:38:12.098	Discovering services...
D	19:38:12.098	gatt.discoverServices()
I	19:38:12.107	[DFU] Notification received from 00001531-1212-efde-1523-785feabcd123, value (0x): 10-01-01
D	19:38:12.108	[Callback] Services discovered with status: 0
A	19:38:12.108	[DFU] Response received (Op Code = 1 Status = 1)
A	19:38:12.108	[DFU] Writing Initialize DFU Parameters...
V	19:38:12.108	[DFU] Writing to characteristic 00001531-1212-efde-1523-785feabcd123
D	19:38:12.108	[DFU] gatt.writeCharacteristic(00001531-1212-efde-1523-785feabcd123)
I	19:38:12.108	Services discovered
V	19:38:12.135	Generic Access (0x1800)
- Device Name [R W] (0x2A00)
- Appearance [R] (0x2A01)
- Peripheral Preferred Connection Parameters [R] (0x2A04)
- Central Address Resolution [R] (0x2AA6)
Generic Attribute (0x1801)
- Service Changed [I] (0x2A05)
Client Characteristic Configuration (0x2902)
Device Firmware Update Service (00001530-1212-efde-1523-785feabcd123)
- DFU Packet [WNR] (00001532-1212-efde-1523-785feabcd123)
- DFU Control Point [N W] (00001531-1212-efde-1523-785feabcd123)
Client Characteristic Configuration (0x2902)
- DFU Version [R] (00001534-1212-efde-1523-785feabcd123)
Device Information (0x180A)
- Manufacturer Name String [R] (0x2A29)
- Model Number String [R] (0x2A24)
- Firmware Revision String [R] (0x2A26)
D	19:38:12.135	gatt.setCharacteristicNotification(00002a05-0000-1000-8000-00805f9b34fb, true)
D	19:38:12.137	gatt.setCharacteristicNotification(00001531-1212-efde-1523-785feabcd123, true)
I	19:38:12.187	[DFU] Data written to 00001531-1212-efde-1523-785feabcd123, value (0x): 02-00
V	19:38:12.187	[DFU] Writing to characteristic 00001532-1212-efde-1523-785feabcd123
D	19:38:12.187	[DFU] gatt.writeCharacteristic(00001532-1212-efde-1523-785feabcd123)
I	19:38:12.187	[DFU] Data written to 00001532-1212-efde-1523-785feabcd123, value (0x): FF-FF-FF-FF-FF-FF-FF-FF-01-00-FE-FF-E9-A9
V	19:38:12.187	[DFU] Writing to characteristic 00001531-1212-efde-1523-785feabcd123
D	19:38:12.187	[DFU] gatt.writeCharacteristic(00001531-1212-efde-1523-785feabcd123)
I	19:38:12.329	Notification received from 00001531-1212-efde-1523-785feabcd123, value: (0x) 10-02-06
A	19:38:12.330	"Response for: Initialize DFU Parameters
Value: Operation failed" received
I	19:38:12.331	[DFU] Data written to 00001531-1212-efde-1523-785feabcd123, value (0x): 02-01
A	19:38:12.331	[DFU] Initialize DFU Parameters completed
I	19:38:12.331	[DFU] Notification received from 00001531-1212-efde-1523-785feabcd123, value (0x): 10-02-06
A	19:38:12.331	[DFU] Response received (Op Code = 2, Status = 6)
E	19:38:12.347	[DFU] Remote DFU error: OPERATION FAILED
V	19:38:12.347	[DFU] Writing to characteristic 00001531-1212-efde-1523-785feabcd123
D	19:38:12.347	[DFU] gatt.writeCharacteristic(00001531-1212-efde-1523-785feabcd123)
D	19:38:17.403	[Callback] Connection state changed with status: 8 and new state: DISCONNECTED (0)
E	19:38:17.403	Error 8 (0x8): GATT CONN TIMEOUT
I	19:38:17.403	Disconnected
A	19:38:17.408	[DFU] Reset request sent
V	19:38:17.441	[DFU] Disconnecting...
D	19:38:17.442	[DFU] gatt.disconnect()
I	19:38:17.442	[DFU] Disconnected
D	19:38:17.442	[DFU] gatt.refresh() (hidden)
D	19:38:17.442	[DFU] gatt.close()
D	19:38:17.442	[DFU] wait(600)
D	19:38:17.472	[Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED
D	19:38:17.489	[DFU] [Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED
D	19:38:18.047	gatt.close()
D	19:38:18.050	wait(200)
V	19:38:18.252	Connecting to F3:5E:96:95:DF:3B...
D	19:38:18.252	gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferred PHY = LE 1M)

Copying UF2 fails on Windows 7 and 10

[Originally posted by @ATMakersBill as https://github.com/adafruit/circuitpython/issues/1575.]

Hi folks, I have a Feather NRF52840 and tried to install CP 4.0b2 on it. I entered bootloader mode and got the FTHR840BOOT drive. I copied the UF2 and got a failure
image

I have gotten different errors saying that the file is too large to fit on the device, but it always fails.

Here is my bootloader version.

UF2 Bootloader 0.2.6 lib/nrfx (v1.1.0-1-g096e770) lib/tinyusb (legacy-525-ga1c59649) s140 6.1.1
Model: Adafruit Feather nRF52840 Express
Board-ID: NRF52-Bluefruit-v0
Bootloader: s140 6.1.1
Date: Dec 21 2018

After multiple attempts, I was able to get the REPL started on beta1. I tried erase_filesystem() and it made no difference.

I switched to a second device and started with just beta1. That gave me an odd error saying the file had not been copied... but it then started up CIRCUITPY and works.

I still have the broken device (which is still broken) if you want any testing done.

This has been replicated on Discord

USB CDC Support

The first USB target should be CDC support with optional printf/scanf redirection, and an appropriate .inf file for Windows systems.

Application can't trigger OTA DFU

Boards: mdk-usb-dongle, pca10059
Env: Linux, nRF52 15.3 SDK

I have a custom application I've written that I've added buttonless DFU to, however I can't seem to get my application to actually flash an update over OTA. nRF Connect is able to initiate buttonless DFU (from both Android & nRF Connect on desktop), and I do see the board briefly go into DFU mode, however instead of flashing an update I simply get a GATT connection error and the board resets back into the application.

Looking at the bootloader code I should just be able to set gpregret to BOOTLOADER_DFU_START then do a reset from the soft device to get the chip to enter OTA DFU and perform a flash, however that doesn't seem to be working (which is what the default Nordic service does in ble_dfu).

Buttonless DFU is pretty straightforward, but for thoroughness:

  • Copied the relevant code sections from the buttonless DFU example in the SDK
  • Updated sdk_config.h by enabling BLE_DFU_ENABLED and NRF_DFU_BLE_BUTTONLESS_SUPPORTS_BONDS to support bondless behavior.
  • Adding the relevant code sections from the example project.
  • Updated the linker uicr_bootloader_start_address in the linker configuration to match the bootloader start address for this bootloader (0x10001014) (Board obviously won't boot without this defined).

UART logging in my app confirms that ble_dfu_buttonless_bootloader_start_finalize is called right before the board resets, so I'm confident that gpregret is set. It seems like the bootloader isn't seeing that register being set when it goes into DFU on reset.

Short of throwing a debugger at the bootloader to see if the register is picked up properly I've thrown everything I can think of at it, including adjusting the timeouts on both the bootloader and application. I feel like I'm missing something obvious in getting OTA DFU to work with this bootloader, but can't seem to figure it out myself so I'm looking for help. I've seen other users be able to get OTA DFU to work so I'm sure it's an implementation change I need to make, I'm just not sure what at this point.

Questions

  • Does this bootloader work with the ble_dfu service provided with Nordic out of the box, or do I need to make changes to the service itself?
  • Is there anything obvious missing in the implementation that I need to add? On pca10059 with the secure bootloader/example provided by Nordic I'm able to get things to work, porting it to this bootloader seems to be the problem.

Thanks for your help!

Nordic Serial DFU over CDC

As the path of least resistance, the first target for a USB bootloader should be recycling the existing serial bootloader from Nordic (as used on the nRF52832), redirecting it over USB CDC.

Compiling error

By trying to build the bootloader for nrf52832 I've got following error message:

make BOARD=feather_nrf52832 all
CC main.c In file included from lib/softdevice/s132_nrf52_6.1.0/s132_nrf52_6.1.0_API/include/nrf_sdm.h:55:0, from lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h:27, from lib/sdk11/components/libraries/bootloader_dfu/bootloader.h:27, from src/main.c:43: lib/softdevice/s132_nrf52_6.1.0/s132_nrf52_6.1.0_API/include/nrf_soc.h: In function 'sd_evt_get': lib/softdevice/s132_nrf52_6.1.0/s132_nrf52_6.1.0_API/include/nrf_soc.h:807:1: error: stack usage computation not supported for this target [-Werror] SVCALL(SD_EVT_GET, uint32_t, sd_evt_get(uint32_t * p_evt_id)); ^ cc1: all warnings being treated as errors make: *** [Makefile:448: _build-feather_nrf52832/main.o] Fehler 1

I've tried with gcc-arm-none-eabi 5_2-2015q4 and 7-2018-q2-update

Any way to secure against OTA DFU?

On instructions adafruit/Adafruit_nRF52_Arduino#218 (comment), I'm re-posting this issue against what is apparently a more appropriate repository.

Looking through the literature on these as carefully as I can, I've come across reference to a mode referred to as "OTA DFU", which can apparently be triggered by Nordic's nRF Toolbox application, allowing the storage memory to be rewritten over an unsecured bluetooth connection.

I've also seen indication that there is absolutely no security on this functionality at all: #162 (comment)

What I need to be able to do is disable this mode altogether, or in the very least, be able to program it with an update key that I (and only I) am in control of. This "feature" otherwise presents a security hole that makes it completely unsuitable for any application that has even fringe security related implications.

Bootloader uf2/cdc should run even without SD flashed

improve stability by making the bootloader uf2/cdc running even without SD. The work is already 90% done, the rest is setting that bootloader pull from the SD, MBR etc ... e.g SD size to flash to appropriate address etc ... it should use default one ( e.g SD 6.1.0 known size in case SD is not flashed).

Once the bootloader without SD (or corrupted) can be put into known good by dfu-flash with an pre-built binary in the bin directory.

USB Dongle (Nordic's) won't boot with 5V without connection with PC

I am prototyping something using the nRf52840 USB Dongle by Nordic (PCA10059).

Nordic's Dongle works with the power supply from the USB
BUT doesn't boot on the following 2 cases:

  1. by applying power to the VBUS and GND even-though those two pins are connected to the power supply of the USB port.
  2. by connecting it o a USB hub that provided only power (not data). I used an external-powered USB-hub and the dongle started working when the hub was connected to the PC, but didn't start working when the hub wasn't connected to the PC, but connected to the power.

I suspect this fault is caused by the bootloader and not the Nordic's Dongle. Correct me if I am wrong

EDIT:
It is a problem that happens only with Adafruit's bootloader, it doesn't happen with the bootloader that Nordic provides

I am using the
pca10059_bootloader-0.2.9_s140_6.1.1.hex
from here

Double-click reset possible?

@hathach @ladyada @tannewt

We were talking a few days ago about not being able to detect double-click in the bootloader because the nRF52 clears out everything on a hard reset. However, the nrf52840 data sheet in section 5.3.6.8 (page 69) says:

Note: The RAM is never reset, but depending on a reset source the content of RAM may be
corrupted.

So I just want to double-check if someone has actually tried this and confirmed that leaving a sentinel value in a RAM location doesn't work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.