Skip to content

Commit 92113dd

Browse files
author
Kevin Townsend
committed
Supervisor REPL support for ports/nrf/boards/feather52
1 parent a38d894 commit 92113dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1622
-355
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@
4040
[submodule "tools/usb_descriptor"]
4141
path = tools/usb_descriptor
4242
url = https://github.com/adafruit/usb_descriptor.git
43+
[submodule "lib/nrfutil"]
44+
path = lib/nrfutil
45+
url = [email protected]:adafruit/nRF52_nrfutil.git

lib/nrfutil

Submodule nrfutil added at 07b4383

ports/nrf/Makefile

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Select the board to build for: if not given on the command line,
2-
# then default to pca10040.
3-
BOARD ?= pca10040
2+
# then default to feather52.
3+
BOARD ?= feather52
44
ifeq ($(wildcard boards/$(BOARD)/.),)
55
$(error Invalid BOARD specified)
66
endif
@@ -11,17 +11,18 @@ SD_LOWER = $(shell echo $(SD) | tr '[:upper:]' '[:lower:]')
1111

1212
# TODO: Verify that it is a valid target.
1313

14-
1514
ifeq ($(SD), )
1615
# If the build directory is not given, make it reflect the board name.
1716
BUILD ?= build-$(BOARD)
1817
include ../../py/mkenv.mk
1918
include boards/$(BOARD)/mpconfigboard.mk
19+
-include mpconfigport.mk
2020
else
2121
# If the build directory is not given, make it reflect the board name.
2222
BUILD ?= build-$(BOARD)-$(SD_LOWER)
2323
include ../../py/mkenv.mk
2424
include boards/$(BOARD)/mpconfigboard_$(SD_LOWER).mk
25+
-include mpconfigport.mk
2526

2627
include drivers/bluetooth/bluetooth_common.mk
2728
endif
@@ -34,10 +35,9 @@ FROZEN_MPY_DIR = freeze
3435
# include py core make definitions
3536
include ../../py/py.mk
3637

38+
include $(TOP)/supervisor/supervisor.mk
3739

3840
FATFS_DIR = lib/oofatfs
39-
MPY_CROSS = ../../mpy-cross/mpy-cross
40-
MPY_TOOL = ../../tools/mpy-tool.py
4141

4242
CROSS_COMPILE = arm-none-eabi-
4343

@@ -120,7 +120,6 @@ SRC_HAL = $(addprefix hal/,\
120120
hal_spi.c \
121121
hal_spie.c \
122122
hal_time.c \
123-
hal_rtc.c \
124123
hal_timer.c \
125124
hal_twi.c \
126125
hal_adc.c \
@@ -136,17 +135,19 @@ SRC_HAL += $(addprefix hal/,\
136135
)
137136
endif
138137

138+
139139
SRC_C += \
140-
main.c \
141140
mphalport.c \
142141
help.c \
143-
gccollect.c \
144142
pin_named_pins.c \
145143
fatfs_port.c \
146144
drivers/softpwm.c \
147145
drivers/ticker.c \
148146
drivers/bluetooth/ble_drv.c \
149147
drivers/bluetooth/ble_uart.c \
148+
boards/$(BOARD)/board.c \
149+
lib/utils/context_manager_helpers.c \
150+
fifo.c \
150151

151152
DRIVERS_SRC_C += $(addprefix modules/,\
152153
machine/modmachine.c \
@@ -156,7 +157,6 @@ DRIVERS_SRC_C += $(addprefix modules/,\
156157
machine/adc.c \
157158
machine/pin.c \
158159
machine/timer.c \
159-
machine/rtc.c \
160160
machine/pwm.c \
161161
machine/led.c \
162162
machine/temp.c \
@@ -183,13 +183,38 @@ SRC_C += \
183183
device/$(MCU_VARIANT)/system_$(MCU_SUB_VARIANT).c \
184184
device/$(MCU_VARIANT)/startup_$(MCU_SUB_VARIANT).c \
185185

186+
187+
SRC_COMMON_HAL += \
188+
board/__init__.c \
189+
digitalio/__init__.c \
190+
digitalio/DigitalInOut.c \
191+
microcontroller/__init__.c \
192+
microcontroller/Pin.c \
193+
microcontroller/Processor.c \
194+
time/__init__.c \
195+
196+
# These don't have corresponding files in each port but are still located in
197+
# shared-bindings to make it clear what the contents of the modules are.
198+
SRC_BINDINGS_ENUMS = \
199+
digitalio/Direction.c \
200+
digitalio/DriveMode.c \
201+
digitalio/Pull.c \
202+
help.c \
203+
math/__init__.c \
204+
util.c
205+
206+
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
207+
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
208+
$(addprefix common-hal/, $(SRC_COMMON_HAL))
209+
186210
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py')
187211
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
188212

189-
OBJ += $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
213+
OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
190214
OBJ += $(addprefix $(BUILD)/, $(SRC_LIB:.c=.o))
191215
OBJ += $(addprefix $(BUILD)/, $(SRC_HAL:.c=.o))
192216
OBJ += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o))
217+
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
193218
OBJ += $(BUILD)/pins_gen.o
194219

195220
$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os
@@ -245,7 +270,7 @@ $(BUILD)/$(OUTPUT_FILENAME).elf: $(OBJ)
245270
$(Q)$(SIZE) $@
246271

247272
# List of sources for qstr extraction
248-
SRC_QSTR += $(SRC_C) $(SRC_MOD) $(SRC_LIB) $(DRIVERS_SRC_C)
273+
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(SRC_LIB) $(DRIVERS_SRC_C) $(SRC_COMMON_HAL_EXPANDED)
249274

250275
# Append any auto-generated sources that are needed by sources listed in
251276
# SRC_QSTR

ports/nrf/boards/board.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
// This file defines board specific functions.
28+
29+
#ifndef MICROPY_INCLUDED_NRF_BOARDS_BOARD_H
30+
#define MICROPY_INCLUDED_NRF_BOARDS_BOARD_H
31+
32+
#include <stdbool.h>
33+
34+
extern volatile uint32_t ticks_ms;
35+
36+
// Initializes board related state once on start up.
37+
void board_init(void);
38+
39+
// Returns true if the user initiates safe mode in a board specific way.
40+
// Also add BOARD_USER_SAFE_MODE in mpconfigboard.h to explain the board specific
41+
// way.
42+
bool board_requests_safe_mode(void);
43+
44+
// Reset the state of off MCU components such as neopixels.
45+
void reset_board(void);
46+
47+
#endif // MICROPY_INCLUDED_NRF_BOARDS_BOARD_H

ports/nrf/boards/feather52/README.md

Lines changed: 75 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
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

2649
To 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

93100
The following command will package and flash the CircuitPython binary using the
94101
appropriate 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

Comments
 (0)