Skip to content

Commit

Permalink
Merge pull request adafruit#1137 from hathach/nrf52_dfu_touch1200
Browse files Browse the repository at this point in the history
Nrf52 dfu touch1200, remove bootloader target
  • Loading branch information
dhalbert authored Aug 22, 2018
2 parents 580a191 + a516d11 commit 6bfff29
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 22,156 deletions.
42 changes: 18 additions & 24 deletions ports/nrf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os
$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os

.phony: all flash sd binary hex bootloader
.phony: all flash sd binary hex

all: binary hex uf2

Expand All @@ -266,6 +266,11 @@ hex: $(BUILD)/$(OUTPUT_FILENAME).hex
$(BUILD)/$(OUTPUT_FILENAME).hex: $(BUILD)/$(OUTPUT_FILENAME).elf
$(OBJCOPY) -O ihex $< $@

## Create uf2 file
uf2: $(BUILD)/$(OUTPUT_FILENAME).hex
$(ECHO) "Create $(OUTPUT_FILENAME).uf2"
$(PYTHON2) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xADA52840 -c -o "$(BUILD)/$(OUTPUT_FILENAME).uf2" $^

#####################
# Flash with debugger
#####################
Expand All @@ -286,9 +291,6 @@ sd: $(BUILD)/$(OUTPUT_FILENAME).hex
nrfjprog --program $< --sectorerase -f $(MCU_VARIANT)
nrfjprog --reset -f $(MCU_VARIANT)

bootloader:
nrfjprog --program $(BOOT_FILE).hex -f nrf52 --chiperase --reset

else ifeq ($(FLASHER), pyocd)

flash: $(BUILD)/$(OUTPUT_FILENAME).hex
Expand All @@ -303,21 +305,19 @@ sd: $(BUILD)/$(OUTPUT_FILENAME).hex
pyocd-flashtool -t $(MCU_SUB_VARIANT) $< --sector_erase
pyocd-tool -t $(MCU_SUB_VARIANT) reset $(BOOT_SETTING_ADDR)

bootloader:
pyocd-flashtool -t $(MCU_SUB_VARIANT) $(BOOT_FILE).hex --chip_erase
pyocd-tool -t $(MCU_SUB_VARIANT) reset

endif

#####################
# Flash with DFU
#####################
.phony: dfu-gen dfu-flash dfu-bootloader
.phony: dfu-gen dfu-flash

NRFUTIL = adafruit-nrfutil

ifeq ($(OS),Windows_NT)
NRFUTIL = ../../lib/nrfutil/binaries/win32/nrfutil.exe
ifeq ($(MCU_SUB_VARIANT),nrf52840)
DFU_TOUCH = --touch 1200
else
NRFUTIL = nrfutil
DFU_TOUCH =
endif

check_defined = \
Expand All @@ -327,22 +327,16 @@ __check_defined = \
$(if $(value $1),, \
$(error Undefined make flag: $1$(if $2, ($2))))

dfu-gen: $(BUILD)/$(OUTPUT_FILENAME).hex
$(NRFUTIL) dfu genpkg --sd-req 0xFFFE --dev-type 0x0052 --application $^ $(BUILD)/dfu-package.zip

## Flash with DFU serial
dfu-flash: $(BUILD)/dfu-package.zip
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0)
$(NRFUTIL) --verbose dfu serial --package $^ -p $(SERIAL) -b 115200 --singlebank

dfu-bootloader:
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
$(NRFUTIL) --verbose dfu serial --package $(BOOT_FILE).zip -p $(SERIAL) -b 115200
$(NRFUTIL) --verbose dfu serial --package $^ -p $(SERIAL) -b 115200 --singlebank $(DFU_TOUCH)

uf2: $(BUILD)/$(OUTPUT_FILENAME).hex
$(ECHO) "Create $(OUTPUT_FILENAME).uf2"
$(PYTHON2) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xADA52840 -c -o "$(BUILD)/$(OUTPUT_FILENAME).uf2" $^
## Create DFU package file
dfu-gen: $(BUILD)/dfu-package.zip

$(BUILD)/dfu-package.zip: dfu-gen
$(BUILD)/dfu-package.zip: $(BUILD)/$(OUTPUT_FILENAME).hex
$(NRFUTIL) dfu genpkg --sd-req 0xFFFE --dev-type 0x0052 --application $^ $(BUILD)/dfu-package.zip

$(BUILD)/$(OUTPUT_FILENAME).elf: $(OBJ)
$(ECHO) "LINK $@"
Expand Down
12 changes: 5 additions & 7 deletions ports/nrf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Target Board (BOARD) | Bluetooth Stack (SD) | Bluetooth Support | Flash
pca10040 | s132 | Peripheral and Scanner | [Segger](#segger-targets)
feather52832 | s132 | Peripheral and Scanner | [UART DFU](#dfu-targets)
pca10056 | s140 | Peripheral and Scanner | [Segger](#segger-targets)
feather52840 | s140 | Peripheral and Scanner | [UART DFU](#dfu-targets)

## Segger Targets

Expand All @@ -98,11 +99,9 @@ note: On Linux it might be required to link SEGGER's `libjlinkarm.so` inside nrf

## DFU Targets

sudo apt-get install build-essential libffi-dev pkg-config gcc-arm-none-eabi git python python-pip
git clone https://github.com/adafruit/Adafruit_nRF52_Arduino.git
cd Adafruit_nRF52_Arduino/tools/nrfutil-0.5.2/
sudo pip install -r requirements.txt
sudo python setup.py install
run follow command to install [adafruit-nrfutil](https://github.com/adafruit/Adafruit_nRF52_nrfutil) from PyPi

$ pip3 install --user adafruit-nrfutil

**make flash** and **make sd** will not work with DFU targets. Hence, **dfu-gen** and **dfu-flash** must be used instead.
* dfu-gen: Generates a Firmware zip to be used by the DFU flash application.
Expand All @@ -111,8 +110,7 @@ note: On Linux it might be required to link SEGGER's `libjlinkarm.so` inside nrf
Example on how to generate and flash feather52832 target:

make BOARD=feather52832 SD=s132
make BOARD=feather52832 SD=s132 dfu-gen
make BOARD=feather52832 SD=s132 dfu-flash
make BOARD=feather52832 SD=s132 dfu-gen dfu-flash

## Bluetooth LE REPL

Expand Down
30 changes: 13 additions & 17 deletions ports/nrf/boards/feather52832/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,15 @@ $ cd ports/nrf
$ ./drivers/bluetooth/download_ble_stack.sh
```

## Installing `nrfutil`
## Installing `adafruit-nrfutil`

The Adafruit Bluefruit nRF52 Feather ships with a serial and OTA BLE bootloader
that can be used to flash firmware images over a simple serial connection,
using the on-board USB serial converter.

If you haven't installed this command-line tool yet, go to the `/libs/nrfutil`
folder (where nrfutil 0.5.2 is installed as a sub-module) and run the following
commands:
run following command to install [adafruit-nrfutil](https://github.com/adafruit/Adafruit_nRF52_nrfutil) from PyPi

> If you get a 'sudo: pip: command not found' error running 'sudo pip install',
you can install pip via 'sudo easy_install pip'

```
$ cd ../../lib/nrfutil
$ sudo pip install -r requirements.txt
$ sudo python setup.py install
```
$ pip3 install --user adafruit-nrfutil

# Building and flashing firmware images

Expand Down Expand Up @@ -75,7 +66,7 @@ You can then connect over BLE UART using an application like Bluefruit LE
Connect, available for Android, iOS and OS X, or any other application that
supports the NUS service and allows you to send the corrent EOL sequence.

## Flashing binaries with `nrfutil`
## Flashing binaries with `adafruit-nrfutil`

### 1. **Update bootloader** to single-bank version

Expand All @@ -90,20 +81,25 @@ Due to the size of CircuitPython, we must migrate this bootloader to a
bootloader from the dual-bank version that ships on Arduino-based Adafruit
Feather52 boards to a single-bank CircuitPython compatible version:

Firstly clone the [Adafruit_nRF52_Bootloader](https://github.com/adafruit/Adafruit_nRF52_Bootloader.git) and enter its directory

$ git clone https://github.com/adafruit/Adafruit_nRF52_Bootloader.git
$ cd Adafruit_nRF52_Bootloader

#### S132 v2.0.1 single-bank (recommended):

By default s132 v2.0.1 is used when no `SOFTDEV_VERSION` field is passed in:
To flash bootloader with s132 v2.0.1

```
$ make BOARD=feather52832 SERIAL=/dev/tty.SLAB_USBtoUART boot-flash
$ make BOARD=feather_nrf52832 VERSION=2.0.1 SERIAL=/dev/tty.SLAB_USBtoUART dfu-flash
```

#### S132 v5.0.0 (BLE5, experimental):

To enable BLE5 support and the latest S132 release, flash the v5.0.0 bootloader via:
To flash bootloader with s132 v5.0.0

```
$ make BOARD=feather52832 SERIAL=/dev/tty.SLAB_USBtoUART SOFTDEV_VERSION=5.0.0 boot-flash
$ make BOARD=feather52832 VERSION=5.0.0 SERIAL=/dev/tty.SLAB_USBtoUART dfu-flash
```

### 2. Generate and flash a CircuitPython DFU .zip package over serial
Expand Down
2 changes: 0 additions & 2 deletions ports/nrf/boards/feather52832/bootloader/.gitattributes

This file was deleted.

9 changes: 0 additions & 9 deletions ports/nrf/boards/feather52832/bootloader/README.md

This file was deleted.

Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion ports/nrf/boards/feather52832/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ SD ?= s132
SOFTDEV_VERSION ?= 2.0.1

LD_FILE = boards/feather52832/custom_nrf52832_dfu_app_$(SOFTDEV_VERSION).ld
BOOT_FILE = boards/feather52832/bootloader/feather52_bootloader_$(SOFTDEV_VERSION)_s132_single

BOOT_SETTING_ADDR = 0x7F000
NRF_DEFINES += -DNRF52832_XXAA
59 changes: 22 additions & 37 deletions ports/nrf/boards/feather52840/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ update the core CircuitPython firmware and internal file system contents
using only a serial connection.

On empty devices, the serial bootloader will need to be flashed once using a
HW debugger such as a Segger J-Link before the serial updater (`nrfutil`) can
HW debugger such as a Segger J-Link before the serial updater (`adafruit-nrfutil`) can
be used.

### Install `nrfjprog`
Expand Down Expand Up @@ -79,20 +79,27 @@ JLinkARM.dll version: 6.20f
> This operation only needs to be done once, and only on boards that don't
already have the serial bootloader installed.

Firstly clone the [Adafruit_nRF52_Bootloader](https://github.com/adafruit/Adafruit_nRF52_Bootloader.git) and enter its directory

```
$ git clone https://github.com/adafruit/Adafruit_nRF52_Bootloader.git
$ cd Adafruit_nRF52_Bootloader
```

Once `nrfjprog` is installed and available in `PATH` you can flash your
board with the serial bootloader via the following command:

```
make SD=s140 BOARD=feather52840 bootloader
make BOARD=feather_nrf52840_express VERSION=latest flash
```

This should give you the following (or very similar) output, and you will see
a DFU blinky pattern on one of the board LEDs:

```
$ make SD=s140 BOARD=feather52840 bootloader
Use make V=1, make V=2 or set BUILD_VERBOSE similarly in your environment to increase build verbosity.
nrfjprog --program boards/feather52840/bootloader/feather52840_bootloader_6.0.0_s140_single.hex -f nrf52 --chiperase --reset
$ make BOARD=pca10056 VERSION=latest flash
Flashing: bin/pca10056/6.0.0r0/pca10056_bootloader_s140_6.0.0r0.hex
nrfjprog --program bin/pca10056/6.0.0r0/pca10056_bootloader_s140_6.0.0r0.hex --chiperase -f nrf52 --reset
Parsing hex file.
Erasing user available code and UICR flash areas.
Applying system reset.
Expand All @@ -105,6 +112,8 @@ Run.
From this point onward, you can now use a simple serial port for firmware
updates.

Note: You can specify other version that are available in the directory `Adafruit_nRF52_Bootloader/bin/feather_nrf52840_express/` . The `VERSION=latest` will use the latest bootloader available.

### IMPORTANT: Disable Mass Storage on PCA10056 J-Link

The J-Link firmware on the PCA10056 implement USB Mass Storage, but this
Expand Down Expand Up @@ -135,31 +144,14 @@ J-Link>exit

## Building and Flashing CircuitPython

### Installing `nrfutil`

If you haven't installed the required command-line tool yet, go to the
`/libs/nrfutil` folder (where nrfutil 0.5.2b is installed as a sub-module)
and run the following commands:
### Installing `adafruit-nrfutil`

> If you get a 'sudo: pip: command not found' error running 'sudo pip install',
you can install pip via 'sudo easy_install pip'
run follow command to install [adafruit-nrfutil](https://github.com/adafruit/Adafruit_nRF52_nrfutil) from PyPi

```
$ cd ../../lib/nrfutil
$ sudo pip install -r requirements.txt
$ sudo python setup.py install
$ pip3 install adafruit-nrfutil --user
```

#### Changes to `nrfutil` in 0.5.2d

**IMPORTANT**: Make sure that you have version **0.5.2d**, since a small
change was required to `dfu_transport_serial.py` to account for the
increased minimum flash erase time on the nRF52840 compared to the earlier
nRF52832!

You can also manually change the file with the following new values (lines
67-68), and reinstall the utility via `sudo python setup.py install`:

### Flashing CircuitPython with USB CDC

With the serial bootloader present on your board, you first need to force your
Expand All @@ -169,8 +161,7 @@ BUTTON1 still pressed as you come out of reset).
This will give you a **fast blinky DFU pattern** to indicate you are in DFU
mode.

At this point, you can **build and flash** a CircuitPython binary via the following
command:
You can **build and flash** a CircuitPython binary via the following command:

```
$ make V=1 SD=s140 SERIAL=/dev/tty.usbmodem1411 BOARD=feather52840 all dfu-gen dfu-flash
Expand All @@ -197,20 +188,14 @@ Device programmed.

### Flashing CircuitPython with MSC UF2

Make `uf2` target to generate the uf2
uf2 file is generated last by `all` target

```
$ make V=1 SD=s140 SERIAL=/dev/tty.usbmodem1411 BOARD=feather52840 all uf2
$ make V=1 SD=s140 SERIAL=/dev/tty.usbmodem1411 BOARD=feather52840 all
Create firmware.uf2
../../tools/uf2/utils/uf2conv.py -c -o "build-feather52840-s140/firmware.uf2" "build-feather52840-s140/firmware.hex"
../../tools/uf2/utils/uf2conv.py -f 0xADA52840 -c -o "build-feather52840-s140/firmware.uf2" "build-feather52840-s140/firmware.hex"
Converting to uf2, output size: 392192, start address: 0x26000
Wrote 392192 bytes to build-feather52840-s140/firmware.uf2.
```

Simply drag and drop firmware.uf2 to the MSC, the nrf52840 will blink fast and reset after done.

**Note**: you need to update `tools/uf2` for uf2conv.py to support hex file input, current circuitpython's master use older verion of uf2conv.py which only support biin file input. To update, change directory to top folder of circuitpython and run. The size of uf2 should be ~400KB, if using the old uf2conv.py the output file would be 1 MB which is not correct.

```
git submodule update --init
```
Simply drag and drop firmware.uf2 to the MSC, the nrf52840 will blink fast and reset after done.
Loading

0 comments on commit 6bfff29

Please sign in to comment.