Skip to content

Commit fb5f653

Browse files
authored
Merge pull request adafruit#623 from microbuilder/nrf52840
nRF52: [WIP] Feather52840 BSP and nRF52840 Serial Bootloader and
2 parents 446a313 + fce0b08 commit fb5f653

12 files changed

Lines changed: 10973 additions & 5 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*.bin
88
*.map
99
*.hex
10+
!ports/nrf/**/bootloader/*.hex
1011
*.dis
1112
*.exe
1213

ports/nrf/boards/feather52/board.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@
3535
#define BOOTLOADER_VERSION_REGISTER NRF_TIMER2->CC[0]
3636
uint32_t bootloaderVersion = 0;
3737

38-
void board_init(void)
39-
{
40-
// Retrieve bootloader version
41-
bootloaderVersion = BOOTLOADER_VERSION_REGISTER;
38+
void board_init(void) {
39+
// Retrieve bootloader version
40+
bootloaderVersion = BOOTLOADER_VERSION_REGISTER;
4241
}
4342

4443
// Check the status of the two buttons on CircuitPlayground Express. If both are
@@ -57,7 +56,7 @@ bool board_requests_safe_mode(void) {
5756
// reset_pin(PIN_PA28);
5857
// return safe_mode;
5958

60-
return false;
59+
return false;
6160
}
6261

6362
void reset_board(void) {
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
# Setup
2+
3+
The `feather52840` board is currently based on the `PCA10056` development
4+
board from Nordic Semiconductors, since commercial modules are not yet
5+
available for the nRF52840.
6+
7+
The difference between the `pca10056` and `feather52840` board support
8+
packages is that no bootloader is present on the `pca10056` (a HW debugger
9+
like a Segger J-Link is required to flash firmware images), whereas the
10+
`feather52840` package uses a serial bootloader, with a slightly different
11+
flash layout to account for the bootloader's presence.
12+
13+
Both targets run on the same hardware and assume the same pinouts.
14+
15+
The `feather52840` board support package will be updated at a later date
16+
to reflect any pin changes in the final Feather form-factor HW.
17+
18+
## Installing CircuitPython submodules
19+
20+
Before you can build, you will need to run the following commands once, which
21+
will install the submodules that are part of the CircuitPython ecosystem, and
22+
build the `mpy-cross` tool:
23+
24+
```
25+
$ cd circuitpython
26+
$ git submodule update --init
27+
$ make -C mpy-cross
28+
```
29+
30+
You then need to download the SD and Nordic SDK files via:
31+
32+
> This script relies on `wget`, which must be available from the command line.
33+
34+
```
35+
$ cd ports/nrf
36+
$ ./drivers/bluetooth/download_ble_stack.sh
37+
```
38+
39+
## Installing the Serial Bootloader
40+
41+
The Adafruit nRF52840 Feather uses a serial bootloader that allows you to
42+
update the core CircuitPython firmware and internal file system contents
43+
using only a serial connection.
44+
45+
On empty devices, the serial bootloader will need to be flashed once using a
46+
HW debugger such as a Segger J-Link before the serial updater (`nrfutil`) can
47+
be used.
48+
49+
### Install `nrfjprog`
50+
51+
Before you can install the bootloader, you will first need to install the
52+
`nrfjprog` tool from Nordic Semiconductors for your operating system. The
53+
binary files can be downloaded via the following links:
54+
55+
- [nRF5x toolset tar for Linux 32-bit v9.7.2](http://www.nordicsemi.com/eng/nordic/Products/nRF52832/nRF5x-Command-Line-Tools-Linux32/52619)
56+
- [nRF5x toolset tar for Linux 64-bit v9.7.2](http://www.nordicsemi.com/eng/nordic/Products/nRF52832/nRF5x-Command-Line-Tools-Linux64/51388)
57+
- [nRF5x toolset tar for OSX v9.7.2](http://www.nordicsemi.com/eng/nordic/Products/nRF52832/nRF5x-Command-Line-Tools-OSX/53406)
58+
- [nRF5x toolset installer for Windows v9.7.2](http://www.nordicsemi.com/eng/nordic/Products/nRF52832/nRF5x-Command-Line-Tools-Win32/48768)
59+
60+
You will then need to add the `nrfjprog` folder to your system `PATH` variable
61+
so that it is available from the command line. The exact process for this is
62+
OS specific, but on a POSIX type system like OS X or Linux, you can
63+
temporarily add the location to your `PATH` environment variables as follows:
64+
65+
```
66+
$ export PATH=$PATH:YOURPATHHERE/nRF5x-Command-Line-Tools_9_7_2_OSX/nrfjprog/
67+
```
68+
69+
You can test this by running the following command:
70+
71+
```
72+
$ nrfjprog --version
73+
nrfjprog version: 9.7.2
74+
JLinkARM.dll version: 6.20f
75+
```
76+
77+
### Flash the Bootloader with `nrfjprog`
78+
79+
> This operation only needs to be done once, and only on boards that don't
80+
already have the serial bootloader installed.
81+
82+
Once `nrfjprog` is installed and available in `PATH` you can flash your
83+
board with the serial bootloader via the following command:
84+
85+
```
86+
make SD=s140 BOARD=feather52840 boot-flash
87+
```
88+
89+
This should give you the following (or very similar) output, and you will see
90+
a DFU blinky pattern on one of the board LEDs:
91+
92+
```
93+
$ make SD=s140 BOARD=feather52840 boot-flash
94+
Use make V=1, make V=2 or set BUILD_VERBOSE similarly in your environment to increase build verbosity.
95+
nrfjprog --program boards/feather52840/bootloader/feather52840_bootloader_6.0.0_s140_single.hex -f nrf52 --chiperase --reset
96+
Parsing hex file.
97+
Erasing user available code and UICR flash areas.
98+
Applying system reset.
99+
Checking that the area to write is not protected.
100+
Programing device.
101+
Applying system reset.
102+
Run.
103+
```
104+
105+
From this point onward, you can now use a simple serial port for firmware
106+
updates.
107+
108+
### IMPORTANT: Disable Mass Storage on PCA10056 J-Link
109+
110+
The J-Link firmware on the PCA10056 implement USB Mass Storage, but this
111+
causes a known conflict with reliable USB CDC serial port communication. In
112+
order to use the serial bootloader, **you must disable MSD support on the
113+
Segger J-Link**!
114+
115+
To disable mass storage support, run the `JLinkExe` (or equivalent) command,
116+
and send `MSDDisable`. (You can re-enable MSD support via `MSDEnable`):
117+
118+
```
119+
$ JLinkExe
120+
SEGGER J-Link Commander V6.20f (Compiled Oct 13 2017 17:20:01)
121+
DLL version V6.20f, compiled Oct 13 2017 17:19:52
122+
123+
Connecting to J-Link via USB...O.K.
124+
Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Jul 24 2017 17:30:12
125+
Hardware version: V1.00
126+
S/N: 683947110
127+
VTref = 3.300V
128+
129+
130+
Type "connect" to establish a target connection, '?' for help
131+
J-Link>MSDDisable
132+
Probe configured successfully.
133+
J-Link>exit
134+
```
135+
136+
## Building and Flashing CircuitPython
137+
138+
### Installing `nrfutil`
139+
140+
If you haven't installed the required command-line tool yet, go to the
141+
`/libs/nrfutil` folder (where nrfutil 0.5.2b is installed as a sub-module)
142+
and run the following commands:
143+
144+
> If you get a 'sudo: pip: command not found' error running 'sudo pip install',
145+
you can install pip via 'sudo easy_install pip'
146+
147+
```
148+
$ cd ../../lib/nrfutil
149+
$ sudo pip install -r requirements.txt
150+
$ sudo python setup.py install
151+
```
152+
153+
#### Changes to `nrfutil` in 0.5.2b
154+
155+
**IMPORTANT**: Make sure that you have version **0.5.2b**, since a small
156+
change was required to `dfu_transport_serial.py` to account for the
157+
increased minimum flash erase time on the nRF52840 compared to the earlier
158+
nRF52832!
159+
160+
You can also manually change the file with the following new values (lines
161+
67-68), and reinstall the utility via `sudo python setup.py install`:
162+
163+
```
164+
FLASH_PAGE_ERASE_MAX_TIME = 0.1 # Worst time to erase a page 100 ms
165+
FLASH_PAGE_ERASE_MIN_TIME = 0.09 # Best time to erase a page 90 ms
166+
```
167+
168+
### Flashing CircuitPython
169+
170+
With the serial bootloader present on your board, you first need to force your
171+
board into DFU mode by holding down BUTTON1 and RESETTING the board (with
172+
BUTTON1 still pressed as you come out of reset).
173+
174+
This will give you a **fast blinky DFU pattern** to indicate you are in DFU
175+
mode.
176+
177+
At this point, you can build and flash a CircuitPython binary via the following
178+
command:
179+
180+
```
181+
$ make V=1 SD=s140 SERIAL=/dev/tty.usbmodem1411 BOARD=feather52840 dfu-gen dfu-flash
182+
```
183+
184+
This should give you the following results:
185+
186+
```
187+
$ make V=1 SD=s140 SERIAL=/dev/tty.usbmodem1411 BOARD=feather52840 dfu-gen dfu-flash
188+
nrfutil dfu genpkg --sd-req 0xFFFE --dev-type 0x0052 --application build-feather52840-s140/firmware.hex build-feather52840-s140/dfu-package.zip
189+
Zip created at build-feather52840-s140/dfu-package.zip
190+
nrfutil --verbose dfu serial --package build-feather52840-s140/dfu-package.zip -p /dev/tty.usbmodem1411 -b 115200
191+
Upgrading target on /dev/tty.usbmodem1411 with DFU package /Users/kevintownsend/Dropbox/microBuilder/Code/CircuitPython/circuitpython-mb/ports/nrf/build-feather52840-s140/dfu-package.zip. Flow control is disabled.
192+
Starting DFU upgrade of type 4, SoftDevice size: 0, bootloader size: 0, application size: 195252
193+
Sending DFU start packet
194+
Sending DFU init packet
195+
Sending firmware file
196+
################################################################################################################################################################################################################################################################################################################################################################################################
197+
Activating new firmware
198+
199+
DFU upgrade took 41.6610329151s
200+
Device programmed.
201+
```
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
GNU linker script for NRF52840 w/S140 6.0.0 SoftDevice
3+
4+
MEMORY MAP
5+
------------------------------------------------------------------------
6+
START ADDR END ADDR SIZE DESCRIPTION
7+
---------- ---------- ------- -----------------------------------------
8+
0x000FF000..0x000FFFFF ( 4KB) Bootloader Settings
9+
0x000FE000..0x000FEFFF ( 4KB) Master Boot Record Params
10+
0x000F4000..0x000FDFFF ( 40KB) Serial + OTA Bootloader
11+
12+
0x000F3000..0x000F3FFF ( 4KB ) Private Config Data (Bonding, Keys, etc.)
13+
0x000F2000..0x000F2FFF ( 4KB ) User NVM data
14+
0x000B2000..0x000F1FFF (256KB) User Filesystem
15+
16+
0x00025000..0x000B1FFF (564KB) Application Code (including ISR vector)
17+
0x00001000..0x00024FFF (144KB) SoftDevice
18+
0x00000000..0x00000FFF (4KB) Master Boot Record
19+
*/
20+
21+
/* Specify the memory areas (S140 6.0.0) */
22+
MEMORY
23+
{
24+
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x100000
25+
26+
FLASH_ISR (rx) : ORIGIN = 0x00025000, LENGTH = 0x001000
27+
FLASH_TEXT (rx) : ORIGIN = 0x00026000, LENGTH = 0x08C000
28+
FLASH_FATFS (r) : ORIGIN = 0x000B2000, LENGTH = 0x040000
29+
30+
/* 0x2000000 - RAM:ORIGIN is reserved for Softdevice */
31+
RAM (xrw) : ORIGIN = 0x20004000, LENGTH = 0x20040000 - 0x20004000
32+
}
33+
34+
/* produce a link error if there is not this amount of RAM for these sections */
35+
_minimum_stack_size = 2K;
36+
_minimum_heap_size = 0;
37+
38+
/* top end of the stack */
39+
40+
/*_stack_end = ORIGIN(RAM) + LENGTH(RAM);*/
41+
_estack = ORIGIN(RAM) + LENGTH(RAM);
42+
43+
/* RAM extents for the garbage collector */
44+
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
45+
_heap_end = 0x20007000; /* tunable */
46+
47+
INCLUDE "boards/common.ld"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include <string.h>
28+
#include <stdbool.h>
29+
30+
#include "nrf.h"
31+
32+
#include "boards/board.h"
33+
34+
void board_init(void) {
35+
36+
}
37+
38+
bool board_requests_safe_mode(void) {
39+
return false;
40+
}
41+
42+
void reset_board(void) {
43+
44+
}

0 commit comments

Comments
 (0)