Skip to content

Commit 60a23f0

Browse files
author
microbuilder
committed
nRF52 update with internal file system support
1 parent 36ec29d commit 60a23f0

Some content is hidden

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

75 files changed

+4035
-616
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 = https://github.com/adafruit/nRF52_nrfutil

lib/nrfutil

Submodule nrfutil added at 07b4383

ports/nrf/Makefile

Lines changed: 96 additions & 35 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,33 +11,38 @@ 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
20+
21+
INC += -Idrivers/bluetooth/s132_$(MCU_VARIANT)_$(SOFTDEV_VERSION)/s132_$(MCU_VARIANT)_$(SOFTDEV_VERSION)_API/include
22+
INC += -Idrivers/bluetooth/s132_$(MCU_VARIANT)_$(SOFTDEV_VERSION)/s132_$(MCU_VARIANT)_$(SOFTDEV_VERSION)_API/include/$(MCU_VARIANT)
23+
2024
else
2125
# If the build directory is not given, make it reflect the board name.
2226
BUILD ?= build-$(BOARD)-$(SD_LOWER)
2327
include ../../py/mkenv.mk
2428
include boards/$(BOARD)/mpconfigboard_$(SD_LOWER).mk
29+
-include mpconfigport.mk
2530

2631
include drivers/bluetooth/bluetooth_common.mk
2732
endif
2833

34+
2935
# qstr definitions (must come before including py.mk)
30-
QSTR_DEFS = qstrdefsport.h $(BUILD)/pins_qstr.h
36+
QSTR_DEFS = qstrdefsport.h
3137

3238
FROZEN_MPY_DIR = freeze
3339

3440
# include py core make definitions
3541
include ../../py/py.mk
3642

43+
include $(TOP)/supervisor/supervisor.mk
3744

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

4247
CROSS_COMPILE = arm-none-eabi-
4348

@@ -105,22 +110,12 @@ LIBS += -L $(dir $(LIBC_FILE_NAME)) -lc
105110
LIBS += -L $(dir $(LIBGCC_FILE_NAME)) -lgcc
106111
endif
107112

108-
SRC_LIB = $(addprefix lib/,\
109-
libc/string0.c \
110-
mp-readline/readline.c \
111-
utils/pyexec.c \
112-
timeutils/timeutils.c \
113-
oofatfs/ff.c \
114-
oofatfs/option/unicode.c \
115-
)
116-
117113
SRC_HAL = $(addprefix hal/,\
118114
hal_uart.c \
119115
hal_uarte.c \
120116
hal_spi.c \
121117
hal_spie.c \
122118
hal_time.c \
123-
hal_rtc.c \
124119
hal_timer.c \
125120
hal_twi.c \
126121
hal_adc.c \
@@ -136,17 +131,31 @@ SRC_HAL += $(addprefix hal/,\
136131
)
137132
endif
138133

134+
139135
SRC_C += \
140-
main.c \
141136
mphalport.c \
142137
help.c \
143-
gccollect.c \
144138
pin_named_pins.c \
145139
fatfs_port.c \
140+
fifo.c \
146141
drivers/softpwm.c \
147142
drivers/ticker.c \
148143
drivers/bluetooth/ble_drv.c \
149144
drivers/bluetooth/ble_uart.c \
145+
boards/$(BOARD)/board.c \
146+
boards/$(BOARD)/pins.c \
147+
device/$(MCU_VARIANT)/system_$(MCU_SUB_VARIANT).c \
148+
device/$(MCU_VARIANT)/startup_$(MCU_SUB_VARIANT).c \
149+
lib/oofatfs/ff.c \
150+
lib/oofatfs/option/ccsbcs.c \
151+
lib/timeutils/timeutils.c \
152+
lib/utils/buffer_helper.c \
153+
lib/utils/context_manager_helpers.c \
154+
lib/utils/pyexec.c \
155+
lib/libc/string0.c \
156+
lib/mp-readline/readline.c \
157+
internal_flash.c \
158+
150159

151160
DRIVERS_SRC_C += $(addprefix modules/,\
152161
machine/modmachine.c \
@@ -156,11 +165,9 @@ DRIVERS_SRC_C += $(addprefix modules/,\
156165
machine/adc.c \
157166
machine/pin.c \
158167
machine/timer.c \
159-
machine/rtc.c \
160168
machine/pwm.c \
161169
machine/led.c \
162170
machine/temp.c \
163-
uos/moduos.c \
164171
utime/modutime.c \
165172
pyb/modpyb.c \
166173
ubluepy/modubluepy.c \
@@ -179,18 +186,72 @@ DRIVERS_SRC_C += $(addprefix modules/,\
179186
random/modrandom.c \
180187
)
181188

182-
SRC_C += \
183-
device/$(MCU_VARIANT)/system_$(MCU_SUB_VARIANT).c \
184-
device/$(MCU_VARIANT)/startup_$(MCU_SUB_VARIANT).c \
189+
190+
SRC_COMMON_HAL += \
191+
board/__init__.c \
192+
digitalio/__init__.c \
193+
digitalio/DigitalInOut.c \
194+
microcontroller/__init__.c \
195+
microcontroller/Pin.c \
196+
microcontroller/Processor.c \
197+
os/__init__.c \
198+
time/__init__.c \
199+
analogio/__init__.c \
200+
analogio/AnalogIn.c \
201+
analogio/AnalogOut.c \
202+
busio/__init__.c\
203+
busio/I2C.c \
204+
busio/SPI.c \
205+
pulseio/__init__.c \
206+
pulseio/PulseIn.c \
207+
pulseio/PulseOut.c \
208+
pulseio/PWMOut.c \
209+
storage/__init__.c \
210+
211+
# These don't have corresponding files in each port but are still located in
212+
# shared-bindings to make it clear what the contents of the modules are.
213+
SRC_BINDINGS_ENUMS = \
214+
digitalio/Direction.c \
215+
digitalio/DriveMode.c \
216+
digitalio/Pull.c \
217+
help.c \
218+
math/__init__.c \
219+
supervisor/__init__.c \
220+
util.c
221+
222+
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
223+
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
224+
$(addprefix common-hal/, $(SRC_COMMON_HAL))
225+
226+
SRC_SHARED_MODULE = \
227+
os/__init__.c \
228+
random/__init__.c \
229+
storage/__init__.c \
230+
231+
# bitbangio/__init__.c \
232+
bitbangio/I2C.c \
233+
bitbangio/OneWire.c \
234+
bitbangio/SPI.c \
235+
busio/OneWire.c \
236+
gamepad/__init__.c \
237+
gamepad/GamePad.c \
238+
struct/__init__.c \
239+
uheap/__init__.c \
240+
ustack/__init__.c
241+
242+
#SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
243+
$(addprefix shared-module/, $(SRC_SHARED_MODULE))
244+
245+
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-module/, $(SRC_SHARED_MODULE))
185246

186247
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py')
187248
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
188249

189-
OBJ += $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
190-
OBJ += $(addprefix $(BUILD)/, $(SRC_LIB:.c=.o))
250+
OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
191251
OBJ += $(addprefix $(BUILD)/, $(SRC_HAL:.c=.o))
192252
OBJ += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o))
193-
OBJ += $(BUILD)/pins_gen.o
253+
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
254+
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))
194255

195256
$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os
196257
$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os
@@ -241,11 +302,11 @@ endif
241302

242303
$(BUILD)/$(OUTPUT_FILENAME).elf: $(OBJ)
243304
$(ECHO) "LINK $@"
244-
$(Q)$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
305+
$(Q)$(CC) $(LDFLAGS) -o $@ $(OBJ) -Wl,--start-group $(LIBS) -Wl,--end-group
245306
$(Q)$(SIZE) $@
246307

247308
# List of sources for qstr extraction
248-
SRC_QSTR += $(SRC_C) $(SRC_MOD) $(SRC_LIB) $(DRIVERS_SRC_C)
309+
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(DRIVERS_SRC_C) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
249310

250311
# Append any auto-generated sources that are needed by sources listed in
251312
# SRC_QSTR
@@ -256,16 +317,16 @@ SRC_QSTR_AUTO_DEPS +=
256317
# any of the objects. The normal dependency generation will deal with the
257318
# case when pins.h is modified. But when it doesn't exist, we don't know
258319
# which source files might need it.
259-
$(OBJ): | $(HEADER_BUILD)/pins.h
320+
#$(OBJ): | $(HEADER_BUILD)/pins.h
260321

261322
# Use a pattern rule here so that make will only call make-pins.py once to make
262323
# both pins_$(BOARD).c and pins.h
263-
$(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(BUILD)/%_qstr.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
264-
$(ECHO) "Create $@"
265-
$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) --af-const $(GEN_PINS_AF_CONST) --af-py $(GEN_PINS_AF_PY) > $(GEN_PINS_SRC)
324+
#$(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(BUILD)/%_qstr.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
325+
# $(ECHO) "Create $@"
326+
# $(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) --af-const $(GEN_PINS_AF_CONST) --af-py $(GEN_PINS_AF_PY) > $(GEN_PINS_SRC)
266327

267-
$(BUILD)/pins_gen.o: $(BUILD)/pins_gen.c
268-
$(call compile_c)
328+
#$(BUILD)/pins_gen.o: $(BUILD)/pins_gen.c
329+
# $(call compile_c)
269330

270331
MAKE_PINS = boards/make-pins.py
271332
BOARD_PINS = boards/$(BOARD)/pins.csv
@@ -290,4 +351,4 @@ CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
290351
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
291352
endif
292353

293-
include ../../py/mkrules.mk
354+
include $(TOP)/py/mkrules.mk

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/common.ld

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/* Flash region for File System */
2+
__fatfs_flash_start_addr = ORIGIN(FLASH_FATFS);
3+
__fatfs_flash_length = LENGTH(FLASH_FATFS);
4+
15
/* define output sections */
26
SECTIONS
37
{
@@ -75,8 +79,8 @@ SECTIONS
7579
.heap :
7680
{
7781
. = ALIGN(4);
78-
PROVIDE ( end = . );
79-
PROVIDE ( _end = . );
82+
PROVIDE ( end = . );
83+
PROVIDE ( _end = . );
8084
_heap_start = .; /* define a global symbol at heap start */
8185
. = . + _minimum_heap_size;
8286
} >RAM
@@ -101,3 +105,4 @@ SECTIONS
101105

102106
.ARM.attributes 0 : { *(.ARM.attributes) }
103107
}
108+

0 commit comments

Comments
 (0)