Differences between revisions 27 and 28
Revision 27 as of 2016-12-22 19:30:08
Size: 7608
Editor: ?PetterReinholdtsen
Comment: Fix typo.
Revision 28 as of 2016-12-25 14:12:03
Size: 7793
Comment:
Deletions are marked like this. Additions are marked like this.
Line 18: Line 18:
   * Lattice "[[http://www.latticesemi.com/icestick|iCEstick Evaluation Kit]]" (12 MHz clock) - supported by DebianPkg:fpga-icestorm, see [[attachment:iCEstick_Evaluation_Kit.jpg|image]]    * Lattice "[[http://www.latticesemi.com/icestick|iCEstick Evaluation Kit]]" (12 MHz clock) - cheapest (~25[$€]) and easiest to carry with you, supported by DebianPkg:fpga-icestorm, see [[attachment:iCEstick_Evaluation_Kit.jpg|image]]
Line 20: Line 20:
   * Nandland "[[https://www.nandland.com/goboard/introduction.html|GO Board]]" (25 MHz clock) - no notion of a support by this Free pipeline    * Nandland "[[https://www.nandland.com/goboard/introduction.html|GO Board]]" (25 MHz clock) - supported by DebianPkg:fpga-icestorm (have not tested it, someone please remove this comment)
Line 51: Line 51:
 * https://github.com/nesl/ice40_examples/ - mostly for the HX8K
 * https://github.com/Obijuan/open-fpga-verilog-tutorial/wiki - thorough tutorial, teaches Spanish and FPGA programming at the same time
 * https://github.com/FPGAwars/FPGA-peripherals/wiki - emergent
 * https://github.com/cyrozap/iCEstick-UART-Demo - very pleasant and usable bidirectional asynchronous UART implementation for allwong serial communication / data exchange with the host
 * https://github.com/CarlosGS/iceDAQ - fast I/O
 * Videos
   * https://www.youtube.com/c/Nandland
 * Code repositories
  
* https://github.com/nesl/ice40_examples/ - mostly for the HX8K
   * https://github.com/Obijuan/open-fpga-verilog-tutorial/wiki - thorough tutorial, teaches Spanish and FPGA programming at the same time
   * https://github.com/FPGAwars/FPGA-peripherals/wiki - emergent
   * https://github.com/cyrozap/iCEstick-UART-Demo - very pleasant and usable bidirectional asynchronous UART implementation for allwong serial communication / data exchange with the host
   * https://github.com/CarlosGS/iceDAQ - fast I/O

Tool chain for Lattice iCE40 FPGAs

Hardware to buy

There is now a complete Open Source tool chain for some FPGAs from Lattice Semiconductor. For a convincing video that these devices and the Open Source development tools are useful, see:

The pipeline employs the following tools:

  • yosys - for logic synthesis of Verilog code. The output is a netlist describing how all cells are connected together in BLIF format.

  • arachne-pnr - for placement and routing of the netlist. The output is a textual bitstream.

The final step, i.e. preparing the bitstream for the FPGA, and transferring it to the FPGA, uses:

  • fpga-icestorm - for the Lattice boards, using libusb/libftdi

  • litterbox - for the CAT-Board, a build-yourself FPGA Hat for the Raspberry Pi. This Python package is not yet packaged for Debian but likely will once we have a CAT-Board at our disposal. For the meantime, it is installed as easily as one types "pip install litterbox".

This pipeline of yosys, arachne-pnr and icestorm now supports two FPGAs, as presented below. Another overview is found on this icoboard page.

Programming

To get a Verilog code file called mydesign.v to "run" on an FPGA, the following commands are needed. Yosys needs a Verilog (.v) file as input (example shown below) and arachne-pnr also needs the Physical Constraints file (.pcf) file to link ports in the Verilog file with ports on the hardware:

   yosys -q -p "synth_ice40 -blif mydesign.blif" mydesign.v \
&& arachne-pnr -p mydesign.pcf mydesign.blif -o mydesign.txt \
&& icepack mydesign.txt mydesign.bin \
&& iceprog mydesign.bin

For the CAT-Board, instead of using iceprog use litterbox. This is nicely described on https://hackaday.io/project/7982-cat-board/log/37305-getting-to-blinky-cat-board-style .

The Debian packages of this Open Source tool chain were successfully tested with the iCEstick Evaluation Kit (iCE40HX1K) on Debian Linux, both on i686 bare metal and amd64 platforms, the latter virtualized with VirtualBox 5.1.2 on MacOS X.

Several Open Source environments have emerged to help supporting programmable hardware. Those are not specific to the Lattice products and summarised here. Users of those tools are cordially invited to help bringing them to Debian.

Open Source Examples for the Lattice iCE HX1K and HX8K

In principle, any Verilog code should just work that

  • is not too large for those FPGA of overseeable size
  • if that Verilog code is compatible with a few remnant constraint of Yosys

and such examples can be found throughout the net as indicated on the parental FPGA page. There are however device-specific hurdles, and for beginners, about everything is a hurdle, no matter what the device is. Please also look at

and there is

For a quick success follow the example below.

Example: Rotating LED Illumination

The Physical Constraints file (.pcf) describes the mapping between pin numbers and ports of the Verilog module. It consist of multiple lines of "set_io D1 99", where D1 in this case is an input or output of the Verilog module called "D1", and 99 is the pin number of the Lattice FPGA.

Example .pcf file (which works with HX1K):

set_io D1 99
set_io D2 98
set_io D3 97
set_io D4 96
set_io D5 95
set_io clk 21

For specifications of all the ports of the HX1K iCEstick boards and their mapping to the chip, see the user manual download able from http://www.latticesemi.com/en/Products/DevelopmentBoardsAndKits/iCEstick.aspx .

Verilog (.v) example

The file is borrowed from the arachne-pnr/examples directory. Per se it is independent from the FPGA. Yosys determines the chip type and it is only with the arachne-pnr that the association with the physical constraints file is manifested in the code so it is working on a particular soldering configuration since it is mostly arbitrary which ports are linked up with the LEDs.

   1 module top(input clk, output D1, output D2, output D3, output D4, output D5);
   2    
   3    reg ready = 0;
   4    reg [23:0]     divider;
   5    reg [3:0]      rot;
   6    
   7    always @(posedge clk) begin
   8       if (ready) 
   9     begin
  10        if (divider == 12000000) 
  11          begin
  12         divider <= 0;
  13     //  rot <= {rot[2:0],rot[3]}; // clockwise
  14         rot <= {rot[0],rot[3:1]}; // counter-clockwise
  15          end
  16        else 
  17          divider <= divider + 1;
  18     end 
  19       else 
  20     begin
  21        ready <= 1;
  22        rot <= 4'b0001;
  23        divider <= 0;
  24     end 
  25    end 
  26    
  27    assign D1 = rot[0];
  28    assign D2 = rot[1];
  29    assign D3 = rot[2];
  30    assign D4 = rot[3];
  31    assign D5 = 1;
  32 endmodule

The outputs are directed by the .pcf file to the LED lights. The rotation of that bit in 'rot' indeed turns the light counter clockwise. So, if you had a fabric new iCE stick that already shows a rotating light by default once it is provided with power, the device just changed the direction.