11# Setup
22
3- Before you can build, you will need to run the following commands once:
3+ ## Installing CircuitPython submodules
4+
5+ Before you can build, you will need to run the following commands once, which
6+ will install the submodules that are part of the CircuitPython ecosystem, and
7+ build the ` mpy-cross ` tool:
48
59```
610$ cd circuitpython
711$ git submodule update --init
812$ make -C mpy-cross
913```
1014
11- You then need to download the SD and Nordic SDK files:
15+ You then need to download the SD and Nordic SDK files via :
1216
1317> This script relies on ` wget ` , which must be available from the command line.
1418
@@ -17,47 +21,50 @@ $ cd ports/nrf
1721$ ./drivers/bluetooth/download_ble_stack.sh
1822```
1923
24+ ## Installing ` nrfutil `
25+
26+ The Adafruit Bluefruit nRF52 Feather ships with a serial and OTA BLE bootloader
27+ that can be used to flash firmware images over a simple serial connection,
28+ using the on-board USB serial converter.
29+
30+ If you haven't installed this command-line tool yet, go to the ` /libs/nrfutil `
31+ folder (where nrfutil 0.5.2 is installed as a sub-module) and run the following
32+ commands:
33+
34+ > If you get a 'sudo: pip: command not found' error running 'sudo pip install',
35+ you can install pip via 'sudo easy_install pip'
36+
37+ ```
38+ $ cd libs/nrfutil
39+ $ sudo pip install -r requirements.txt
40+ $ sudo python setup.py install
41+ ```
42+
2043# Building and flashing firmware images
2144
22- ## Building CircuitPython
45+ ## Building CircuitPython binaries
2346
2447#### REPL over UART (default settings)
2548
2649To build a CircuitPython binary with default settings for the
2750` feather52 ` target enter:
2851
52+ > ** NOTE:** ` BOARD=feather52 ` is the default option and isn't stricly required.
53+
2954```
3055$ make BOARD=feather52 V=1
3156```
3257
33- #### REPL over BLE UART (AKA ` NUS ` )
58+ #### REPL over BLE support
3459
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:
60+ To build a CircuitPython binary with BLE support (S132) include ` SD=s132 `
61+ as part of the build process:
4762
4863```
4964$ make BOARD=feather52 V=1 SD=s132
5065```
5166
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.
67+ ## Flashing binaries with ` nrfutil `
6168
6269### 1. ** Update bootloader** to single-bank version
6370
@@ -88,7 +95,7 @@ To enable BLE5 support and the latest S132 release, flash the v5.0.0 bootloader
8895$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART SOFTDEV_VERSION=5.0.0 boot-flash
8996```
9097
91- ### 2. Generate a CircuitPython DFU .zip package and flash it over serial
98+ ### 2. Generate and flash a CircuitPython DFU .zip package over serial
9299
93100The following command will package and flash the CircuitPython binary using the
94101appropriate bootloader mentionned above.
@@ -102,9 +109,49 @@ image, as described earlier in this readme.
102109$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART dfu-gen dfu-flash
103110```
104111
105- If you built your CircuitPython binary with ** BLE UART ** support you will
106- need to add the ` SD=s132 ` flag as shown below:
112+ If you built your CircuitPython binary with ** BLE** support you will need to
113+ add the ` SD=s132 ` flag as shown below:
107114
108115```
109116$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART SD=s132 dfu-gen dfu-flash
110117```
118+
119+ ## Working with CircuitPython
120+
121+ ### Running local files with ` ampy `
122+
123+ [ ampy] ( https://learn.adafruit.com/micropython-basics-load-files-and-run-code/install-ampy )
124+ is a command-line tool that can be used with the nRF52 Feather to transfer
125+ local python files to the nRF52 for execution, rather than having to enter
126+ the REPL manually, enter paste mode, and paste the code yourself.
127+
128+ > ** IMPORTANT** : You must have ` ampy ` version ** 1.0.3** or higher to use ` ampy `
129+ with the nRF52. The bootloader on the nRF52 requires a delay between the
130+ HW reset, and the moment when the command sequance is sent to enter raw
131+ mode. This required ` -d/--delay ` flag was added in release 1.0.3.
132+
133+
134+ Save the following file as ` test.py ` :
135+
136+ ```
137+ import board
138+ import digitalio
139+ import time
140+
141+ led = digitalio.DigitalInOut(board.LED2)
142+ led.direction = digitalio.Direction.OUTPUT
143+
144+ while True:
145+ led.value = True
146+ time.sleep(0.5)
147+ led.value = False
148+ time.sleep(0.5)
149+ ```
150+
151+ Then run the saved file via ampy, updating the serial port as required:
152+
153+ ```
154+ $ ampy -p /dev/tty.SLAB_USBtoUART -d 1.5 run test.py
155+ ```
156+
157+ This should give you blinky at 1 Hz on LED2 (the blue LED on the nRF52 Feather).
0 commit comments