8000 Fixed feather52 DFU support · boneskull/circuitpython@237cc95 · GitHub
[go: up one dir, main page]

Skip to content

Commit 237cc95

Browse files
author
Kevin Townsend
committed
Fixed feather52 DFU support
1 parent 9564f7b commit 237cc95

8 files changed

+179
-36
lines changed

ports/nrf/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ CFLAGS_MCU_m4 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-s
7070
CFLAGS_MCU_m0 = $(CFLAGS_CORTEX_M) --short-enums -mtune=cortex-m0 -mcpu=cortex-m0 -mfloat-abi=soft -fno-builtin
7171

7272

73-
CFLAGS += $(CFLAGS_MCU_$(MCU_SERIES))
73+
CFLAGS += $(CFLAGS_MCU_$(MCU_SERIES))
7474
CFLAGS += $(INC) -Wall -Werror -ansi -std=gnu99 -nostdlib $(COPT) $(NRF_DEFINES) $(CFLAGS_MOD)
7575
CFLAGS += -fno-strict-aliasing
7676
CFLAGS += -fstack-usage
@@ -291,4 +291,3 @@ CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
291291
endif
292292

293293
include ../../py/mkrules.mk
294-

ports/nrf/boards/feather52/README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Setup
2+
3+
Before you can build, you will need to run the following commands once:
4+
5+
```
6+
$ cd circuitpython
7+
$ git submodule update --init
8+
$ make -C mpy-cross
9+
```
10+
11+
You then need to download the SD and Nordic SDK files:
12+
13+
> This script relies on `wget`, which must be available from the command line.
14+
15+
```
16+
$ cd ports/nrf
17+
$ ./drivers/bluetooth/download_ble_stack.sh
18+
```
19+
20+
# Building and flashing firmware images
21+
22+
## Building CircuitPython
23+
24+
#### REPL over UART (default settings)
25+
26+
To build a CircuitPython binary with default settings for the
27+
`feather52` target enter:
28+
29+
```
30+
$ make BOARD=feather52 V=1
31+
```
32+
33+
#### REPL over BLE UART (AKA `NUS`)
34+
35+
To build a CircuitPython binary with REPL over BLE UART, edit
36+
`bluetooth_conf.h` with the following values (under
37+
`#elif (BLUETOOTH_SD == 132)`):
38+
39+
```
40+
#define MICROPY_PY_BLE (1)
41+
#define MICROPY_PY_BLE_NUS (1)
42+
#define BLUETOOTH_WEBBLUETOOTH_REPL (1)
43+
```
44+
45+
Then build the CircuitPython binary, including `SD=s132`
46+
to enable BLE support in the build process:
47+
48+
```
49+
$ make BOARD=feather52 V=1 SD=s132
50+
```
51+
52+
## Flashing with `nrfutil`
53+
54+
The Adafruit Bluefruit nRF52 Feather ships with a serial and OTA BLE bootloader
55+
that can be used to flash firmware images over a simple serial connection,
56+
using the on-board USB serial converter.
57+
58+
These commands assume that you have already installed `nrfutil`, as described
59+
in the [learning guide](https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide/arduino-bsp-setup)
60+
for the Arduino variant of the board.
61+
62+
### 1. **Update bootloader** to single-bank version
63+
64+
The Adafruit nRF52 Feather ships, by default, with a **dual-bank** bootloader
65+
that cuts the available flash memory in half in exchange for safer
66+
OTA updates.
67+
68+
Due to the size of CircuitPython, we must migrate this bootloader to a
69+
**single-bank** version, doubling the amount of flash memory available to us.
70+
71+
> These commands only need to be run once and will update the SoftDevice and
72+
bootloader from the dual-bank version that ships on Arduino-based Adafruit
73+
Feather52 boards to a single-bank CircuitPython compatible version:
74+
75+
#### S132 v2.0.1 single-bank (recommended):
76+
77+
By default s132 v2.0.1 is used when no `SOFTDEV_VERSION` field is passed in:
78+
79+
```
80+
$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART boot-flash
81+
```
82+
83+
#### S132 v5.0.0 (BLE5, experimental):
84+
85+
To enable BLE5 support and the latest S132 release, flash the v5.0.0 bootloader via:
86+
87+
```
88+
$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART SOFTDEV_VERSION=5.0.0 boot-flash
89+
```
90+
91+
### 2. Generate a CircuitPython DFU .zip package and flash it over serial
92+
93+
The following command will package and flash the CircuitPython binary using the
94+
appropriate bootloader mentionned above.
95+
96+
This command assumes you have already build a valid circuitpython
97+
image, as described earlier in this readme.
98+
99+
> The name of the serial port target will vary, depending on your OS.
100+
101+
```
102+
$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART dfu-gen dfu-flash
103+
```
104+
105+
If you built your CircuitPython binary with **BLE UART** support you will
106+
need to add the `SD=s132` flag as shown below:
107+
108+
```
109+
$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART SD=s132 dfu-gen dfu-flash
110+
```
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
/*
22
GNU linker script for NRF52 w/ s132 2.0.1 SoftDevice
3+
4+
MEMORY MAP
5+
------------------------------------------------------------------------
6+
START ADDR END ADDR SIZE DESCRIPTION
7+
---------- ---------- ------- -----------------------------------------
8+
0x00074000..0x00080000 ( 48KB) Serial + OTA Bootloader
9+
0x0006D000..0x00073FFF ( 28KB) Private Config Data (Bonding, Keys, etc.)
10+
0x00055000..0x0006CFFF ( 96KB) User Filesystem
11+
0x0001C000..0x00054FFF (228KB) Application Code
12+
0x00001000..0x0001BFFF (108KB) SoftDevice
13+
0x00000000..0x00000FFF (4KB) Master Boot Record
314
*/
415

5-
/* Specify the memory areas */
16+
/* Specify the memory areas (S132 2.0.1) */
617
MEMORY
718
{
819
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x080000 /* entire flash, 512 KiB */
920
FLASH_ISR (rx) : ORIGIN = 0x0001c000, LENGTH = 0x001000 /* sector 0, 4 KiB */
10-
FLASH_TEXT (rx) : ORIGIN = 0x0001c400, LENGTH = 0x026c00 /* 152 KiB - APP - ISR */
21+
FLASH_TEXT (rx) : ORIGIN = 0x0001d000, LENGTH = 0x038000 /* APP - ISR, 224 KiB */
1122
RAM (xrw) : ORIGIN = 0x200039c0, LENGTH = 0x0c640 /* 49.5 KiB, give 8KiB headroom for softdevice */
1223
}
13-
24+
1425
/* produce a link error if there is not this amount of RAM for these sections */
1526
_minimum_stack_size = 2K;
1627
_minimum_heap_size = 16K;
17-
28+
1829
/* top end of the stack */
1930

2031
/*_stack_end = ORIGIN(RAM) + LENGTH(RAM);*/
@@ -24,4 +35,4 @@ _estack = ORIGIN(RAM) + LENGTH(RAM);
2435
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
2536
_heap_end = 0x20007000; /* tunable */
2637

27-
INCLUDE "boards/common.ld"
38+
INCLUDE "boards/common.ld"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
GNU linker script for NRF52 w/ s132 5.0.0 SoftDevice
3+
4+
MEMORY MAP
5+
------------------------------------------------------------------------
6+
START ADDR END ADDR SIZE DESCRIPTION
7+
---------- ---------- ------- -----------------------------------------
8+
0x00074000..0x00080000 ( 48KB) Serial + OTA Bootloader
9+
0x0006D000..0x00073FFF ( 28KB) Private Config Data (Bonding, Keys, etc.)
10+
0x00055000..0x0006CFFF ( 96KB) User Filesystem
11+
0x00023000..0x00054FFF (200KB) Application Code
12+
0x00001000..0x00022FFF (136KB) SoftDevice
13+
0x00000000..0x00000FFF (4KB) Master Boot Record
14+
*/
15+
16+
/* Specify the memory areas (S132 5.0.0) */
17+
MEMORY
18+
{
19+
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x080000 /* entire flash, 512 KiB */
20+
FLASH_ISR (rx) : ORIGIN = 0x00023000, LENGTH = 0x001000 /* sector 0, 4 KiB */
21+
FLASH_TEXT (rx) : ORIGIN = 0x00024000, LENGTH = 0x030FFF /* APP - ISR, 200 KiB */
22+
RAM (xrw) : ORIGIN = 0x200039c0, LENGTH = 0x0c640 /* 49.5 KiB, give 8KiB headroom for softdevice */
23+
}
24+
25+
/* produce a link error if there is not this amount of RAM for these sections */
26+
_minimum_stack_size = 2K;
27+
_minimum_heap_size = 16K;
28+
29+
/* top end of the stack */
30+
31+
/*_stack_end = ORIGIN(RAM) + LENGTH(RAM);*/
32+
_estack = ORIGIN(RAM) + LENGTH(RAM);
33+
34+
/* RAM extents for the garbage collector */
35+
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
36+
_heap_end = 0x20007000; /* tunable */
37+
38+
INCLUDE "boards/common.ld"
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
MCU_SERIES = m4
22
MCU_VARIANT = nrf52
33
MCU_SUB_VARIANT = nrf52832
4-
SOFTDEV_VERSION = 2.0.1
4+
SOFTDEV_VERSION ?= 2.0.1
55

6-
LD_FILE = boards/feather52/custom_nrf52832_dfu_app.ld
6+
LD_FILE = boards/feather52/custom_nrf52832_dfu_app_$(SOFTDEV_VERSION).ld
7+
BOOTLOADER_PKG = boards/feather52/bootloader/feather52_bootloader_$(SOFTDEV_VERSION)_s132_single.zip
78

89
NRF_DEFINES += -DNRF52832_XXAA
910

1011

12+
1113
check_defined = \
1214
$(strip $(foreach 1,$1, \
1315
$(call __check_defined,$1,$(strip $(value 2)))))
1416
__check_defined = \
1517
$(if $(value $1),, \
1618
$(error Undefined make flag: $1$(if $2, ($2))))
1719

18-
.PHONY: dfu-gen dfu-flash
20+
.PHONY: dfu-gen dfu-flash boot-flash
1921

2022
dfu-gen:
2123
nrfutil dfu genpkg --dev-type 0x0052 --application $(BUILD)/$(OUTPUT_FILENAME).hex $(BUILD)/dfu-package.zip
2224

2325
dfu-flash:
2426
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0)
25-
sudo nrfutil dfu serial --package $(BUILD)/dfu-package.zip -p $(SERIAL)
27+
nrfutil dfu serial --package $(BUILD)/dfu-package.zip -p $(SERIAL) -b 115200
28+
29+
boot-flash:
30+
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0)
31+
nrfutil dfu serial --package $(BOOTLOADER_PKG) -p $(SERIAL) -b 115200
Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,4 @@
1-
MCU_SERIES = m4
2-
MCU_VARIANT = nrf52
3-
MCU_SUB_VARIANT = nrf52832
4-
SOFTDEV_VERSION = 2.0.1
5-
6-
LD_FILE = boards/feather52/custom_nrf52832_dfu_app.ld
7-
8-
NRF_DEFINES += -DNRF52832_XXAA
9-
10-
11-
check_defined = \
12-
$(strip $(foreach 1,$1, \
13-
$(call __check_defined,$1,$(strip $(value 2)))))
14-
__check_defined = \
15-
$(if $(value $1),, \
16-
$(error Undefined make flag: $1$(if $2, ($2))))
17-
18-
.PHONY: dfu-gen dfu-flash
19-
20-
dfu-gen:
21-
nrfutil dfu genpkg --dev-type 0x0052 --application $(BUILD)/$(OUTPUT_FILENAME).hex $(BUILD)/dfu-package.zip
22-
23-
dfu-flash:
24-
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0)
25-
sudo nrfutil dfu serial --package $(BUILD)/dfu-package.zip -p $(SERIAL)
1+
# This file is a placeholder to enable building with 'SD=s132' flag
2+
# The actual config data is stored in the file referenced below, regardless
3+
# of whether S132 is actively used or not.
4+
include boards/$(BOARD)/mpconfigboard.mk

0 commit comments

Comments
 (0)
0