Skip to content

Commit fc19e03

Browse files
committed
WIP: bonding
1 parent f4922a5 commit fc19e03

8 files changed

Lines changed: 63 additions & 130 deletions

File tree

ports/nrf/README.md

Lines changed: 6 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2,85 +2,26 @@
22

33
This is a port of CircuitPython to the Nordic Semiconductor nRF52 series of chips.
44

5-
## Supported Features
6-
7-
* UART
8-
* SPI
9-
* LEDs
10-
* Pins
11-
* ADC
12-
* I2C
13-
* PWM
14-
* Temperature
15-
* RTC (Real Time Counter. Low-Power counter)
16-
* BLE support including:
17-
* Peripheral role
18-
* Scanner role
19-
* _REPL over Bluetooth LE_ (optionally using WebBluetooth)
20-
* ubluepy: Bluetooth LE module for CircuitPython
21-
* 1 non-connectable advertiser while in connection
22-
23-
## Tested Hardware
24-
25-
* nRF52840
26-
* [PCA10056](http://www.nordicsemi.com/eng/Products/nRF52840-Preview-DK)
27-
28-
## Board Specific Instructions
29-
30-
For board-specific instructions on building and flashing CircuitPython, see
31-
the following links:
32-
33-
> **NOTE**: These board specific readmes may be more up to date than the
34-
generic board-neutral documentation further down.
35-
36-
* Adafruit Feather nRF52840: `boards/feather_nrf52840_express/README.md`: 1MB Flash, 256KB SRAM
37-
* Nordic PCA10056 (uses nRF52840): `boards/pca10056/README.md`
38-
* MakerDiary nRF52840 MDK: `boards/makerdiary_nrf52840_mdk/README.md`
39-
* MakerDiary nRF52840 MDK USB Dongle: `boards/makerdiary_nrf52840_mdk_usb_dongle/README.md`
40-
41-
For all other board targets, see the generic notes below.
5+
> **NOTE**: There are board-specific READMEs that may be more up to date than the
6+
generic board-neutral documentation below.
427

438
## Compile and Flash
449

4510
Prerequisite steps for building the nrf port:
4611

4712
git clone <URL>.git circuitpython
4813
cd circuitpython
49-
git submodule update --init
14+
git submodule update --init --recursive
5015
make -C mpy-cross
5116

17+
Some boards have UF2 bootloaders and can simply be flashed in the normal way, by copying
18+
firmware.uf2 to the BOOT drive.
19+
5220
To build and flash issue the following command inside the ports/nrf/ folder:
5321

5422
make BOARD=pca10056
5523
make BOARD=pca10056 flash
5624

57-
## Compile and Flash with Bluetooth Stack
58-
59-
First prepare the bluetooth folder by downloading Bluetooth LE stacks and headers:
60-
61-
./bluetooth/download_ble_stack.sh
62-
63-
If the Bluetooth stacks has been downloaded, compile the target with the following command:
64-
65-
make BOARD=pca10040 SD=s132
66-
67-
The **make sd** will trigger a flash of the bluetooth stack before that application is flashed. Note that **make sd** will perform a full erase of the chip, which could cause 3rd party bootloaders to also be wiped.
68-
69-
make BOARD=pca10040 SD=s132 sd
70-
71-
Note: further tuning of features to include in bluetooth or even setting up the device to use REPL over Bluetooth can be configured in the `bluetooth_conf.h`.
72-
73-
## Target Boards and Make Flags
74-
75-
Target Board (BOARD) | Bluetooth Stack (SD) | Bluetooth Support | Flash Util
76-
-------------------------|-------------------------|------------------------|-------------------------------
77-
pca10056 | s140 | Peripheral and Scanner | [Segger](#segger-targets)
78-
feather_nrf52840_express | s140 | Peripheral and Scanner | UF2 bootloader
79-
makerdiary_nrf52840_mdk | s140 | Peripheral and Scanner | pyocd or ARM mbed DAPLink
80-
makerdiary_nrf52840_mdk_usb_dongle | s140 | Peripheral and Scanner | DFU bootloader & nrfutil
81-
electronut_labs_papyr | s140 | Peripheral and Scanner | UF2 bootloader
82-
electronut_labs_blip | s140 | Peripheral and Scanner | Black Magic Probe
83-
8425
## Segger Targets
8526

8627
Install the necessary tools to flash and debug using Segger:
@@ -107,22 +48,7 @@ run follow command to install [adafruit-nrfutil](https://github.com/adafruit/Ada
10748
* dfu-gen: Generates a Firmware zip to be used by the DFU flash application.
10849
* dfu-flash: Triggers the DFU flash application to upload the firmware from the generated Firmware zip file.
10950

110-
Example on how to generate and flash feather_nrf52840 target:
111-
112-
make BOARD=feather_nrf52840 SD=s140
113-
make BOARD=feather_nrf52840 SD=s140 dfu-gen dfu-flash
114-
115-
## Bluetooth LE REPL
116-
117-
The port also implements a BLE REPL driver. This feature is disabled by default, as it will deactivate the UART REPL when activated. As some of the nRF devices only have one UART, using the BLE REPL free's the UART instance such that it can be used as a general UART peripheral not bound to REPL.
118-
119-
The configuration can be enabled by editing the `bluetooth_conf.h` and set `MICROPY_PY_BLE_NUS` to 1.
12051

12152
When enabled you have different options to test it:
12253
* [NUS Console for Linux](https://github.com/tralamazza/nus_console) (recommended)
12354
* [WebBluetooth REPL](https://glennrub.github.io/webbluetooth/micropython/repl/) (experimental)
124-
125-
Other:
126-
* nRF UART application for IPhone/Android
127-
128-
WebBluetooth mode can also be configured by editing `bluetooth_conf.h` and set `BLUETOOTH_WEBBLUETOOTH_REPL` to 1. This will alternate advertisement between Eddystone URL and regular connectable advertisement. The Eddystone URL will point the phone or PC to download [WebBluetooth REPL](https://glennrub.github.io/webbluetooth/micropython/repl/) (experimental), which subsequently can be used to connect to the Bluetooth REPL from the PC or Phone browser.

ports/nrf/bluetooth/ble_uart.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include "shared-bindings/_bleio/Service.h"
4141
#include "shared-bindings/_bleio/UUID.h"
4242

43-
#if (MICROPY_PY_BLE_NUS == 1)
43+
#if CIRCUITPY_SERIAL_BLE
4444

4545
static const char default_name[] = "CP-REPL"; // max 8 chars or uuid won't fit in adv data
4646
static const char NUS_UUID[] = "6e400001-b5a3-f393-e0a9-e50e24dcca9e";
@@ -190,4 +190,4 @@ void mp_hal_stdout_tx_strn(const char *str, size_t len) {
190190
}
191191
}
192192

193-
#endif // MICROPY_PY_BLE_NUS
193+
#endif // CIRCUITPY_SERIAL_BLE

ports/nrf/boards/adafruit_nrf52840_s140_v6.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ MEMORY
2424
FLASH_ISR (rx) : ORIGIN = 0x00026000, LENGTH = 0x001000
2525
FLASH_TEXT (rx) : ORIGIN = 0x00027000, LENGTH = 0x086000
2626
FLASH_FATFS (r) : ORIGIN = 0x000AD000, LENGTH = 0x040000
27+
FLASH_CONFIG (r): ORIGIN = 0x000ED000, LENGTH = 0x007000
2728

2829
/* 0x2000000 - RAM:ORIGIN is reserved for Softdevice */
2930
RAM (xrw) : ORIGIN = 0x20004000, LENGTH = 0x20040000 - 0x20004000

ports/nrf/boards/common.ld

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
__fatfs_flash_start_addr = ORIGIN(FLASH_FATFS);
33
__fatfs_flash_length = LENGTH(FLASH_FATFS);
44

5+
/* Flash region for configuration information (bonding info, keys, etc.) */
6+
__config_flash_start_addr = ORIGIN(FLASH_CONFIG);
7+
__config_flash_length = LENGTH(FLASH_CONFIG);
8+
59
/* define output sections */
610
SECTIONS
711
{
@@ -13,7 +17,7 @@ SECTIONS
1317

1418
. = ALIGN(4);
1519
} >FLASH_ISR
16-
20+
1721
/* The program code and other data goes into FLASH */
1822
.text :
1923
{
@@ -28,7 +32,7 @@ SECTIONS
2832
. = ALIGN(4);
2933
_etext = .; /* define a global symbol at end of code */
3034
} >FLASH_TEXT
31-
35+
3236
/*
3337
.ARM.extab :
3438
{
@@ -42,10 +46,10 @@ SECTIONS
4246
__exidx_end = .;
4347
} >FLASH
4448
*/
45-
49+
4650
/* used by the startup to initialize data */
4751
_sidata = .;
48-
52+
4953
/* This is the initialized data section
5054
The program executes knowing that the data is in the RAM
5155
but the loader puts the initial values in the FLASH (inidata).
@@ -60,8 +64,8 @@ SECTIONS
6064

6165
. = ALIGN(4);
6266
_edata = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */
63-
} >RAM
64-
67+
} >RAM
68+
6569
/* Uninitialized data section */
6670
.bss :
6771
{
@@ -105,4 +109,3 @@ SECTIONS
105109

106110
.ARM.attributes 0 : { *(.ARM.attributes) }
107111
}
108-

ports/nrf/mpconfigport.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@
3838
#define MICROPY_PY_UBINASCII (1)
3939
#define MICROPY_PY_UJSON (1)
4040

41-
// TODO this is old BLE stuff
42-
#if BLUETOOTH_SD
43-
#define MICROPY_PY_BLEIO (1)
44-
#define MICROPY_PY_BLE_NUS (0)
45-
#else
46-
#ifndef MICROPY_PY_BLEIO
47-
#define MICROPY_PY_BLEIO (0)
48-
#endif
49-
#endif
50-
5141
// 24kiB stack
5242
#define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000
5343

ports/nrf/supervisor/serial.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828

2929
#include "supervisor/serial.h"
3030

31-
#if (MICROPY_PY_BLE_NUS == 1)
31+
#if CIRCUITPY_SERIAL_BLE
3232
#include "ble_uart.h"
33-
#else
33+
#elif CIRCUITPY_SERIAL_UART
3434
#include <string.h>
3535
#include "nrf_gpio.h"
3636
#include "nrfx_uarte.h"
3737
#endif
3838

39-
#if (MICROPY_PY_BLE_NUS == 1)
39+
#if CIRCUITPY_SERIAL_BLE
4040

4141
void serial_init(void) {
4242
ble_uart_init();
@@ -58,7 +58,7 @@ void serial_write(const char *text) {
5858
ble_uart_stdout_tx_str(text);
5959
}
6060

61-
#elif !defined(NRF52840_XXAA)
61+
#elif CIRCUITPY_SERIAL_UART
6262

6363
uint8_t serial_received_char;
6464
nrfx_uarte_t serial_instance = NRFX_UARTE_INSTANCE(0);
@@ -124,4 +124,4 @@ void serial_write_substring(const char *text, uint32_t len) {
124124
}
125125
}
126126

127-
#endif
127+
#endif // CIRCUITPY_SERIAL_UART

py/circuitpy_mpconfig.mk

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2424
# THE SOFTWARE.
2525

26-
2726
# mpconfigboard.mk files can specify:
2827
# CIRCUITPY_FULL_BUILD = 1 (which is the default)
2928
# or
@@ -284,8 +283,21 @@ CIRCUITPY_USTACK = 0
284283
endif
285284
CFLAGS += -DCIRCUITPY_USTACK=$(CIRCUITPY_USTACK)
286285

286+
# Non-module conditionals
287287

288288
ifndef CIRCUITPY_BITBANG_APA102
289289
CIRCUITPY_BITBANG_APA102 = 0
290290
endif
291291
CFLAGS += -DCIRCUITPY_BITBANG_APA102=$(CIRCUITPY_BITBANG_APA102)
292+
293+
# REPL over BLE
294+
ifndef CIRCUITPY_SERIAL_BLE
295+
CIRCUITPY_SERIAL_BLE = 0
296+
endif
297+
CFLAGS += -DCIRCUITPY_SERIAL_BLE=$(CIRCUITPY_SERIAL_BLE)
298+
299+
# REPL over UART
300+
ifndef CIRCUITPY_SERIAL_UART
301+
CIRCUITPY_SERIAL_UART = 0
302+
endif
303+
CFLAGS += -DCIRCUITPY_SERIAL_UART=$(CIRCUITPY_SERIAL_UART)

supervisor/supervisor.mk

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ifdef EXTERNAL_FLASH_DEVICES
4646
else
4747
ifeq ($(DISABLE_FILESYSTEM),1)
4848
SRC_SUPERVISOR += supervisor/stub/internal_flash.c
49-
else
49+
else
5050
SRC_SUPERVISOR += supervisor/internal_flash.c
5151
endif
5252
endif
@@ -58,30 +58,31 @@ ifeq ($(USB),FALSE)
5858
SRC_SUPERVISOR += supervisor/serial.c
5959
endif
6060
else
61-
SRC_SUPERVISOR += lib/tinyusb/src/common/tusb_fifo.c \
62-
lib/tinyusb/src/device/usbd.c \
63-
lib/tinyusb/src/device/usbd_control.c \
64-
lib/tinyusb/src/class/msc/msc_device.c \
65-
lib/tinyusb/src/class/cdc/cdc_device.c \
66-
lib/tinyusb/src/class/hid/hid_device.c \
67-
lib/tinyusb/src/class/midi/midi_device.c \
68-
lib/tinyusb/src/tusb.c \
69-
supervisor/shared/serial.c \
70-
supervisor/usb.c \
71-
supervisor/shared/usb/usb_desc.c \
72-
supervisor/shared/usb/usb.c \
73-
supervisor/shared/usb/usb_msc_flash.c \
74-
shared-bindings/usb_hid/__init__.c \
75-
shared-bindings/usb_hid/Device.c \
76-
shared-bindings/usb_midi/__init__.c \
77-
shared-bindings/usb_midi/PortIn.c \
78-
shared-bindings/usb_midi/PortOut.c \
79-
shared-module/usb_hid/__init__.c \
80-
shared-module/usb_hid/Device.c \
81-
shared-module/usb_midi/__init__.c \
82-
shared-module/usb_midi/PortIn.c \
83-
shared-module/usb_midi/PortOut.c \
84-
$(BUILD)/autogen_usb_descriptor.c
61+
SRC_SUPERVISOR += \
62+
lib/tinyusb/src/common/tusb_fifo.c \
63+
lib/tinyusb/src/device/usbd.c \
64+
lib/tinyusb/src/device/usbd_control.c \
65+
lib/tinyusb/src/class/msc/msc_device.c \
66+
lib/tinyusb/src/class/cdc/cdc_device.c \
67+
lib/tinyusb/src/class/hid/hid_device.c \
68+
lib/tinyusb/src/class/midi/midi_device.c \
69+
lib/tinyusb/src/tusb.c \
70+
supervisor/shared/serial.c \
71+
supervisor/usb.c \
72+
supervisor/shared/usb/usb_desc.c \
73+
supervisor/shared/usb/usb.c \
74+
supervisor/shared/usb/usb_msc_flash.c \
75+
shared-bindings/usb_hid/__init__.c \
76+
shared-bindings/usb_hid/Device.c \
77+
shared-bindings/usb_midi/__init__.c \
78+
shared-bindings/usb_midi/PortIn.c \
79+
shared-bindings/usb_midi/PortOut.c \
80+
shared-module/usb_hid/__init__.c \
81+
shared-module/usb_hid/Device.c \
82+
shared-module/usb_midi/__init__.c \
83+
shared-module/usb_midi/PortIn.c \
84+
shared-module/usb_midi/PortOut.c \
85+
$(BUILD)/autogen_usb_descriptor.c
8586

8687
CFLAGS += -DUSB_AVAILABLE
8788
endif

0 commit comments

Comments
 (0)