From 9918d5c9fab5011ae160da25816186ada28f8717 Mon Sep 17 00:00:00 2001 From: Unai Martinez-Corral Date: Mon, 1 Aug 2022 14:42:58 +0200 Subject: [PATCH 1/6] ice40: add environment.yml and requirements.txt Signed-off-by: Unai Martinez-Corral --- ice40/environment.yml | 31 +++++++++++++++++++++++++++++++ ice40/requirements.txt | 17 +++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 ice40/environment.yml create mode 100644 ice40/requirements.txt diff --git a/ice40/environment.yml b/ice40/environment.yml new file mode 100644 index 00000000..e1aa4419 --- /dev/null +++ b/ice40/environment.yml @@ -0,0 +1,31 @@ +# Copyright (C) 2020-2022 F4PGA Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +name: ice40 + +channels: + - litex-hub + +dependencies: + - litex-hub::yosys=0.15_51_g6318db615=20220317_162926_py37 + - litex-hub::symbiflow-yosys-plugins=1.0.0_7_832_ga2a80a1=20220317_162926 + - litex-hub::vtr-optimized=8.0.0_5338_g829c06d8f=20220409_131122 + - make + - git + - pip + # Packages installed from PyPI + - pip: + - -r requirements.txt diff --git a/ice40/requirements.txt b/ice40/requirements.txt new file mode 100644 index 00000000..0b2760ad --- /dev/null +++ b/ice40/requirements.txt @@ -0,0 +1,17 @@ +# Copyright (C) 2020-2022 F4PGA Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +https://github.com/chipsalliance/f4pga/archive/main.zip#subdirectory=f4pga From cfc8c5b289dc55dafac8a43e5dec725fffc86492 Mon Sep 17 00:00:00 2001 From: Unai Martinez-Corral Date: Mon, 1 Aug 2022 16:03:03 +0200 Subject: [PATCH 2/6] docs/getting: support ice40 Signed-off-by: Unai Martinez-Corral --- docs/getting.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/getting.rst b/docs/getting.rst index 4a4081f6..371b1fcd 100644 --- a/docs/getting.rst +++ b/docs/getting.rst @@ -107,6 +107,13 @@ Select your target FPGA family: export FPGA_FAM=eos-s3 + .. group-tab:: ICE40 + + .. code-block:: bash + :name: fpga-fam-ice40 + + export FPGA_FAM=ice40 + Next, setup Conda and your system's environment, and download architecture definitions: .. NOTE:: @@ -146,6 +153,7 @@ If the above commands exited without errors, you have successfully installed and * Subdir :ghsrc:`xc7` for the Artix-7 devices * Subdir :ghsrc:`eos-s3` for the EOS S3 devices + * Subdir :ghsrc:`ice40` for the ICE40 devices Bumping specific tools ====================== From 9eaeef40517dd9575bccdbf336b90e759a380aa0 Mon Sep 17 00:00:00 2001 From: Krzysztof Boronski Date: Wed, 20 Jul 2022 13:18:41 -0500 Subject: [PATCH 3/6] "spectrum" example for FOMU (ice40) Signed-off-by: Krzysztof Boronski --- ice40/spectrum/flow.json | 20 +++++++ ice40/spectrum/fomu.pcf | 4 ++ ice40/spectrum/spectrum.v | 114 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 ice40/spectrum/flow.json create mode 100644 ice40/spectrum/fomu.pcf create mode 100644 ice40/spectrum/spectrum.v diff --git a/ice40/spectrum/flow.json b/ice40/spectrum/flow.json new file mode 100644 index 00000000..5d605707 --- /dev/null +++ b/ice40/spectrum/flow.json @@ -0,0 +1,20 @@ +{ + "default_part": "ICE40UP5K-UWG30", + "values": { + "top": "top" + }, + "dependencies": { + "sources": [ + "spectrum.v" + ], + "yosys_synth_log": "synth.log", + "nextpnr_pnr_log": "nextpnr.log" + }, + "ICE40UP5K-UWG30": { + "default_target": "bitstream", + "dependencies": { + "build_dir": "build/fomu", + "pcf": "fomu.pcf" + } + } +} diff --git a/ice40/spectrum/fomu.pcf b/ice40/spectrum/fomu.pcf new file mode 100644 index 00000000..1160da81 --- /dev/null +++ b/ice40/spectrum/fomu.pcf @@ -0,0 +1,4 @@ +set_io led[0] C5 +set_io led[1] B5 +set_io led[2] A5 +set_io clk F4 diff --git a/ice40/spectrum/spectrum.v b/ice40/spectrum/spectrum.v new file mode 100644 index 00000000..37e6e621 --- /dev/null +++ b/ice40/spectrum/spectrum.v @@ -0,0 +1,114 @@ +/* Spectrum + * + * This example consists of a series of triangle wave generator with their phases shifted + * driving a multichannel PWM generator. The output is supposed to be used to drive LEDs, + * which will create a spectrum-like effect. + */ + +module Counter ( + input wire clk, + output wire [(RESOLUTION-1):0] out +); + parameter RESOLUTION = 4; + parameter PHASE = 0; + parameter CEILING = (2**RESOLUTION)-1; + + reg [(RESOLUTION-1):0] counter = PHASE; + + always @(posedge clk) begin + counter <= (counter == CEILING - 1) ? 0 : (counter + 1); + end + + assign out = counter; +endmodule + +module PWMController ( + input wire clk, + input wire [(CHANNELS*RESOLUTION-1):0] fill, + output wire [(CHANNELS-1):0] out +); + parameter RESOLUTION = 4; + parameter CHANNELS = 1; + + reg [(RESOLUTION-1):0] counter = 0; + + always @(posedge clk) begin + counter <= counter + 1; + end + + genvar i; + generate + for (i = 0; i < CHANNELS; i++) begin + assign out[i] = counter < fill[((i+1)*RESOLUTION-1):(i*RESOLUTION)]; + end + endgenerate +endmodule + +module TriGen ( + input wire clk, + input wire [(RESOLUTION):0] ceiling, + output wire [(RESOLUTION-1):0] out +); + parameter RESOLUTION = 4; + parameter PHASE = 0; + parameter CEILING = 2**RESOLUTION; + + wire [RESOLUTION:0] counter_out; + + Counter #( + .RESOLUTION (RESOLUTION+1), + .PHASE (PHASE) + ) counter ( + .clk (clk), + .out (counter_out) + ); + + wire [RESOLUTION:0] out_wide; + + assign out_wide = counter_out >= CEILING + ? ((~counter_out)+1) + : counter_out; + + assign out = out_wide[RESOLUTION:1]; +endmodule + +module top ( + input clk, + output [(BITS-1):0] led +); + + localparam BITS = 3; + localparam LOG2DELAY = 18; + + wire [(BITS-1):0] ledctl; + wire [(BITS*8-1):0] ledfills; + + genvar i; + generate + for (i = 0; i < BITS; i++) begin + + wire [8+LOG2DELAY-1:0] trigen_out; + + TriGen #( + .RESOLUTION (8+LOG2DELAY), + .PHASE (i*((2**8)/BITS)*(2**LOG2DELAY)) + ) trigen ( + .clk (clk), + .out (trigen_out) + ); + + assign ledfills[((i+1)*8-1):(i*8)] = trigen_out >> LOG2DELAY; + end + endgenerate + + PWMController #( + .RESOLUTION (8), + .CHANNELS (BITS) + ) pwm ( + .clk (clk), + .fill (ledfills), + .out (ledctl) + ); + + assign led = ~ledctl; +endmodule From d6906532216a123518529c37ee5bd081d593d9ec Mon Sep 17 00:00:00 2001 From: Unai Martinez-Corral Date: Mon, 1 Aug 2022 23:22:54 +0200 Subject: [PATCH 4/6] ice40/spectrum: add README.rst Signed-off-by: Unai Martinez-Corral --- ice40/spectrum/README.rst | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 ice40/spectrum/README.rst diff --git a/ice40/spectrum/README.rst b/ice40/spectrum/README.rst new file mode 100644 index 00000000..d3ea4dc7 --- /dev/null +++ b/ice40/spectrum/README.rst @@ -0,0 +1,7 @@ +Spectrum +~~~~~~~~ + +.. code-block:: bash + :name: ice40-spectrum + + make -C spectrum From 4b6f4755903dd42cdbd9ebb2a1fa85b893b10f8e Mon Sep 17 00:00:00 2001 From: Unai Martinez-Corral Date: Tue, 2 Aug 2022 00:19:15 +0200 Subject: [PATCH 5/6] ice40/spectrum: add Makefile Signed-off-by: Unai Martinez-Corral --- ice40/spectrum/Makefile | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 ice40/spectrum/Makefile diff --git a/ice40/spectrum/Makefile b/ice40/spectrum/Makefile new file mode 100644 index 00000000..182aff3a --- /dev/null +++ b/ice40/spectrum/Makefile @@ -0,0 +1,2 @@ +all: + f4pga -vvv build --flow ./flow.json From f983a7ba025b10ea1ee7fd4d7ca945687a63103d Mon Sep 17 00:00:00 2001 From: Unai Martinez-Corral Date: Mon, 1 Aug 2022 15:43:27 +0200 Subject: [PATCH 6/6] ci: test ice40/spectrum Signed-off-by: Unai Martinez-Corral --- .github/scripts/build-examples.sh | 8 ++++++++ .github/scripts/generate_job_matrices.py | 10 ++++++++++ docs/building-examples.rst | 23 +++++++++++++++++++++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/.github/scripts/build-examples.sh b/.github/scripts/build-examples.sh index 5e84a2c8..eea38111 100755 --- a/.github/scripts/build-examples.sh +++ b/.github/scripts/build-examples.sh @@ -91,6 +91,14 @@ case "$fpga_family" in esac done ;; + ice40) for example in $examples; do + case $example in + "spectrum") tuttest_exec ${snippets} ice40/spectrum/README.rst:ice40-spectrum ;; + *) echo "ERROR: Unknown example name: $example" >&2 + exit 1 ;; + esac + done + ;; *) echo "ERROR: Unknown fpga_family: $fpga_family" >&2 exit 1 ;; diff --git a/.github/scripts/generate_job_matrices.py b/.github/scripts/generate_job_matrices.py index 18436d0d..68418d9a 100755 --- a/.github/scripts/generate_job_matrices.py +++ b/.github/scripts/generate_job_matrices.py @@ -105,6 +105,16 @@ def get_jobs( 'surelog': "-parse -DSYNTHESIS" if usesSurelog else "" } for osver in osvers]) + jobs.extend([{ + 'name': "Surelog" if usesSurelog else "Default", + 'runs-on': runs_on, + 'fpga-fam': "ice40", + 'os': osver[0], + 'os-version': osver[1], + 'example': "spectrum", + 'surelog': "-parse -DSYNTHESIS" if usesSurelog else "" + } for osver in osvers]) + return jobs for distribution in ['debian', 'ubuntu', 'fedora', 'centos']: diff --git a/docs/building-examples.rst b/docs/building-examples.rst index c15734d5..de24b49e 100644 --- a/docs/building-examples.rst +++ b/docs/building-examples.rst @@ -20,14 +20,21 @@ Select your FPGA family: .. code-block:: bash :name: fpga-fam-xc7 - FPGA_FAM="xc7" + export FPGA_FAM=xc7 .. group-tab:: EOS S3 .. code-block:: bash :name: fpga-fam-eos-s3 - FPGA_FAM="eos-s3" + export FPGA_FAM=eos-s3 + + .. group-tab:: ICE40 + + .. code-block:: bash + :name: fpga-fam-ice40 + + export FPGA_FAM=ice40 Next, prepare the environment: @@ -104,3 +111,15 @@ Enter the directory that contains examples for QuickLogic EOS S3: .. jinja:: eos-s3_btn_counter :file: templates/example.jinja + + +Lattice ICE40 +============= + +.. code-block:: bash + :name: enter-dir-ice40 + + cd ice40 + +.. jinja:: ice40-spectrum + :file: templates/example.jinja