Skip to content

Commit f47b964

Browse files
authored
Merge pull request #2726 from xobs/fomu-circuitpython
ports: litex: add port and fomu board
2 parents cbe9512 + 7959544 commit f47b964

Some content is hidden

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

46 files changed

+3202
-57
lines changed

.github/workflows/build.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,49 @@ jobs:
279279
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
280280
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
281281
if: github.event_name == 'push' || (github.event_name == 'release' && (github.event.action == 'published' || github.event.action == 'rerequested'))
282+
283+
build-riscv:
284+
runs-on: ubuntu-16.04
285+
needs: test
286+
strategy:
287+
fail-fast: false
288+
matrix:
289+
board:
290+
- "fomu"
291+
292+
steps:
293+
- name: Set up Python 3.5
294+
uses: actions/setup-python@v1
295+
with:
296+
python-version: 3.5
297+
- name: Install deps
298+
run: |
299+
sudo apt-get install -y gettext
300+
pip install requests sh click setuptools awscli
301+
wget https://static.dev.sifive.com/dev-tools/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-centos6.tar.gz
302+
sudo tar -C /usr --strip-components=1 -xaf riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-centos6.tar.gz
303+
- name: Versions
304+
run: |
305+
gcc --version
306+
riscv64-unknown-elf-gcc --version
307+
python3 --version
308+
- uses: actions/checkout@v1
309+
with:
310+
submodules: true
311+
- name: mpy-cross
312+
run: make -C mpy-cross -j2
313+
- name: build
314+
run: python3 -u build_release_files.py
315+
working-directory: tools
316+
env:
317+
BOARDS: ${{ matrix.board }}
318+
- uses: actions/[email protected]
319+
with:
320+
name: ${{ matrix.board }}
321+
path: bin/${{ matrix.board }}
322+
- name: Upload to S3
323+
run: "[ -z \"$AWS_ACCESS_KEY_ID\" ] || aws s3 cp bin/ s3://adafruit-circuit-python/bin/ --recursive --no-progress --region us-east-1"
324+
env:
325+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
326+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
327+
if: github.event_name == 'push' || (github.event_name == 'release' && (github.event.action == 'published' || github.event.action == 'rerequested'))

conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"ports/atmel-samd/tools",
124124
"ports/cxd56/mkspk",
125125
"ports/cxd56/spresense-exported-sdk",
126+
"ports/litex/hw",
126127
"ports/minimal",
127128
"ports/mimxrt10xx/peripherals",
128129
"ports/mimxrt10xx/sdk",

ports/litex/Makefile

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# This file is part of the MicroPython project, http://micropython.org/
2+
#
3+
# The MIT License (MIT)
4+
#
5+
# Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
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+
# Board-specific
39+
include boards/$(BOARD)/mpconfigboard.mk
40+
# Port-specific
41+
include mpconfigport.mk
42+
43+
# CircuitPython-specific
44+
include $(TOP)/py/circuitpy_mpconfig.mk
45+
46+
# qstr definitions (must come before including py.mk)
47+
QSTR_DEFS = qstrdefsport.h
48+
49+
# include py core make definitions
50+
include $(TOP)/py/py.mk
51+
52+
include $(TOP)/supervisor/supervisor.mk
53+
54+
# Include make rules and variables common across CircuitPython builds.
55+
include $(TOP)/py/circuitpy_defns.mk
56+
57+
CROSS_COMPILE = riscv64-unknown-elf-
58+
59+
#######################################
60+
# CFLAGS
61+
#######################################
62+
63+
INC += -I.
64+
INC += -I../..
65+
INC += -I$(BUILD)
66+
INC += -I$(BUILD)/genhdr
67+
INC += -I./boards
68+
INC += -I./boards/$(BOARD)
69+
INC += -I./peripherals
70+
INC += -I../../lib/mp-readline
71+
INC += -I../../lib/tinyusb/src
72+
INC += -I../../supervisor/shared/usb
73+
74+
75+
#Debugging/Optimization
76+
ifeq ($(DEBUG), 1)
77+
CFLAGS += -ggdb
78+
# You may want to enable these flags to make setting breakpoints easier.
79+
CFLAGS += -fno-inline -fno-ipa-sra
80+
else
81+
CFLAGS += -Os -DNDEBUG -ggdb3
82+
# TODO: Test with -flto
83+
### CFLAGS += -flto
84+
endif
85+
86+
CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostdlib $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
87+
88+
# TODO: check this
89+
CFLAGS += -D__START=main -DFOMU
90+
91+
LD_FILE := boards/$(BOARD)/$(BOARD)-spi.ld
92+
93+
LDFLAGS = $(CFLAGS) -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs -Wl,-melf32lriscv
94+
LIBS := -lgcc -lc
95+
96+
97+
LDFLAGS += -flto -ffreestanding -nostartfiles -Wl,--gc-section -Wl,-Bstatic -Wl,-melf32lriscv -nostartfiles \
98+
-Wl,--no-warn-mismatch \
99+
-Wl,--build-id=none
100+
101+
# Use toolchain libm if we're not using our own.
102+
ifndef INTERNAL_LIBM
103+
LIBS += -lm
104+
endif
105+
106+
# TinyUSB defines
107+
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_VALENTYUSB_EPTRI -DCFG_TUD_CDC_RX_BUFSIZE=1024 -DCFG_TUD_CDC_TX_BUFSIZE=1024 -DCFG_TUD_MSC_BUFSIZE=4096 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_MIDI_TX_BUFSIZE=128
108+
109+
110+
######################################
111+
# source
112+
######################################
113+
114+
115+
SRC_C += \
116+
background.c \
117+
fatfs_port.c \
118+
mphalport.c \
119+
tick.c \
120+
boards/$(BOARD)/board.c \
121+
boards/$(BOARD)/pins.c \
122+
lib/libc/string0.c \
123+
lib/mp-readline/readline.c \
124+
lib/oofatfs/ff.c \
125+
lib/oofatfs/option/ccsbcs.c \
126+
lib/timeutils/timeutils.c \
127+
lib/utils/buffer_helper.c \
128+
lib/utils/context_manager_helpers.c \
129+
lib/utils/interrupt_char.c \
130+
lib/utils/pyexec.c \
131+
lib/utils/stdout_helpers.c \
132+
lib/utils/sys_stdio_mphal.c \
133+
supervisor/shared/memory.c
134+
135+
ifneq ($(USB),FALSE)
136+
SRC_C += lib/tinyusb/src/portable/valentyusb/eptri/dcd_eptri.c
137+
endif
138+
139+
SRC_S = \
140+
crt0-vexriscv.S
141+
142+
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
143+
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
144+
$(addprefix common-hal/, $(SRC_COMMON_HAL))
145+
146+
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
147+
$(addprefix shared-module/, $(SRC_SHARED_MODULE)) \
148+
$(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL))
149+
150+
151+
ifneq ($(FROZEN_MPY_DIR),)
152+
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py')
153+
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
154+
endif
155+
156+
OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
157+
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
158+
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))
159+
ifeq ($(INTERNAL_LIBM),1)
160+
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
161+
endif
162+
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.S=.o))
163+
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
164+
165+
$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os
166+
$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os
167+
168+
# List of sources for qstr extraction
169+
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
170+
# Sources that only hold QSTRs after pre-processing.
171+
SRC_QSTR_PREPROCESSOR +=
172+
173+
174+
all: $(BUILD)/firmware.bin $(BUILD)/firmware.dfu
175+
176+
$(BUILD)/firmware.elf: $(OBJ)
177+
$(STEPECHO) "LINK $@"
178+
$(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group
179+
$(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(LD_FILE)
180+
181+
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
182+
$(STEPECHO) "Create $@"
183+
$(Q)$(OBJCOPY) -O binary $^ $@
184+
# $(Q)$(OBJCOPY) -O binary -j .vectors -j .text -j .data $^ $@
185+
186+
$(BUILD)/firmware.hex: $(BUILD)/firmware.elf
187+
$(STEPECHO) "Create $@"
188+
$(Q)$(OBJCOPY) -O ihex $^ $@
189+
# $(Q)$(OBJCOPY) -O ihex -j .vectors -j .text -j .data $^ $@
190+
191+
$(BUILD)/firmware.dfu: $(BUILD)/firmware.bin
192+
$(ECHO) "Create $@"
193+
$(PYTHON3) $(TOP)/tools/dfu.py -b $^ -D 0x1209:0x5bf0 "$(BUILD)/firmware.dfu"
194+
195+
include $(TOP)/py/mkrules.mk
196+
197+
# Print out the value of a make variable.
198+
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
199+
print-%:
200+
@echo $* = $($*)

ports/litex/background.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
#include "py/runtime.h"
28+
#include "supervisor/filesystem.h"
29+
#include "supervisor/usb.h"
30+
#include "supervisor/shared/stack.h"
31+
32+
#if CIRCUITPY_DISPLAYIO
33+
#include "shared-module/displayio/__init__.h"
34+
#endif
35+
36+
static bool running_background_tasks = false;
37+
38+
void background_tasks_reset(void) {
39+
running_background_tasks = false;
40+
}
41+
42+
void run_background_tasks(void) {
43+
// Don't call ourselves recursively.
44+
if (running_background_tasks) {
45+
return;
46+
}
47+
running_background_tasks = true;
48+
filesystem_background();
49+
50+
#if USB_AVAILABLE
51+
usb_background();
52+
#endif
53+
54+
#if CIRCUITPY_DISPLAYIO
55+
displayio_background();
56+
#endif
57+
running_background_tasks = false;
58+
59+
assert_heap_ok();
60+
}

ports/litex/background.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Dan Halbert 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+
#ifndef MICROPY_INCLUDED_LITEX_BACKGROUND_H
28+
#define MICROPY_INCLUDED_LITEX_BACKGROUND_H
29+
30+
#include <stdbool.h>
31+
32+
void background_tasks_reset(void);
33+
void run_background_tasks(void);
34+
35+
#endif // MICROPY_INCLUDED_LITEX_BACKGROUND_H

0 commit comments

Comments
 (0)