Merge pull request #431 from microbuilder/master

Added feather52 DFU support
This commit is contained in:
Dan Halbert 2017-11-10 07:42:15 -05:00 committed by GitHub
commit 2d0d1ef5f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 179 additions and 36 deletions

View File

@ -70,7 +70,7 @@ CFLAGS_MCU_m4 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-s
CFLAGS_MCU_m0 = $(CFLAGS_CORTEX_M) --short-enums -mtune=cortex-m0 -mcpu=cortex-m0 -mfloat-abi=soft -fno-builtin
CFLAGS += $(CFLAGS_MCU_$(MCU_SERIES))
CFLAGS += $(CFLAGS_MCU_$(MCU_SERIES))
CFLAGS += $(INC) -Wall -Werror -ansi -std=gnu99 -nostdlib $(COPT) $(NRF_DEFINES) $(CFLAGS_MOD)
CFLAGS += -fno-strict-aliasing
CFLAGS += -fstack-usage
@ -291,4 +291,3 @@ CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
endif
include ../../py/mkrules.mk

View File

@ -0,0 +1,110 @@
# Setup
Before you can build, you will need to run the following commands once:
```
$ cd circuitpython
$ git submodule update --init
$ make -C mpy-cross
```
You then need to download the SD and Nordic SDK files:
> This script relies on `wget`, which must be available from the command line.
```
$ cd ports/nrf
$ ./drivers/bluetooth/download_ble_stack.sh
```
# Building and flashing firmware images
## Building CircuitPython
#### REPL over UART (default settings)
To build a CircuitPython binary with default settings for the
`feather52` target enter:
```
$ make BOARD=feather52 V=1
```
#### REPL over BLE UART (AKA `NUS`)
To build a CircuitPython binary with REPL over BLE UART, edit
`bluetooth_conf.h` with the following values (under
`#elif (BLUETOOTH_SD == 132)`):
```
#define MICROPY_PY_BLE (1)
#define MICROPY_PY_BLE_NUS (1)
#define BLUETOOTH_WEBBLUETOOTH_REPL (1)
```
Then build the CircuitPython binary, including `SD=s132`
to enable BLE support in the build process:
```
$ make BOARD=feather52 V=1 SD=s132
```
## Flashing with `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.
These commands assume that you have already installed `nrfutil`, as described
in the [learning guide](https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide/arduino-bsp-setup)
for the Arduino variant of the board.
### 1. **Update bootloader** to single-bank version
The Adafruit nRF52 Feather ships, by default, with a **dual-bank** bootloader
that cuts the available flash memory in half in exchange for safer
OTA updates.
Due to the size of CircuitPython, we must migrate this bootloader to a
**single-bank** version, doubling the amount of flash memory available to us.
> These commands only need to be run once and will update the SoftDevice and
bootloader from the dual-bank version that ships on Arduino-based Adafruit
Feather52 boards to a single-bank CircuitPython compatible version:
#### S132 v2.0.1 single-bank (recommended):
By default s132 v2.0.1 is used when no `SOFTDEV_VERSION` field is passed in:
```
$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART boot-flash
```
#### S132 v5.0.0 (BLE5, experimental):
To enable BLE5 support and the latest S132 release, flash the v5.0.0 bootloader via:
```
$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART SOFTDEV_VERSION=5.0.0 boot-flash
```
### 2. Generate a CircuitPython DFU .zip package and flash it over serial
The following command will package and flash the CircuitPython binary using the
appropriate bootloader mentionned above.
This command assumes you have already build a valid circuitpython
image, as described earlier in this readme.
> The name of the serial port target will vary, depending on your OS.
```
$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART dfu-gen dfu-flash
```
If you built your CircuitPython binary with **BLE UART** support you will
need to add the `SD=s132` flag as shown below:
```
$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART SD=s132 dfu-gen dfu-flash
```

View File

@ -1,20 +1,31 @@
/*
GNU linker script for NRF52 w/ s132 2.0.1 SoftDevice
MEMORY MAP
------------------------------------------------------------------------
START ADDR END ADDR SIZE DESCRIPTION
---------- ---------- ------- -----------------------------------------
0x00074000..0x00080000 ( 48KB) Serial + OTA Bootloader
0x0006D000..0x00073FFF ( 28KB) Private Config Data (Bonding, Keys, etc.)
0x00055000..0x0006CFFF ( 96KB) User Filesystem
0x0001C000..0x00054FFF (228KB) Application Code
0x00001000..0x0001BFFF (108KB) SoftDevice
0x00000000..0x00000FFF (4KB) Master Boot Record
*/
/* Specify the memory areas */
/* Specify the memory areas (S132 2.0.1) */
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x080000 /* entire flash, 512 KiB */
FLASH_ISR (rx) : ORIGIN = 0x0001c000, LENGTH = 0x001000 /* sector 0, 4 KiB */
FLASH_TEXT (rx) : ORIGIN = 0x0001c400, LENGTH = 0x026c00 /* 152 KiB - APP - ISR */
FLASH_TEXT (rx) : ORIGIN = 0x0001d000, LENGTH = 0x038000 /* APP - ISR, 224 KiB */
RAM (xrw) : ORIGIN = 0x200039c0, LENGTH = 0x0c640 /* 49.5 KiB, give 8KiB headroom for softdevice */
}
/* produce a link error if there is not this amount of RAM for these sections */
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* top end of the stack */
/*_stack_end = ORIGIN(RAM) + LENGTH(RAM);*/
@ -24,4 +35,4 @@ _estack = ORIGIN(RAM) + LENGTH(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_end = 0x20007000; /* tunable */
INCLUDE "boards/common.ld"
INCLUDE "boards/common.ld"

View File

@ -0,0 +1,38 @@
/*
GNU linker script for NRF52 w/ s132 5.0.0 SoftDevice
MEMORY MAP
------------------------------------------------------------------------
START ADDR END ADDR SIZE DESCRIPTION
---------- ---------- ------- -----------------------------------------
0x00074000..0x00080000 ( 48KB) Serial + OTA Bootloader
0x0006D000..0x00073FFF ( 28KB) Private Config Data (Bonding, Keys, etc.)
0x00055000..0x0006CFFF ( 96KB) User Filesystem
0x00023000..0x00054FFF (200KB) Application Code
0x00001000..0x00022FFF (136KB) SoftDevice
0x00000000..0x00000FFF (4KB) Master Boot Record
*/
/* Specify the memory areas (S132 5.0.0) */
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x080000 /* entire flash, 512 KiB */
FLASH_ISR (rx) : ORIGIN = 0x00023000, LENGTH = 0x001000 /* sector 0, 4 KiB */
FLASH_TEXT (rx) : ORIGIN = 0x00024000, LENGTH = 0x030FFF /* APP - ISR, 200 KiB */
RAM (xrw) : ORIGIN = 0x200039c0, LENGTH = 0x0c640 /* 49.5 KiB, give 8KiB headroom for softdevice */
}
/* produce a link error if there is not this amount of RAM for these sections */
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* top end of the stack */
/*_stack_end = ORIGIN(RAM) + LENGTH(RAM);*/
_estack = ORIGIN(RAM) + LENGTH(RAM);
/* RAM extents for the garbage collector */
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_end = 0x20007000; /* tunable */
INCLUDE "boards/common.ld"

View File

@ -1,13 +1,15 @@
MCU_SERIES = m4
MCU_VARIANT = nrf52
MCU_SUB_VARIANT = nrf52832
SOFTDEV_VERSION = 2.0.1
SOFTDEV_VERSION ?= 2.0.1
LD_FILE = boards/feather52/custom_nrf52832_dfu_app.ld
LD_FILE = boards/feather52/custom_nrf52832_dfu_app_$(SOFTDEV_VERSION).ld
BOOTLOADER_PKG = boards/feather52/bootloader/feather52_bootloader_$(SOFTDEV_VERSION)_s132_single.zip
NRF_DEFINES += -DNRF52832_XXAA
check_defined = \
$(strip $(foreach 1,$1, \
$(call __check_defined,$1,$(strip $(value 2)))))
@ -15,11 +17,15 @@ __check_defined = \
$(if $(value $1),, \
$(error Undefined make flag: $1$(if $2, ($2))))
.PHONY: dfu-gen dfu-flash
.PHONY: dfu-gen dfu-flash boot-flash
dfu-gen:
nrfutil dfu genpkg --dev-type 0x0052 --application $(BUILD)/$(OUTPUT_FILENAME).hex $(BUILD)/dfu-package.zip
dfu-flash:
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0)
sudo nrfutil dfu serial --package $(BUILD)/dfu-package.zip -p $(SERIAL)
nrfutil dfu serial --package $(BUILD)/dfu-package.zip -p $(SERIAL) -b 115200
boot-flash:
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0)
nrfutil dfu serial --package $(BOOTLOADER_PKG) -p $(SERIAL) -b 115200

View File

@ -1,25 +1,4 @@
MCU_SERIES = m4
MCU_VARIANT = nrf52
MCU_SUB_VARIANT = nrf52832
SOFTDEV_VERSION = 2.0.1
LD_FILE = boards/feather52/custom_nrf52832_dfu_app.ld
NRF_DEFINES += -DNRF52832_XXAA
check_defined = \
$(strip $(foreach 1,$1, \
$(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = \
$(if $(value $1),, \
$(error Undefined make flag: $1$(if $2, ($2))))
.PHONY: dfu-gen dfu-flash
dfu-gen:
nrfutil dfu genpkg --dev-type 0x0052 --application $(BUILD)/$(OUTPUT_FILENAME).hex $(BUILD)/dfu-package.zip
dfu-flash:
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0)
sudo nrfutil dfu serial --package $(BUILD)/dfu-package.zip -p $(SERIAL)
# This file is a placeholder to enable building with 'SD=s132' flag
# The actual config data is stored in the file referenced below, regardless
# of whether S132 is actively used or not.
include boards/$(BOARD)/mpconfigboard.mk