From 6feb0209a4c54b96dfd565fc50af382e37a02e23 Mon Sep 17 00:00:00 2001 From: Kelvin Ly Date: Sun, 5 Jan 2020 13:06:33 -0500 Subject: [PATCH] Mostly working workflow for programming the FPGA --- rtl/.gitignore | 3 ++ rtl/Makefile | 22 ++++++++ rtl/bldc.pcf | 3 ++ rtl/bldc.v | 13 +++++ rtl/flash.sh | 3 ++ rtl/ice40flow | 131 ++++++++++++++++++++++++++++++++++++++++++++++ rtl/ice40flow.env | 12 +++++ rtl/run_yosys.sh | 15 ++++++ 8 files changed, 202 insertions(+) create mode 100644 rtl/.gitignore create mode 100644 rtl/Makefile create mode 100644 rtl/bldc.pcf create mode 100644 rtl/bldc.v create mode 100644 rtl/flash.sh create mode 100644 rtl/ice40flow create mode 100644 rtl/ice40flow.env create mode 100755 rtl/run_yosys.sh diff --git a/rtl/.gitignore b/rtl/.gitignore new file mode 100644 index 0000000..ca64527 --- /dev/null +++ b/rtl/.gitignore @@ -0,0 +1,3 @@ +*.asc +*.bin +*.json diff --git a/rtl/Makefile b/rtl/Makefile new file mode 100644 index 0000000..6602f6b --- /dev/null +++ b/rtl/Makefile @@ -0,0 +1,22 @@ +# Note: Yosys chokes on spaces in library directories (reported to yosys) +# Library path if not overriden (environment) +NEXTPNR_OPTS=--up5k --package sg48 +ICETIME_OPTS=-d up5k +FN=bldc + +${FN}.bin: ${FN}.asc + icepack ${FN}.asc ${FN}.bin + +${FN}.json: ${FN}.v + ./run_yosys.sh ${FN} + +${FN}.asc: ${FN}.json ${FN}.pcf + nextpnr-ice40 ${NEXTPNR_OPTS} --pcf "${FN}.pcf" --json "${FN}.json" --asc "${FN}.asc" + +#${FN}.rpt: ${FN}.pcf ${FN}.txt +# icetime $ICETIME_OPTS -p "${FN}.pcf" -mtr "${FN}.rpt" "${FN}.txt" + +clean: + rm ${FN}.json ${FN}.asc ${FN}.bin + +flash: $FN.bin diff --git a/rtl/bldc.pcf b/rtl/bldc.pcf new file mode 100644 index 0000000..2fe1a1a --- /dev/null +++ b/rtl/bldc.pcf @@ -0,0 +1,3 @@ +set_io --warn-no-port if_int 32 + +set_io --warn-no-port clk 20 diff --git a/rtl/bldc.v b/rtl/bldc.v new file mode 100644 index 0000000..4de35f1 --- /dev/null +++ b/rtl/bldc.v @@ -0,0 +1,13 @@ +module bldc ( + input clk, + output if_int + ); + +reg tmp = 0; +assign if_int = tmp; + +always @(posedge clk) begin + tmp <= ~tmp; +end + +endmodule diff --git a/rtl/flash.sh b/rtl/flash.sh new file mode 100644 index 0000000..ceb49b7 --- /dev/null +++ b/rtl/flash.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +flashrom -p ft2232_spi:type=232H,port=A diff --git a/rtl/ice40flow b/rtl/ice40flow new file mode 100644 index 0000000..b8b6a24 --- /dev/null +++ b/rtl/ice40flow @@ -0,0 +1,131 @@ +#!/bin/bash +# Script by Al Williams (Hackaday) + +#### Things you might want to change: +#### Note that none of these will clobber what's already there +#### In the environment/env file/command line + + # Note: Yosys chokes on spaces in library directories (reported to yosys) +# Library path if not overriden (environment) +DEF_YOSYS_LIBDIR=".:library" +# Default yosys options +DEF_YOSYS_OPTS= +# Default read_verilog options +DEF_YOSYS_V_OPTS=-noautowire +# default Arachne-pnr options +DEF_ARACHNE_OPTS=-d\ 1k +# default icetime options +DEF_ICETIME_OPTS=-d\ hx1k +# default project name +DEF_YOSYS_PROJECT= + +# You probably don't need to change much below this line + +# for -n option. Put it here so you can override the default +# in the env file but that's not likely to happen +PROG=1 + +# Set per directory defaults +# look for ice40flow.env in current directory +if [ -f ice40flow.env ] +then + # Note that if you want to not clobber existing environment + # You should set the DEF_ variables from above + # If you set the others you will override command line/user environment + # which is probably not what you want + source ice40flow.env +fi + + + # Note: Yosys chokes on spaces in library directories (reported to yosys) +# Library path if not overriden (environment) +YOSYS_LIBDIR=${YOSYS_LIBDIR:-$DEF_YOSYS_LIBDIR} +# Default yosys options +YOSYS_OPTS=${YOSYS_OPTS:-$DEF_YOSYS_OPTS} +# Default read_verilog options +YOSYS_V_OPTS=${YOSYS_V_OPTS:-$DEF_YOSYS_V_OPTS} +# default Arachne-pnr options +ARACHNE_OPTS=${ARACHNE_OPTS:-$DEF_ARACHNE_OPTS} +# default icetime options +ICETIME_OPTS=${ICETIME_OPTS:-$DEF_ICETIME_OPTS} +# Default project +YOSYS_DEFPROJECT=${YOSYS_DEFPROJECT:-$DEF_YOSYS_PROJECT} + + + + +# Handle -n options (didn't use getopts for one option) +# Note the default is set before reading env +# so if you wanted to never program you could +# set PROG=0 in the env file +# but there would be no good way to override +# Maybe put PROG=${PROG:-0} so you could say +# PROG=1 ice40flow to program? I don't know... +if [ "$1" == "-n" ] +then + PROG=0 + shift +fi + + + +# If you provide project name in environment we will +# use that unless you provide the name on the command line +# No project is an error +FN=${1-$YOSYS_DEFPROJECT} +if [ ! -z "$FN" -a ! -f "$FN.v" ] +then + echo 1>&2 "Can't find $FN.v" + unset FN +fi + +if [ -z "$FN" ] +then + echo 1>&2 "Usage: ice40flow [-n] project" + echo 1>&2 " -n = Do not program device" + echo 1>&2 " Note: project name of foo implies foo.v exists" + echo 1>&2 " do not supply the .v suffix on the project name" + echo 1>&2 " You can set the following options in the environment or in ice40flow.env:" + echo 1>&2 " YOSYS_DEFPROJECT = default project name if not specified on command line" + echo 1>&2 " YOSYS_LIBDIR = Colon separated directories to search (no spaces)" + echo 1>&2 " YOSYS_OPTS = Options to pass to yosys (try -Qq for quiet output)" + echo 1>&2 " YOSYS_V_OPTS = Options to pass to yosys read_verilog (default -noautowire)" + echo 1>&2 " ARACHNE_OPTS = Options to pass to Arachne-pnr (default -d 1k)" + echo 1>&2 " ICETIME_OPTS = Options to pass to icetime (default -d hx1k)" + exit 1 +fi + +# temporary test to warn people about Yosys not liking spaces in the libdir +if [[ "$YOSYS_LIBDIR" =~ " " ]] +then + echo 1>&2 "Error: Yosys currently won't accept spaces in library directory names!" + echo 1>&2 "Please change the library path and try again." + exit 99 +fi + +if [[ "$FN" =~ " " ]] +then + echo 1>&2 "Error: Please do not use spaces in the project name!" + exit 98 +fi + + + +yosys $YOSYS_OPTS <&2 "Programming disabled by -n option" +fi diff --git a/rtl/ice40flow.env b/rtl/ice40flow.env new file mode 100644 index 0000000..1b67663 --- /dev/null +++ b/rtl/ice40flow.env @@ -0,0 +1,12 @@ +# Generally, you want to only set DEF_xxx variables here +# unless you really mean to override the user's environment + +# DEF_YOSYS_LIBDIR = Default library path (colon separated directories; default .:library) +# DEF_YOSYS_OPTS = Default yosys command line options (default none) +# DEF_YOSYS_V_OPTS = Default yosys read_verilog options (default -noautowire) +# DEF_ARACHNE_OPTS = Default arachne-pnr options (default -d 1k) +# DEF_ICETIME_OPTS = Default icetime options (default -d hx1k) +# DEF_YOSYS_PROJECT = Default project name (default none) + +DEF_YOSYS_PROJECT=top +DEF_YOSYS_OPTS=-qQ diff --git a/rtl/run_yosys.sh b/rtl/run_yosys.sh new file mode 100755 index 0000000..dd03ede --- /dev/null +++ b/rtl/run_yosys.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +YOSYS_LIBDIR=".:library" +YOSYS_OPTS= +YOSYS_V_OPTS=-noautowire + +FN=$1 + +yosys ${YOSYS_OPTS} <