Skip to content

Add Spresense board #2207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ jobs:
- "sparkfun_redboard_turbo"
- "sparkfun_samd21_dev"
- "sparkfun_samd21_mini"
- "spresense"
- "stm32f411ve_discovery"
- "stm32f412zg_discovery"
- "trellis_m4_express"
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,6 @@
[submodule "ports/stm32f4/stm32f4"]
path = ports/stm32f4/stm32f4
url = https://github.com/adafruit/stm32f4.git
[submodule "ports/cxd56/spresense-exported-sdk"]
path = ports/cxd56/spresense-exported-sdk
url = https://github.com/sonydevworld/spresense-exported-sdk.git
1 change: 1 addition & 0 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"ports/cc3200",
"ports/cc3200/FreeRTOS",
"ports/cc3200/hal",
"ports/cxd56/spresense-exported-sdk",
"ports/esp32",
"ports/esp8266/boards",
"ports/esp8266/common-hal",
Expand Down
1 change: 1 addition & 0 deletions docs/supported_ports.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ and ESP8266.
../ports/atmel-samd/README
../ports/esp8266/README
../ports/nrf/README
../ports/cxd56/README
1 change: 1 addition & 0 deletions ports/cxd56/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build-*/
220 changes: 220 additions & 0 deletions ports/cxd56/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
# This file is part of the MicroPython project, http://micropython.org/
#
# The MIT License (MIT)
#
# Copyright 2019 Sony Semiconductor Solutions Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# Select the board to build for.
ifeq ($(BOARD),)
$(error You must provide a BOARD parameter)
else
ifeq ($(wildcard boards/$(BOARD)/.),)
$(error Invalid BOARD specified)
endif
endif

# If the build directory is not given, make it reflect the board name.
BUILD ?= build-$(BOARD)

include ../../py/mkenv.mk

# Board-specific
include boards/$(BOARD)/mpconfigboard.mk

# Port-specific
include mpconfigport.mk

# CircuitPython-specific
include $(TOP)/py/circuitpy_mpconfig.mk

# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h

# include py core make definitions
include $(TOP)/py/py.mk

include $(TOP)/supervisor/supervisor.mk

# Include make rules and variables common across CircuitPython builds.
include $(TOP)/py/circuitpy_defns.mk

CROSS_COMPILE = arm-none-eabi-

SPRESENSE_SDK = spresense-exported-sdk

FIRMWARE = $(SPRESENSE_SDK)/firmware

# Platforms are: Linux, Darwin, MSYS, CYGWIN
PLATFORM := $(firstword $(subst _, ,$(shell uname -s 2>/dev/null)))

ifeq ($(PLATFORM),Darwin)
# macOS
MKSPK = $(SPRESENSE_SDK)/sdk/tools/macos/mkspk
else ifeq ($(PLATFORM),Linux)
# Linux
MKSPK = $(SPRESENSE_SDK)/sdk/tools/linux/mkspk
else
# Cygwin/MSYS2
MKSPK = $(SPRESENSE_SDK)/sdk/tools/windows/mkspk.exe
endif

SERIAL ?= /dev/ttyUSB0

INC += \
-I. \
-I../.. \
-I../lib/mp-readline \
-I../lib/timeutils \
-I../../lib/tinyusb/src \
-I../../supervisor/shared/usb \
-Iboards/$(BOARD) \
-I$(BUILD) \
-I$(SPRESENSE_SDK)/nuttx/include \
-I$(SPRESENSE_SDK)/nuttx/arch \
-I$(SPRESENSE_SDK)/nuttx/arch/chip \
-I$(SPRESENSE_SDK)/sdk/bsp/include \
-I$(SPRESENSE_SDK)/sdk/bsp/include/sdk \

CFLAGS += \
$(INC) \
-DCONFIG_WCHAR_BUILTIN \
-DCONFIG_HAVE_DOUBLE \
-Dmain=spresense_main \
-D_estack=__stack \
-c \
-Os \
-pipe \
-std=gnu11 \
-mcpu=cortex-m4 \
-mthumb \
-mfpu=fpv4-sp-d16 \
-mfloat-abi=hard \
-mabi=aapcs \
-fno-builtin \
-fno-strict-aliasing \
-fno-strength-reduce \
-fomit-frame-pointer \
-ffunction-sections \
-fdata-sections \
-Wall \

LIBM = "${shell "$(CC)" $(CFLAGS) -print-file-name=libm.a}"

LIBGCC = "${shell "$(CC)" $(CFLAGS) -print-libgcc-file-name}"

LDFLAGS = \
--entry=__start \
-nostartfiles \
-nodefaultlibs \
--defsym __stack=_vectors+786432 \
-T$(SPRESENSE_SDK)/nuttx/build/ramconfig.ld \
--gc-sections \
-Map=$(BUILD)/output.map \
-o $(BUILD)/firmware.elf \
--start-group \
-u spresense_main \
$(BUILD)/libmpy.a \
$(SPRESENSE_SDK)/sdk/libs/libapps.a \
$(SPRESENSE_SDK)/sdk/libs/libsdk.a \
$(LIBM) \
$(LIBGCC) \
--end-group \
-L$(BUILD) \

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)

SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
$(addprefix common-hal/, $(SRC_COMMON_HAL))

SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
$(addprefix shared-module/, $(SRC_SHARED_MODULE))

SRC_S = supervisor/cpu.s

SRC_C = \
tick.c \
background.c \
fatfs_port.c \
mphalport.c \
boards/$(BOARD)/board.c \
boards/$(BOARD)/pins.c \
lib/utils/stdout_helpers.c \
lib/utils/pyexec.c \
lib/libc/string0.c \
lib/mp-readline/readline.c \
lib/timeutils/timeutils.c \
lib/oofatfs/ff.c \
lib/oofatfs/option/ccsbcs.c \
lib/utils/interrupt_char.c \
lib/utils/sys_stdio_mphal.c \
lib/utils/context_manager_helpers.c \
lib/utils/buffer_helper.c \
supervisor/shared/memory.c \
lib/tinyusb/src/portable/sony/cxd56/dcd_cxd56.c \

OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))

# List of sources for qstr extraction
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
# Sources that only hold QSTRs after pre-processing.
SRC_QSTR_PREPROCESSOR +=

all: $(BUILD)/firmware.spk

$(FIRMWARE):
$(ECHO) ""
$(ECHO) "Download the spresense binaries zip archive from:"
$(ECHO) "https://developer.sony.com/file/download/download-spresense-firmware-v1-4-000"
$(ECHO) "Extract spresense binaries to $(FIRMWARE)"
$(ECHO) ""
$(ECHO) "run make flash-bootloader again to flash bootloader."
exit 1

$(BUILD)/libmpy.a: $(SPRESENSE_SDK) $(OBJ)
$(ECHO) "AR $@"
$(Q)$(AR) rcs $(BUILD)/libmpy.a $(OBJ)

$(BUILD)/firmware.elf: $(BUILD)/libmpy.a
$(ECHO) "LD $@"
$(Q)$(LD) $(LDFLAGS)

$(BUILD)/firmware.spk: $(BUILD)/firmware.elf
$(ECHO) "Creating $@"
$(MKSPK) -c 2 $(BUILD)/firmware.elf nuttx $(BUILD)/firmware.spk

flash: $(BUILD)/firmware.spk
$(ECHO) "Writing $< to the board"
$(SPRESENSE_SDK)/sdk/tools/flash.sh -c $(SERIAL) $(BUILD)/firmware.spk

flash-bootloader: $(SPRESENSE_SDK) $(FIRMWARE)
$(ECHO) "Writing loader to the board"
$(SPRESENSE_SDK)/sdk/tools/flash.sh -l $(FIRMWARE) -c $(SERIAL)

include $(TOP)/py/mkrules.mk

# Print out the value of a make variable.
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
print-%:
@echo $* = $($*)
98 changes: 98 additions & 0 deletions ports/cxd56/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# CircuitPython port to Spresense #

This directory contains the port of CircuitPython to Spresense. It is a compact
development board based on Sony’s power-efficient multicore microcontroller
CXD5602.

Board features:

* Integrated GPS
* The embedded GNSS with support for GPS, QZSS and GLONASS enables applications
where tracking is required.
* Hi-res audio output and multi mic inputs
* Advanced 192kHz/24 bit audio codec and amplifier for audio output, and
support for up to 8 mic input channels.
* Multicore microcontroller
* Spresense is powered by Sony's CXD5602 microcontroller (ARM® Cortex®-M4F × 6
cores), with a clock speed of 156 MHz.

Currently, Spresense port does not support GNSS, Audio and Multicore.

Refer to [developer.sony.com/develop/spresense/](https://developer.sony.com/develop/spresense/)
for further information about this board.

## Prerequisites ##

### Linux ###

Add user to `dialout` group:

$ sudo usermod -a -G dialout <user-name>

### Windows ###

Download and install USB serial driver

* [CP210x USB to serial driver for Windows 7/8/8.1](https://www.silabs.com/documents/public/software/CP210x_Windows_Drivers.zip)

* [CP210x USB to serial driver for Windows 10](https://www.silabs.com/documents/public/software/CP210x_Universal_Windows_Driver.zip)

### macOS ###

Download and install USB serial driver

* [CP210x USB to serial driver for Mac OS X](https://www.silabs.com/documents/public/software/Mac_OSX_VCP_Driver.zip)

## Build instructions ##

Pull all submodules into your clone:

$ git submodule update --init --recursive

Build the MicroPython cross-compiler:

$ make -C mpy-cross

Change directory to cxd56:

$ cd ports/cxd56

To build circuitpython image run:

$ make BOARD=spresense

## USB connection ##

Connect the `Spresense main board` to the PC via the USB cable.

## Flash the bootloader ##

The correct bootloader is required for the Spresense board to function.

Bootloader information:

* The bootloader has to be flashed the very first time the board is used.

* You have to accept the End User License Agreement to be able to download and use the Spresense bootloader binary.

Download the spresense binaries zip archive from: [Spresense firmware v1-4-000](https://developer.sony.com/file/download/download-spresense-firmware-v1-4-000)

Extract spresense binaries in your PC to ports/spresense/spresense-exported-sdk/firmware/

To flash the bootloader run the command:

$ make BOARD=spresense flash-bootloader

## Flash the circuitpython image ##

To flash the firmware run the command:

$ make BOARD=spresense flash

## Accessing the board ##

Connect the `Spresense extension board` to the PC via the USB cable.

Once built and deployed, access the CircuitPython REPL (the Python prompt) via USB. You can run:

$ screen /dev/ttyACM0 115200
6 changes: 6 additions & 0 deletions ports/cxd56/alloca.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef _ALLOCA_H
#define _ALLOCA_H

#define alloca __builtin_alloca

#endif /* _ALLOCA_H */
Loading