Skip to content

Commit 00766e4

Browse files
committed
Merge commit 'f57be61' into nrf2_merge
2 parents 60e9b8f + f57be61 commit 00766e4

209 files changed

Lines changed: 59699 additions & 0 deletions

File tree

Some content is hidden

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

lib/utils/pyexec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ int pyexec_frozen_module(const char *name);
5555
void pyexec_event_repl_init(void);
5656
int pyexec_event_repl_process_char(int c);
5757
extern uint8_t pyexec_repl_active;
58+
mp_obj_t pyb_set_repl_info(mp_obj_t o_value);
5859

5960
MP_DECLARE_CONST_FUN_OBJ_1(pyb_set_repl_info_obj);
6061

ports/nrf/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Nordic files
2+
#####################
3+
drivers/bluetooth/s1*/
4+
5+
# Build files
6+
#####################
7+
build-*/
8+

ports/nrf/Makefile

Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
# Select the board to build for: if not given on the command line,
2+
# then default to pca10040.
3+
BOARD ?= pca10040
4+
ifeq ($(wildcard boards/$(BOARD)/.),)
5+
$(error Invalid BOARD specified)
6+
endif
7+
8+
# If SoftDevice is selected, try to use that one.
9+
SD ?=
10+
SD_LOWER = $(shell echo $(SD) | tr '[:upper:]' '[:lower:]')
11+
12+
# TODO: Verify that it is a valid target.
13+
14+
15+
ifeq ($(SD), )
16+
# If the build directory is not given, make it reflect the board name.
17+
BUILD ?= build-$(BOARD)
18+
include ../../py/mkenv.mk
19+
include boards/$(BOARD)/mpconfigboard.mk
20+
else
21+
# If the build directory is not given, make it reflect the board name.
22+
BUILD ?= build-$(BOARD)-$(SD_LOWER)
23+
include ../../py/mkenv.mk
24+
include boards/$(BOARD)/mpconfigboard_$(SD_LOWER).mk
25+
26+
include drivers/bluetooth/bluetooth_common.mk
27+
endif
28+
29+
# qstr definitions (must come before including py.mk)
30+
QSTR_DEFS = qstrdefsport.h $(BUILD)/pins_qstr.h
31+
32+
FROZEN_MPY_DIR = freeze
33+
34+
# include py core make definitions
35+
include ../../py/py.mk
36+
37+
38+
FATFS_DIR = lib/oofatfs
39+
MPY_CROSS = ../../mpy-cross/mpy-cross
40+
MPY_TOOL = ../../tools/mpy-tool.py
41+
42+
CROSS_COMPILE = arm-none-eabi-
43+
44+
MCU_VARIANT_UPPER = $(shell echo $(MCU_VARIANT) | tr '[:lower:]' '[:upper:]')
45+
46+
INC += -I.
47+
INC += -I../..
48+
INC += -I$(BUILD)
49+
INC += -I./../../lib/cmsis/inc
50+
INC += -I./device
51+
INC += -I./device/$(MCU_VARIANT)
52+
INC += -I./hal
53+
INC += -I./hal/$(MCU_VARIANT)
54+
INC += -I./modules/machine
55+
INC += -I./modules/ubluepy
56+
INC += -I./modules/music
57+
INC += -I./modules/random
58+
INC += -I./modules/ble
59+
INC += -I../../lib/mp-readline
60+
INC += -I./drivers/bluetooth
61+
INC += -I./drivers
62+
63+
NRF_DEFINES += -D$(MCU_VARIANT_UPPER)
64+
NRF_DEFINES += -DCONFIG_GPIO_AS_PINRESET
65+
66+
CFLAGS_CORTEX_M = -mthumb -mabi=aapcs -fsingle-precision-constant -Wdouble-promotion
67+
68+
CFLAGS_MCU_m4 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
69+
70+
CFLAGS_MCU_m0 = $(CFLAGS_CORTEX_M) --short-enums -mtune=cortex-m0 -mcpu=cortex-m0 -mfloat-abi=soft -fno-builtin
71+
72+
73+
CFLAGS += $(CFLAGS_MCU_$(MCU_SERIES))
74+
CFLAGS += $(INC) -Wall -Werror -ansi -std=gnu99 -nostdlib $(COPT) $(NRF_DEFINES) $(CFLAGS_MOD)
75+
CFLAGS += -fno-strict-aliasing
76+
CFLAGS += -fstack-usage
77+
CFLAGS += -fdata-sections -ffunction-sections
78+
CFLAGS += -Iboards/$(BOARD)
79+
CFLAGS += -DNRF5_HAL_H='<$(MCU_VARIANT)_hal.h>'
80+
81+
LDFLAGS = $(CFLAGS)
82+
LDFLAGS += -Xlinker -Map=$(@:.elf=.map)
83+
LDFLAGS += -mthumb -mabi=aapcs -T $(LD_FILE) -L boards/
84+
LDFLAGS += -Wl,--gc-sections
85+
86+
#Debugging/Optimization
87+
ifeq ($(DEBUG), 1)
88+
#ASMFLAGS += -g -gtabs+
89+
CFLAGS += -O0 -ggdb
90+
LDFLAGS += -O0
91+
else
92+
CFLAGS += -Os -DNDEBUG
93+
LDFLAGS += -Os
94+
endif
95+
96+
LIBS = \
97+
98+
ifeq ($(MCU_VARIANT), nrf52)
99+
LIBM_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-file-name=libm.a)
100+
LIBC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-file-name=libc.a)
101+
LIBGCC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
102+
103+
LIBS += -L $(dir $(LIBM_FILE_NAME)) -lm
104+
LIBS += -L $(dir $(LIBC_FILE_NAME)) -lc
105+
LIBS += -L $(dir $(LIBGCC_FILE_NAME)) -lgcc
106+
endif
107+
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+
117+
SRC_HAL = $(addprefix hal/,\
118+
hal_uart.c \
119+
hal_uarte.c \
120+
hal_spi.c \
121+
hal_spie.c \
122+
hal_time.c \
123+
hal_rtc.c \
124+
hal_timer.c \
125+
hal_twi.c \
126+
hal_adc.c \
127+
hal_adce.c \
128+
hal_temp.c \
129+
hal_gpio.c \
130+
hal_rng.c \
131+
)
132+
133+
ifeq ($(MCU_VARIANT), nrf52)
134+
SRC_HAL += $(addprefix hal/,\
135+
hal_pwm.c \
136+
)
137+
endif
138+
139+
SRC_C += \
140+
main.c \
141+
mphalport.c \
142+
help.c \
143+
gccollect.c \
144+
pin_named_pins.c \
145+
fatfs_port.c \
146+
drivers/softpwm.c \
147+
drivers/ticker.c \
148+
drivers/bluetooth/ble_drv.c \
149+
drivers/bluetooth/ble_uart.c \
150+
151+
DRIVERS_SRC_C += $(addprefix modules/,\
152+
machine/modmachine.c \
153+
machine/uart.c \
154+
machine/spi.c \
155+
machine/i2c.c \
156+
machine/adc.c \
157+
machine/pin.c \
158+
machine/timer.c \
159+
machine/rtc.c \
160+
machine/pwm.c \
161+
machine/led.c \
162+
machine/temp.c \
163+
uos/moduos.c \
164+
utime/modutime.c \
165+
pyb/modpyb.c \
166+
ubluepy/modubluepy.c \
167+
ubluepy/ubluepy_peripheral.c \
168+
ubluepy/ubluepy_service.c \
169+
ubluepy/ubluepy_characteristic.c \
170+
ubluepy/ubluepy_uuid.c \
171+
ubluepy/ubluepy_delegate.c \
172+
ubluepy/ubluepy_constants.c \
173+
ubluepy/ubluepy_descriptor.c \
174+
ubluepy/ubluepy_scanner.c \
175+
ubluepy/ubluepy_scan_entry.c \
176+
music/modmusic.c \
177+
music/musictunes.c \
178+
ble/modble.c \
179+
random/modrandom.c \
180+
)
181+
182+
SRC_C += \
183+
device/$(MCU_VARIANT)/system_$(MCU_SUB_VARIANT).c \
184+
device/$(MCU_VARIANT)/startup_$(MCU_SUB_VARIANT).c \
185+
186+
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py')
187+
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
188+
189+
OBJ += $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
190+
OBJ += $(addprefix $(BUILD)/, $(SRC_LIB:.c=.o))
191+
OBJ += $(addprefix $(BUILD)/, $(SRC_HAL:.c=.o))
192+
OBJ += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o))
193+
OBJ += $(BUILD)/pins_gen.o
194+
195+
$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os
196+
$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os
197+
198+
.phony: all flash sd binary hex
199+
200+
all: binary hex
201+
202+
OUTPUT_FILENAME = firmware
203+
204+
## Create binary .bin file from the .out file
205+
binary: $(BUILD)/$(OUTPUT_FILENAME).bin
206+
207+
$(BUILD)/$(OUTPUT_FILENAME).bin: $(BUILD)/$(OUTPUT_FILENAME).elf
208+
$(OBJCOPY) -O binary $< $@
209+
210+
## Create binary .hex file from the .out file
211+
hex: $(BUILD)/$(OUTPUT_FILENAME).hex
212+
213+
$(BUILD)/$(OUTPUT_FILENAME).hex: $(BUILD)/$(OUTPUT_FILENAME).elf
214+
$(OBJCOPY) -O ihex $< $@
215+
216+
FLASHER ?=
217+
218+
ifeq ($(FLASHER),)
219+
220+
flash: $(BUILD)/$(OUTPUT_FILENAME).hex
221+
nrfjprog --program $< --sectorerase -f $(MCU_VARIANT)
222+
nrfjprog --reset -f $(MCU_VARIANT)
223+
224+
sd: $(BUILD)/$(OUTPUT_FILENAME).hex
225+
nrfjprog --eraseall -f $(MCU_VARIANT)
226+
nrfjprog --program $(SOFTDEV_HEX) -f $(MCU_VARIANT)
227+
nrfjprog --program $< --sectorerase -f $(MCU_VARIANT)
228+
nrfjprog --reset -f $(MCU_VARIANT)
229+
230+
else ifeq ($(FLASHER), pyocd)
231+
232+
flash: $(BUILD)/$(OUTPUT_FILENAME).hex
233+
pyocd-flashtool -t $(MCU_VARIANT) $<
234+
235+
sd: $(BUILD)/$(OUTPUT_FILENAME).hex
236+
pyocd-flashtool -t $(MCU_VARIANT) --chip_erase
237+
pyocd-flashtool -t $(MCU_VARIANT) $(SOFTDEV_HEX)
238+
pyocd-flashtool -t $(MCU_VARIANT) $<
239+
240+
endif
241+
242+
$(BUILD)/$(OUTPUT_FILENAME).elf: $(OBJ)
243+
$(ECHO) "LINK $@"
244+
$(Q)$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
245+
$(Q)$(SIZE) $@
246+
247+
# List of sources for qstr extraction
248+
SRC_QSTR += $(SRC_C) $(SRC_MOD) $(SRC_LIB) $(DRIVERS_SRC_C)
249+
250+
# Append any auto-generated sources that are needed by sources listed in
251+
# SRC_QSTR
252+
SRC_QSTR_AUTO_DEPS +=
253+
254+
# Making OBJ use an order-only depenedency on the generated pins.h file
255+
# has the side effect of making the pins.h file before we actually compile
256+
# any of the objects. The normal dependency generation will deal with the
257+
# case when pins.h is modified. But when it doesn't exist, we don't know
258+
# which source files might need it.
259+
$(OBJ): | $(HEADER_BUILD)/pins.h
260+
261+
# Use a pattern rule here so that make will only call make-pins.py once to make
262+
# 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)
266+
267+
$(BUILD)/pins_gen.o: $(BUILD)/pins_gen.c
268+
$(call compile_c)
269+
270+
MAKE_PINS = boards/make-pins.py
271+
BOARD_PINS = boards/$(BOARD)/pins.csv
272+
AF_FILE = $(MCU_VARIANT)_af.csv
273+
PREFIX_FILE = boards/$(MCU_VARIANT)_prefix.c
274+
GEN_PINS_SRC = $(BUILD)/pins_gen.c
275+
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
276+
GEN_PINS_QSTR = $(BUILD)/pins_qstr.h
277+
GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins_af_const.h
278+
GEN_PINS_AF_PY = $(BUILD)/pins_af.py
279+
280+
ifneq ($(FROZEN_DIR),)
281+
# To use frozen source modules, put your .py files in a subdirectory (eg scripts/)
282+
# and then invoke make with FROZEN_DIR=scripts (be sure to build from scratch).
283+
CFLAGS += -DMICROPY_MODULE_FROZEN_STR
284+
endif
285+
286+
ifneq ($(FROZEN_MPY_DIR),)
287+
# To use frozen bytecode, put your .py files in a subdirectory (eg frozen/) and
288+
# then invoke make with FROZEN_MPY_DIR=frozen (be sure to build from scratch).
289+
CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
290+
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
291+
endif
292+
293+
include ../../py/mkrules.mk
294+

0 commit comments

Comments
 (0)