Merge pull request #1137 from hathach/nrf52_dfu_touch1200

Nrf52 dfu touch1200, remove bootloader target
This commit is contained in:
Dan Halbert 2018-08-22 10:14:08 -04:00 committed by GitHub
commit 6bfff29d22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 86 additions and 22156 deletions

@ -1 +1 @@
Subproject commit 6d96b12e27ae60ca500365ee2137105145ada9dd
Subproject commit 7b35cd0203bc409d7c1aefc075672103cb4a913e

View File

@ -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
@ -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
#####################
@ -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
@ -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
ifeq ($(OS),Windows_NT)
NRFUTIL = ../../lib/nrfutil/binaries/win32/nrfutil.exe
NRFUTIL = adafruit-nrfutil
ifeq ($(MCU_SUB_VARIANT),nrf52840)
DFU_TOUCH = --touch 1200
else
NRFUTIL = nrfutil
DFU_TOUCH =
endif
check_defined = \
@ -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
$(NRFUTIL) --verbose dfu serial --package $^ -p $(SERIAL) -b 115200 --singlebank $(DFU_TOUCH)
dfu-bootloader:
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
$(NRFUTIL) --verbose dfu serial --package $(BOOT_FILE).zip -p $(SERIAL) -b 115200
## Create DFU package file
dfu-gen: $(BUILD)/dfu-package.zip
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" $^
$(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 $@"

View File

@ -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
@ -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.
@ -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

View File

@ -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
@ -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
@ -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

View File

@ -1,2 +0,0 @@
# Inform git that .zip files should be treated as binary
*.zip binary

View File

@ -1,9 +0,0 @@
# Adafruit nRF52 Feather Single-Bank Bootloader
These files contain an implementation of a single-bank bootloader,
which doubles the amount of flash memory available to applications
at the expense of safe over the air updates.
Two versions are present, based on release **2.0.1** and **5.0.0**
of the Nordic S132 SoftDevice. The SoftDevice is included as poart
of the bootloader binary.

View File

@ -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

View File

@ -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`
@ -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.
@ -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
@ -135,31 +144,14 @@ J-Link>exit
## Building and Flashing CircuitPython
### Installing `nrfutil`
### Installing `adafruit-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:
> 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
@ -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
@ -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.

View File

@ -5,12 +5,11 @@ SD ?= s140
SOFTDEV_VERSION ?= 6.0.0
BOOT_SETTING_ADDR = 0xFF000
BOOT_FILE = boards/$(BOARD)/bootloader/$(SOFTDEV_VERSION)/$(BOARD)_bootloader_$(SOFTDEV_VERSION)_s140
ifeq ($(SD),)
LD_FILE = boards/nrf52840_1M_256k.ld
else
LD_FILE = boards/bluefruit_$(MCU_SUB_VARIANT)_$(SD_LOWER)_$(SOFTDEV_VERSION).ld
LD_FILE = boards/adafruit_$(MCU_SUB_VARIANT)_$(SD_LOWER)_v$(firstword $(subst ., ,$(SOFTDEV_VERSION))).ld
endif
NRF_DEFINES += -DNRF52840_XXAA

View File

@ -5,13 +5,11 @@ SD ?= s140
SOFTDEV_VERSION ?= 6.0.0
BOOT_SETTING_ADDR = 0xFF000
BOOT_FILE = boards/$(BOARD)/bootloader/$(SOFTDEV_VERSION)/$(BOARD)_bootloader_$(SOFTDEV_VERSION)_s140
ifeq ($(SD),)
LD_FILE = boards/nrf52840_1M_256k.ld
else
LD_FILE = boards/bluefruit_$(MCU_SUB_VARIANT)_$(SD_LOWER)_$(SOFTDEV_VERSION).ld
LD_FILE = boards/adafruit_$(MCU_SUB_VARIANT)_$(SD_LOWER)_v$(firstword $(subst ., ,$(SOFTDEV_VERSION))).ld
endif
NRF_DEFINES += -DNRF52840_XXAA

View File

@ -94,9 +94,12 @@ void usb_init(void) {
//--------------------------------------------------------------------+
// tinyusb callbacks
//--------------------------------------------------------------------+
// Invoked when device is mounted
void tud_mount_cb(void) {
}
// Invoked when device is unmounted
void tud_umount_cb(void) {
}
@ -107,6 +110,28 @@ uint32_t tusb_hal_millis(void) {
return (uint32_t) ms;
}
// Invoked when cdc when line state changed e.g connected/disconnected
// Use to reset to DFU when disconnect with 1200 bps
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
(void) itf; // interface ID, not used
// disconnected event
if ( !dtr && !rts )
{
cdc_line_coding_t coding;
tud_cdc_get_line_coding(&coding);
if ( coding.bit_rate == 1200 )
{
enum { DFU_MAGIC_SERIAL = 0x4e };
NRF_POWER->GPREGRET = DFU_MAGIC_SERIAL;
NVIC_SystemReset();
}
}
}
#if MICROPY_KBD_EXCEPTION
/**