Skip to content

Commit 51582ab

Browse files
authored
Merge pull request #2207 from kamtom480/circuitpython-spresense
Add Spresense board
2 parents 1a53ced + 150f904 commit 51582ab

Some content is hidden

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

70 files changed

+3664
-3
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ jobs:
145145
- "sparkfun_redboard_turbo"
146146
- "sparkfun_samd21_dev"
147147
- "sparkfun_samd21_mini"
148+
- "spresense"
148149
- "stm32f411ve_discovery"
149150
- "stm32f412zg_discovery"
150151
- "trellis_m4_express"

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,6 @@
9898
[submodule "ports/stm32f4/stm32f4"]
9999
path = ports/stm32f4/stm32f4
100100
url = https://github.com/adafruit/stm32f4.git
101+
[submodule "ports/cxd56/spresense-exported-sdk"]
102+
path = ports/cxd56/spresense-exported-sdk
103+
url = https://github.com/sonydevworld/spresense-exported-sdk.git

conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
"ports/cc3200",
126126
"ports/cc3200/FreeRTOS",
127127
"ports/cc3200/hal",
128+
"ports/cxd56/spresense-exported-sdk",
128129
"ports/esp32",
129130
"ports/esp8266/boards",
130131
"ports/esp8266/common-hal",

docs/supported_ports.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ and ESP8266.
1010
../ports/atmel-samd/README
1111
../ports/esp8266/README
1212
../ports/nrf/README
13+
../ports/cxd56/README

ports/cxd56/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build-*/

ports/cxd56/Makefile

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
# This file is part of the MicroPython project, http://micropython.org/
2+
#
3+
# The MIT License (MIT)
4+
#
5+
# Copyright 2019 Sony Semiconductor Solutions Corporation
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
# THE SOFTWARE.
24+
25+
# Select the board to build for.
26+
ifeq ($(BOARD),)
27+
$(error You must provide a BOARD parameter)
28+
else
29+
ifeq ($(wildcard boards/$(BOARD)/.),)
30+
$(error Invalid BOARD specified)
31+
endif
32+
endif
33+
34+
# If the build directory is not given, make it reflect the board name.
35+
BUILD ?= build-$(BOARD)
36+
37+
include ../../py/mkenv.mk
38+
39+
# Board-specific
40+
include boards/$(BOARD)/mpconfigboard.mk
41+
42+
# Port-specific
43+
include mpconfigport.mk
44+
45+
# CircuitPython-specific
46+
include $(TOP)/py/circuitpy_mpconfig.mk
47+
48+
# qstr definitions (must come before including py.mk)
49+
QSTR_DEFS = qstrdefsport.h
50+
51+
# include py core make definitions
52+
include $(TOP)/py/py.mk
53+
54+
include $(TOP)/supervisor/supervisor.mk
55+
56+
# Include make rules and variables common across CircuitPython builds.
57+
include $(TOP)/py/circuitpy_defns.mk
58+
59+
CROSS_COMPILE = arm-none-eabi-
60+
61+
SPRESENSE_SDK = spresense-exported-sdk
62+
63+
FIRMWARE = $(SPRESENSE_SDK)/firmware
64+
65+
# Platforms are: Linux, Darwin, MSYS, CYGWIN
66+
PLATFORM := $(firstword $(subst _, ,$(shell uname -s 2>/dev/null)))
67+
68+
ifeq ($(PLATFORM),Darwin)
69+
# macOS
70+
MKSPK = $(SPRESENSE_SDK)/sdk/tools/macos/mkspk
71+
else ifeq ($(PLATFORM),Linux)
72+
# Linux
73+
MKSPK = $(SPRESENSE_SDK)/sdk/tools/linux/mkspk
74+
else
75+
# Cygwin/MSYS2
76+
MKSPK = $(SPRESENSE_SDK)/sdk/tools/windows/mkspk.exe
77+
endif
78+
79+
SERIAL ?= /dev/ttyUSB0
80+
81+
INC += \
82+
-I. \
83+
-I../.. \
84+
-I../lib/mp-readline \
85+
-I../lib/timeutils \
86+
-I../../lib/tinyusb/src \
87+
-I../../supervisor/shared/usb \
88+
-Iboards/$(BOARD) \
89+
-I$(BUILD) \
90+
-I$(SPRESENSE_SDK)/nuttx/include \
91+
-I$(SPRESENSE_SDK)/nuttx/arch \
92+
-I$(SPRESENSE_SDK)/nuttx/arch/chip \
93+
-I$(SPRESENSE_SDK)/sdk/bsp/include \
94+
-I$(SPRESENSE_SDK)/sdk/bsp/include/sdk \
95+
96+
CFLAGS += \
97+
$(INC) \
98+
-DCONFIG_WCHAR_BUILTIN \
99+
-DCONFIG_HAVE_DOUBLE \
100+
-Dmain=spresense_main \
101+
-D_estack=__stack \
102+
-c \
103+
-Os \
104+
-pipe \
105+
-std=gnu11 \
106+
-mcpu=cortex-m4 \
107+
-mthumb \
108+
-mfpu=fpv4-sp-d16 \
109+
-mfloat-abi=hard \
110+
-mabi=aapcs \
111+
-fno-builtin \
112+
-fno-strict-aliasing \
113+
-fno-strength-reduce \
114+
-fomit-frame-pointer \
115+
-ffunction-sections \
116+
-fdata-sections \
117+
-Wall \
118+
119+
LIBM = "${shell "$(CC)" $(CFLAGS) -print-file-name=libm.a}"
120+
121+
LIBGCC = "${shell "$(CC)" $(CFLAGS) -print-libgcc-file-name}"
122+
123+
LDFLAGS = \
124+
--entry=__start \
125+
-nostartfiles \
126+
-nodefaultlibs \
127+
--defsym __stack=_vectors+786432 \
128+
-T$(SPRESENSE_SDK)/nuttx/build/ramconfig.ld \
129+
--gc-sections \
130+
-Map=$(BUILD)/output.map \
131+
-o $(BUILD)/firmware.elf \
132+
--start-group \
133+
-u spresense_main \
134+
$(BUILD)/libmpy.a \
135+
$(SPRESENSE_SDK)/sdk/libs/libapps.a \
136+
$(SPRESENSE_SDK)/sdk/libs/libsdk.a \
137+
$(LIBM) \
138+
$(LIBGCC) \
139+
--end-group \
140+
-L$(BUILD) \
141+
142+
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_CXD56 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=512 $(CFLAGS_MOD)
143+
144+
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
145+
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
146+
$(addprefix common-hal/, $(SRC_COMMON_HAL))
147+
148+
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
149+
$(addprefix shared-module/, $(SRC_SHARED_MODULE))
150+
151+
SRC_S = supervisor/cpu.s
152+
153+
SRC_C = \
154+
tick.c \
155+
background.c \
156+
fatfs_port.c \
157+
mphalport.c \
158+
boards/$(BOARD)/board.c \
159+
boards/$(BOARD)/pins.c \
160+
lib/utils/stdout_helpers.c \
161+
lib/utils/pyexec.c \
162+
lib/libc/string0.c \
163+
lib/mp-readline/readline.c \
164+
lib/timeutils/timeutils.c \
165+
lib/oofatfs/ff.c \
166+
lib/oofatfs/option/ccsbcs.c \
167+
lib/utils/interrupt_char.c \
168+
lib/utils/sys_stdio_mphal.c \
169+
lib/utils/context_manager_helpers.c \
170+
lib/utils/buffer_helper.c \
171+
supervisor/shared/memory.c \
172+
lib/tinyusb/src/portable/sony/cxd56/dcd_cxd56.c \
173+
174+
OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
175+
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
176+
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
177+
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))
178+
179+
# List of sources for qstr extraction
180+
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
181+
# Sources that only hold QSTRs after pre-processing.
182+
SRC_QSTR_PREPROCESSOR +=
183+
184+
all: $(BUILD)/firmware.spk
185+
186+
$(FIRMWARE):
187+
$(ECHO) ""
188+
$(ECHO) "Download the spresense binaries zip archive from:"
189+
$(ECHO) "https://developer.sony.com/file/download/download-spresense-firmware-v1-4-000"
190+
$(ECHO) "Extract spresense binaries to $(FIRMWARE)"
191+
$(ECHO) ""
192+
$(ECHO) "run make flash-bootloader again to flash bootloader."
193+
exit 1
194+
195+
$(BUILD)/libmpy.a: $(SPRESENSE_SDK) $(OBJ)
196+
$(ECHO) "AR $@"
197+
$(Q)$(AR) rcs $(BUILD)/libmpy.a $(OBJ)
198+
199+
$(BUILD)/firmware.elf: $(BUILD)/libmpy.a
200+
$(ECHO) "LD $@"
201+
$(Q)$(LD) $(LDFLAGS)
202+
203+
$(BUILD)/firmware.spk: $(BUILD)/firmware.elf
204+
$(ECHO) "Creating $@"
205+
$(MKSPK) -c 2 $(BUILD)/firmware.elf nuttx $(BUILD)/firmware.spk
206+
207+
flash: $(BUILD)/firmware.spk
208+
$(ECHO) "Writing $< to the board"
209+
$(SPRESENSE_SDK)/sdk/tools/flash.sh -c $(SERIAL) $(BUILD)/firmware.spk
210+
211+
flash-bootloader: $(SPRESENSE_SDK) $(FIRMWARE)
212+
$(ECHO) "Writing loader to the board"
213+
$(SPRESENSE_SDK)/sdk/tools/flash.sh -l $(FIRMWARE) -c $(SERIAL)
214+
215+
include $(TOP)/py/mkrules.mk
216+
217+
# Print out the value of a make variable.
218+
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
219+
print-%:
220+
@echo $* = $($*)

ports/cxd56/README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# CircuitPython port to Spresense #
2+
3+
This directory contains the port of CircuitPython to Spresense. It is a compact
4+
development board based on Sony’s power-efficient multicore microcontroller
5+
CXD5602.
6+
7+
Board features:
8+
9+
* Integrated GPS
10+
* The embedded GNSS with support for GPS, QZSS and GLONASS enables applications
11+
where tracking is required.
12+
* Hi-res audio output and multi mic inputs
13+
* Advanced 192kHz/24 bit audio codec and amplifier for audio output, and
14+
support for up to 8 mic input channels.
15+
* Multicore microcontroller
16+
* Spresense is powered by Sony's CXD5602 microcontroller (ARM® Cortex®-M4F × 6
17+
cores), with a clock speed of 156 MHz.
18+
19+
Currently, Spresense port does not support GNSS, Audio and Multicore.
20+
21+
Refer to [developer.sony.com/develop/spresense/](https://developer.sony.com/develop/spresense/)
22+
for further information about this board.
23+
24+
## Prerequisites ##
25+
26+
### Linux ###
27+
28+
Add user to `dialout` group:
29+
30+
$ sudo usermod -a -G dialout <user-name>
31+
32+
### Windows ###
33+
34+
Download and install USB serial driver
35+
36+
* [CP210x USB to serial driver for Windows 7/8/8.1](https://www.silabs.com/documents/public/software/CP210x_Windows_Drivers.zip)
37+
38+
* [CP210x USB to serial driver for Windows 10](https://www.silabs.com/documents/public/software/CP210x_Universal_Windows_Driver.zip)
39+
40+
### macOS ###
41+
42+
Download and install USB serial driver
43+
44+
* [CP210x USB to serial driver for Mac OS X](https://www.silabs.com/documents/public/software/Mac_OSX_VCP_Driver.zip)
45+
46+
## Build instructions ##
47+
48+
Pull all submodules into your clone:
49+
50+
$ git submodule update --init --recursive
51+
52+
Build the MicroPython cross-compiler:
53+
54+
$ make -C mpy-cross
55+
56+
Change directory to cxd56:
57+
58+
$ cd ports/cxd56
59+
60+
To build circuitpython image run:
61+
62+
$ make BOARD=spresense
63+
64+
## USB connection ##
65+
66+
Connect the `Spresense main board` to the PC via the USB cable.
67+
68+
## Flash the bootloader ##
69+
70+
The correct bootloader is required for the Spresense board to function.
71+
72+
Bootloader information:
73+
74+
* The bootloader has to be flashed the very first time the board is used.
75+
76+
* You have to accept the End User License Agreement to be able to download and use the Spresense bootloader binary.
77+
78+
Download the spresense binaries zip archive from: [Spresense firmware v1-4-000](https://developer.sony.com/file/download/download-spresense-firmware-v1-4-000)
79+
80+
Extract spresense binaries in your PC to ports/spresense/spresense-exported-sdk/firmware/
81+
82+
To flash the bootloader run the command:
83+
84+
$ make BOARD=spresense flash-bootloader
85+
86+
## Flash the circuitpython image ##
87+
88+
To flash the firmware run the command:
89+
90+
$ make BOARD=spresense flash
91+
92+
## Accessing the board ##
93+
94+
Connect the `Spresense extension board` to the PC via the USB cable.
95+
96+
Once built and deployed, access the CircuitPython REPL (the Python prompt) via USB. You can run:
97+
98+
$ screen /dev/ttyACM0 115200

ports/cxd56/alloca.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef _ALLOCA_H
2+
#define _ALLOCA_H
3+
4+
#define alloca __builtin_alloca
5+
6+
#endif /* _ALLOCA_H */

0 commit comments

Comments
 (0)