summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2019-10-06 21:30:26 -0400
committerDan Halbert <halbert@halwitz.org>2019-10-06 21:30:26 -0400
commitfc19e03128aeeb94a22fdff097e4d0576d768986 (patch)
tree98343aa13844f82d5f9ffce99e875f2a26b66acb
parentf4922a530a06ed62523ae333eab90fee6145fc46 (diff)
WIP: bonding
-rw-r--r--ports/nrf/README.md86
-rw-r--r--ports/nrf/bluetooth/ble_uart.c4
-rw-r--r--ports/nrf/boards/adafruit_nrf52840_s140_v6.ld1
-rw-r--r--ports/nrf/boards/common.ld17
-rw-r--r--ports/nrf/mpconfigport.h10
-rw-r--r--ports/nrf/supervisor/serial.c10
-rw-r--r--py/circuitpy_mpconfig.mk14
-rw-r--r--supervisor/supervisor.mk51
8 files changed, 63 insertions, 130 deletions
diff --git a/ports/nrf/README.md b/ports/nrf/README.md
index 5f6d03720..64f5b8aff 100644
--- a/ports/nrf/README.md
+++ b/ports/nrf/README.md
@@ -2,43 +2,8 @@
This is a port of CircuitPython to the Nordic Semiconductor nRF52 series of chips.
-## Supported Features
-
-* UART
-* SPI
-* LEDs
-* Pins
-* ADC
-* I2C
-* PWM
-* Temperature
-* RTC (Real Time Counter. Low-Power counter)
-* BLE support including:
- * Peripheral role
- * Scanner role
- * _REPL over Bluetooth LE_ (optionally using WebBluetooth)
- * ubluepy: Bluetooth LE module for CircuitPython
- * 1 non-connectable advertiser while in connection
-
-## Tested Hardware
-
-* nRF52840
- * [PCA10056](http://www.nordicsemi.com/eng/Products/nRF52840-Preview-DK)
-
-## Board Specific Instructions
-
-For board-specific instructions on building and flashing CircuitPython, see
-the following links:
-
-> **NOTE**: These board specific readmes may be more up to date than the
- generic board-neutral documentation further down.
-
-* Adafruit Feather nRF52840: `boards/feather_nrf52840_express/README.md`: 1MB Flash, 256KB SRAM
-* Nordic PCA10056 (uses nRF52840): `boards/pca10056/README.md`
-* MakerDiary nRF52840 MDK: `boards/makerdiary_nrf52840_mdk/README.md`
-* MakerDiary nRF52840 MDK USB Dongle: `boards/makerdiary_nrf52840_mdk_usb_dongle/README.md`
-
-For all other board targets, see the generic notes below.
+> **NOTE**: There are board-specific READMEs that may be more up to date than the
+ generic board-neutral documentation below.
## Compile and Flash
@@ -46,41 +11,17 @@ Prerequisite steps for building the nrf port:
git clone <URL>.git circuitpython
cd circuitpython
- git submodule update --init
+ git submodule update --init --recursive
make -C mpy-cross
+Some boards have UF2 bootloaders and can simply be flashed in the normal way, by copying
+firmware.uf2 to the BOOT drive.
+
To build and flash issue the following command inside the ports/nrf/ folder:
make BOARD=pca10056
make BOARD=pca10056 flash
-## Compile and Flash with Bluetooth Stack
-
-First prepare the bluetooth folder by downloading Bluetooth LE stacks and headers:
-
- ./bluetooth/download_ble_stack.sh
-
-If the Bluetooth stacks has been downloaded, compile the target with the following command:
-
- make BOARD=pca10040 SD=s132
-
-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.
-
- make BOARD=pca10040 SD=s132 sd
-
-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`.
-
-## Target Boards and Make Flags
-
-Target Board (BOARD) | Bluetooth Stack (SD) | Bluetooth Support | Flash Util
--------------------------|-------------------------|------------------------|-------------------------------
-pca10056 | s140 | Peripheral and Scanner | [Segger](#segger-targets)
-feather_nrf52840_express | s140 | Peripheral and Scanner | UF2 bootloader
-makerdiary_nrf52840_mdk | s140 | Peripheral and Scanner | pyocd or ARM mbed DAPLink
-makerdiary_nrf52840_mdk_usb_dongle | s140 | Peripheral and Scanner | DFU bootloader & nrfutil
-electronut_labs_papyr | s140 | Peripheral and Scanner | UF2 bootloader
-electronut_labs_blip | s140 | Peripheral and Scanner | Black Magic Probe
-
## Segger Targets
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
* dfu-gen: Generates a Firmware zip to be used by the DFU flash application.
* dfu-flash: Triggers the DFU flash application to upload the firmware from the generated Firmware zip file.
-Example on how to generate and flash feather_nrf52840 target:
-
- make BOARD=feather_nrf52840 SD=s140
- make BOARD=feather_nrf52840 SD=s140 dfu-gen dfu-flash
-
-## Bluetooth LE REPL
-
-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.
-
-The configuration can be enabled by editing the `bluetooth_conf.h` and set `MICROPY_PY_BLE_NUS` to 1.
When enabled you have different options to test it:
* [NUS Console for Linux](https://github.com/tralamazza/nus_console) (recommended)
* [WebBluetooth REPL](https://glennrub.github.io/webbluetooth/micropython/repl/) (experimental)
-
-Other:
-* nRF UART application for IPhone/Android
-
-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.
diff --git a/ports/nrf/bluetooth/ble_uart.c b/ports/nrf/bluetooth/ble_uart.c
index 787a2a117..1e7a319bd 100644
--- a/ports/nrf/bluetooth/ble_uart.c
+++ b/ports/nrf/bluetooth/ble_uart.c
@@ -40,7 +40,7 @@
#include "shared-bindings/_bleio/Service.h"
#include "shared-bindings/_bleio/UUID.h"
-#if (MICROPY_PY_BLE_NUS == 1)
+#if CIRCUITPY_SERIAL_BLE
static const char default_name[] = "CP-REPL"; // max 8 chars or uuid won't fit in adv data
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) {
}
}
-#endif // MICROPY_PY_BLE_NUS
+#endif // CIRCUITPY_SERIAL_BLE
diff --git a/ports/nrf/boards/adafruit_nrf52840_s140_v6.ld b/ports/nrf/boards/adafruit_nrf52840_s140_v6.ld
index 2587a19e3..90b8862cf 100644
--- a/ports/nrf/boards/adafruit_nrf52840_s140_v6.ld
+++ b/ports/nrf/boards/adafruit_nrf52840_s140_v6.ld
@@ -24,6 +24,7 @@ MEMORY
FLASH_ISR (rx) : ORIGIN = 0x00026000, LENGTH = 0x001000
FLASH_TEXT (rx) : ORIGIN = 0x00027000, LENGTH = 0x086000
FLASH_FATFS (r) : ORIGIN = 0x000AD000, LENGTH = 0x040000
+ FLASH_CONFIG (r): ORIGIN = 0x000ED000, LENGTH = 0x007000
/* 0x2000000 - RAM:ORIGIN is reserved for Softdevice */
RAM (xrw) : ORIGIN = 0x20004000, LENGTH = 0x20040000 - 0x20004000
diff --git a/ports/nrf/boards/common.ld b/ports/nrf/boards/common.ld
index df81aae58..dfb355a76 100644
--- a/ports/nrf/boards/common.ld
+++ b/ports/nrf/boards/common.ld
@@ -2,6 +2,10 @@
__fatfs_flash_start_addr = ORIGIN(FLASH_FATFS);
__fatfs_flash_length = LENGTH(FLASH_FATFS);
+/* Flash region for configuration information (bonding info, keys, etc.) */
+__config_flash_start_addr = ORIGIN(FLASH_CONFIG);
+__config_flash_length = LENGTH(FLASH_CONFIG);
+
/* define output sections */
SECTIONS
{
@@ -13,7 +17,7 @@ SECTIONS
. = ALIGN(4);
} >FLASH_ISR
-
+
/* The program code and other data goes into FLASH */
.text :
{
@@ -28,7 +32,7 @@ SECTIONS
. = ALIGN(4);
_etext = .; /* define a global symbol at end of code */
} >FLASH_TEXT
-
+
/*
.ARM.extab :
{
@@ -42,10 +46,10 @@ SECTIONS
__exidx_end = .;
} >FLASH
*/
-
+
/* used by the startup to initialize data */
_sidata = .;
-
+
/* This is the initialized data section
The program executes knowing that the data is in the RAM
but the loader puts the initial values in the FLASH (inidata).
@@ -60,8 +64,8 @@ SECTIONS
. = ALIGN(4);
_edata = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */
- } >RAM
-
+ } >RAM
+
/* Uninitialized data section */
.bss :
{
@@ -105,4 +109,3 @@ SECTIONS
.ARM.attributes 0 : { *(.ARM.attributes) }
}
-
diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h
index 0b755a156..9c3d02f44 100644
--- a/ports/nrf/mpconfigport.h
+++ b/ports/nrf/mpconfigport.h
@@ -38,16 +38,6 @@
#define MICROPY_PY_UBINASCII (1)
#define MICROPY_PY_UJSON (1)
-// TODO this is old BLE stuff
-#if BLUETOOTH_SD
- #define MICROPY_PY_BLEIO (1)
- #define MICROPY_PY_BLE_NUS (0)
-#else
- #ifndef MICROPY_PY_BLEIO
- #define MICROPY_PY_BLEIO (0)
- #endif
-#endif
-
// 24kiB stack
#define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000
diff --git a/ports/nrf/supervisor/serial.c b/ports/nrf/supervisor/serial.c
index 6fd89eb3e..b19e9267c 100644
--- a/ports/nrf/supervisor/serial.c
+++ b/ports/nrf/supervisor/serial.c
@@ -28,15 +28,15 @@
#include "supervisor/serial.h"
-#if (MICROPY_PY_BLE_NUS == 1)
+#if CIRCUITPY_SERIAL_BLE
#include "ble_uart.h"
-#else
+#elif CIRCUITPY_SERIAL_UART
#include <string.h>
#include "nrf_gpio.h"
#include "nrfx_uarte.h"
#endif
-#if (MICROPY_PY_BLE_NUS == 1)
+#if CIRCUITPY_SERIAL_BLE
void serial_init(void) {
ble_uart_init();
@@ -58,7 +58,7 @@ void serial_write(const char *text) {
ble_uart_stdout_tx_str(text);
}
-#elif !defined(NRF52840_XXAA)
+#elif CIRCUITPY_SERIAL_UART
uint8_t serial_received_char;
nrfx_uarte_t serial_instance = NRFX_UARTE_INSTANCE(0);
@@ -124,4 +124,4 @@ void serial_write_substring(const char *text, uint32_t len) {
}
}
-#endif
+#endif // CIRCUITPY_SERIAL_UART
diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk
index c5756f488..d54e626e2 100644
--- a/py/circuitpy_mpconfig.mk
+++ b/py/circuitpy_mpconfig.mk
@@ -23,7 +23,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
-
# mpconfigboard.mk files can specify:
# CIRCUITPY_FULL_BUILD = 1 (which is the default)
# or
@@ -284,8 +283,21 @@ CIRCUITPY_USTACK = 0
endif
CFLAGS += -DCIRCUITPY_USTACK=$(CIRCUITPY_USTACK)
+# Non-module conditionals
ifndef CIRCUITPY_BITBANG_APA102
CIRCUITPY_BITBANG_APA102 = 0
endif
CFLAGS += -DCIRCUITPY_BITBANG_APA102=$(CIRCUITPY_BITBANG_APA102)
+
+# REPL over BLE
+ifndef CIRCUITPY_SERIAL_BLE
+CIRCUITPY_SERIAL_BLE = 0
+endif
+CFLAGS += -DCIRCUITPY_SERIAL_BLE=$(CIRCUITPY_SERIAL_BLE)
+
+# REPL over UART
+ifndef CIRCUITPY_SERIAL_UART
+CIRCUITPY_SERIAL_UART = 0
+endif
+CFLAGS += -DCIRCUITPY_SERIAL_UART=$(CIRCUITPY_SERIAL_UART)
diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk
index ee47be4b0..90b0e85d5 100644
--- a/supervisor/supervisor.mk
+++ b/supervisor/supervisor.mk
@@ -46,7 +46,7 @@ ifdef EXTERNAL_FLASH_DEVICES
else
ifeq ($(DISABLE_FILESYSTEM),1)
SRC_SUPERVISOR += supervisor/stub/internal_flash.c
- else
+ else
SRC_SUPERVISOR += supervisor/internal_flash.c
endif
endif
@@ -58,30 +58,31 @@ ifeq ($(USB),FALSE)
SRC_SUPERVISOR += supervisor/serial.c
endif
else
- SRC_SUPERVISOR += lib/tinyusb/src/common/tusb_fifo.c \
- lib/tinyusb/src/device/usbd.c \
- lib/tinyusb/src/device/usbd_control.c \
- lib/tinyusb/src/class/msc/msc_device.c \
- lib/tinyusb/src/class/cdc/cdc_device.c \
- lib/tinyusb/src/class/hid/hid_device.c \
- lib/tinyusb/src/class/midi/midi_device.c \
- lib/tinyusb/src/tusb.c \
- supervisor/shared/serial.c \
- supervisor/usb.c \
- supervisor/shared/usb/usb_desc.c \
- supervisor/shared/usb/usb.c \
- supervisor/shared/usb/usb_msc_flash.c \
- shared-bindings/usb_hid/__init__.c \
- shared-bindings/usb_hid/Device.c \
- shared-bindings/usb_midi/__init__.c \
- shared-bindings/usb_midi/PortIn.c \
- shared-bindings/usb_midi/PortOut.c \
- shared-module/usb_hid/__init__.c \
- shared-module/usb_hid/Device.c \
- shared-module/usb_midi/__init__.c \
- shared-module/usb_midi/PortIn.c \
- shared-module/usb_midi/PortOut.c \
- $(BUILD)/autogen_usb_descriptor.c
+ SRC_SUPERVISOR += \
+ lib/tinyusb/src/common/tusb_fifo.c \
+ lib/tinyusb/src/device/usbd.c \
+ lib/tinyusb/src/device/usbd_control.c \
+ lib/tinyusb/src/class/msc/msc_device.c \
+ lib/tinyusb/src/class/cdc/cdc_device.c \
+ lib/tinyusb/src/class/hid/hid_device.c \
+ lib/tinyusb/src/class/midi/midi_device.c \
+ lib/tinyusb/src/tusb.c \
+ supervisor/shared/serial.c \
+ supervisor/usb.c \
+ supervisor/shared/usb/usb_desc.c \
+ supervisor/shared/usb/usb.c \
+ supervisor/shared/usb/usb_msc_flash.c \
+ shared-bindings/usb_hid/__init__.c \
+ shared-bindings/usb_hid/Device.c \
+ shared-bindings/usb_midi/__init__.c \
+ shared-bindings/usb_midi/PortIn.c \
+ shared-bindings/usb_midi/PortOut.c \
+ shared-module/usb_hid/__init__.c \
+ shared-module/usb_hid/Device.c \
+ shared-module/usb_midi/__init__.c \
+ shared-module/usb_midi/PortIn.c \
+ shared-module/usb_midi/PortOut.c \
+ $(BUILD)/autogen_usb_descriptor.c
CFLAGS += -DUSB_AVAILABLE
endif