Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9fc0ec6

Browse files
authored
Merge pull request #934 from microbuilder/usbboot
[WIP] nRF52840 USB Bootloader
2 parents 720042f + 35d38db commit 9fc0ec6

20 files changed

+11123
-32
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*.bin
88
*.map
99
*.hex
10-
!ports/nrf/**/bootloader/*.hex
10+
!ports/nrf/**/bootloader/**/*.hex
1111
*.dis
1212
*.exe
1313

lib/nrfutil

ports/nrf/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,22 @@ FLASHER ?=
291291

292292
ifeq ($(FLASHER),)
293293

294+
# Adafruit use bootloader that requires writing to its settting ( app valid = 0x0001, crc = 0x0000 )
295+
ifneq (,$(filter $(BOARD),feather52 feather52840))
296+
297+
flash: $(BUILD)/$(OUTPUT_FILENAME).hex
298+
nrfjprog --program $< --sectorerase -f $(MCU_VARIANT)
299+
nrfjprog --erasepage $(BOOT_SETTING_ADDR) -f $(MCU_VARIANT)
300+
nrfjprog --memwr $(BOOT_SETTING_ADDR) --val 0x00000001 -f $(MCU_VARIANT)
301+
nrfjprog --reset -f $(MCU_VARIANT)
302+
303+
else
304+
294305
flash: $(BUILD)/$(OUTPUT_FILENAME).hex
295306
nrfjprog --program $< --sectorerase -f $(MCU_VARIANT)
296307
nrfjprog --reset -f $(MCU_VARIANT)
308+
309+
endif
297310

298311
sd: $(BUILD)/$(OUTPUT_FILENAME).hex
299312
nrfjprog --eraseall -f $(MCU_VARIANT)

ports/nrf/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ This is a port of CircuitPython to the Nordic Semiconductor nRF52 series of chip
2828
* nRF52840
2929
* [PCA10056](http://www.nordicsemi.com/eng/Products/nRF52840-Preview-DK)
3030

31+
## Board Specific Instructions
32+
33+
For board-specific instructions on building and flashing CircuitPython, see
34+
the following links:
35+
36+
> **NOTE**: These board specific readmes may be more up to date than the
37+
generic board-neutral documentation further down.
38+
39+
* Adafruit [Feather nRF52](boards/feather52/README.md): 512KB Flash, 64KB SRAM
40+
* Adafruit [Feather nRF52840](boards/feather52840/README.md): 1MB Flash, 256KB SRAM
41+
* Nordic PCA10056 see [Feather nRF52840](boards/feather52840/README.md)
42+
43+
For all other board targets, see the generic notes below.
44+
3145
## Compile and Flash
3246

3347
Prerequisite steps for building the nrf port:

ports/nrf/boards/feather52/mpconfigboard.mk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ SOFTDEV_VERSION ?= 2.0.1
66
LD_FILE = boards/feather52/custom_nrf52832_dfu_app_$(SOFTDEV_VERSION).ld
77
BOOTLOADER_PKG = boards/feather52/bootloader/feather52_bootloader_$(SOFTDEV_VERSION)_s132_single.zip
88

9+
BOOT_SETTING_ADDR = 0x7F000
910
NRF_DEFINES += -DNRF52832_XXAA
1011

1112
ifeq ($(OS),Windows_NT)
@@ -31,12 +32,12 @@ __check_defined = \
3132
.PHONY: dfu-gen dfu-flash boot-flash
3233

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

3637
dfu-flash:
3738
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0)
38-
$(NRFUTIL) dfu serial --package $(BUILD)/dfu-package.zip -p $(SERIAL) -b 115200
39+
$(NRFUTIL) dfu serial --package $(BUILD)/dfu-package.zip -p $(SERIAL) -b 115200 --singlebank
3940

40-
boot-flash:
41+
dfu-bootloader:
4142
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0)
4243
$(NRFUTIL) dfu serial --package $(BOOTLOADER_PKG) -p $(SERIAL) -b 115200

ports/nrf/boards/feather52840/README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ nrfjprog version: 9.7.2
7474
JLinkARM.dll version: 6.20f
7575
```
7676

77-
### Flash the Bootloader with `nrfjprog`
77+
### Option 1 (nRF52832 or nRF52840): Flash the HW UART Bootloader with `nrfjprog`
7878

7979
> This operation only needs to be done once, and only on boards that don't
8080
already have the serial bootloader installed.
@@ -105,6 +105,37 @@ Run.
105105
From this point onward, you can now use a simple serial port for firmware
106106
updates.
107107

108+
### Option 2 (nRF52840): Flash the USB CDC Bootloader with 'nrfjprog'
109+
110+
> This operation only needs to be done once, and only on boards that don't
111+
already have the serial bootloader installed.
112+
113+
Once `nrfjprog` is installed and available in `PATH` you can flash your
114+
board with the serial bootloader via the following command:
115+
116+
```
117+
make SD=s140 BOARD=feather52840 boot-usb-flash
118+
```
119+
120+
This should give you the following (or very similar) output, and you will see
121+
a DFU blinky pattern on one of the board LEDs:
122+
123+
```
124+
$ make SD=s140 BOARD=feather52840 boot-usb-flash
125+
Use make V=1, make V=2 or set BUILD_VERBOSE similarly in your environment to increase build verbosity.
126+
nrfjprog --program boards/feather52840/bootloader/usb/feather52840_bootloader_6.0.0_s140_single.hex -f nrf52 --chiperase --reset
127+
Parsing hex file.
128+
Erasing user available code and UICR flash areas.
129+
Applying system reset.
130+
Checking that the area to write is not protected.
131+
Programing device.
132+
Applying system reset.
133+
Run.
134+
```
135+
136+
From this point onward, you can now use a simple serial port for firmware
137+
updates.
138+
108139
### IMPORTANT: Disable Mass Storage on PCA10056 J-Link
109140

110141
The J-Link firmware on the PCA10056 implement USB Mass Storage, but this
@@ -174,11 +205,11 @@ BUTTON1 still pressed as you come out of reset).
174205
This will give you a **fast blinky DFU pattern** to indicate you are in DFU
175206
mode.
176207

177-
At this point, you can build and flash a CircuitPython binary via the following
208+
At this point, you can **build and flash** a CircuitPython binary via the following
178209
command:
179210

180211
```
181-
$ make V=1 SD=s140 SERIAL=/dev/tty.usbmodem1411 BOARD=feather52840 dfu-gen dfu-flash
212+
$ make V=1 SD=s140 SERIAL=/dev/tty.usbmodem1411 BOARD=feather52840 all dfu-gen dfu-flash
182213
```
183214

184215
This should give you the following results:

ports/nrf/boards/feather52840/bluefruit_nrf52840_s140_6.0.0.ld

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
0x000FE000..0x000FEFFF ( 4KB) Master Boot Record Params
1010
0x000F4000..0x000FDFFF ( 40KB) Serial + OTA Bootloader
1111
12-
0x000F3000..0x000F3FFF ( 4KB ) Private Config Data (Bonding, Keys, etc.)
13-
0x000F2000..0x000F2FFF ( 4KB ) User NVM data
14-
0x000B2000..0x000F1FFF (256KB) User Filesystem
12+
0x000ED000..0x000F3FFF (28KB ) Private Config Data (Bonding, Keys, etc.)
13+
0x000AD000..0x000ECFFF (256KB) User Filesystem
1514
16-
0x00025000..0x000B1FFF (564KB) Application Code (including ISR vector)
17-
0x00001000..0x00024FFF (144KB) SoftDevice
15+
0x00026000..0x000ACFFF (540KB) Application Code (including ISR vector)
16+
0x00001000..0x00025FFF (148KB) SoftDevice
1817
0x00000000..0x00000FFF (4KB) Master Boot Record
1918
*/
2019

@@ -23,9 +22,9 @@ MEMORY
2322
{
2423
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x100000
2524

26-
FLASH_ISR (rx) : ORIGIN = 0x00025000, LENGTH = 0x001000
27-
FLASH_TEXT (rx) : ORIGIN = 0x00026000, LENGTH = 0x08C000
28-
FLASH_FATFS (r) : ORIGIN = 0x000B2000, LENGTH = 0x040000
25+
FLASH_ISR (rx) : ORIGIN = 0x00026000, LENGTH = 0x001000
26+
FLASH_TEXT (rx) : ORIGIN = 0x00027000, LENGTH = 0x086000
27+
FLASH_FATFS (r) : ORIGIN = 0x000AD000, LENGTH = 0x040000
2928

3029
/* 0x2000000 - RAM:ORIGIN is reserved for Softdevice */
3130
RAM (xrw) : ORIGIN = 0x20004000, LENGTH = 0x20040000 - 0x20004000
@@ -42,6 +41,6 @@ _estack = ORIGIN(RAM) + LENGTH(RAM);
4241

4342
/* RAM extents for the garbage collector */
4443
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
45-
_heap_end = 0x20007000; /* tunable */
44+
_heap_end = 0x20020000; /* tunable */
4645

4746
INCLUDE "boards/common.ld"
-162 KB
Binary file not shown.
File renamed without changes.

0 commit comments

Comments
 (0)