Fpga

pramode_ce 1,433 views 32 slides Mar 12, 2016
Slide 1
Slide 1 of 32
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32

About This Presentation

Program lattice semiconductor's FPGA's using 100% free software tools from the IceStorm Project.


Slide Content

FPGA hacking with Free Software Tools
Pramode C.E
http://pramode.net
March 12, 2016

What is this?
Pramode C.E FPGA hacking with Free Software Tools

From NAND to Tetris
Pramode C.E FPGA hacking with Free Software Tools

Can you build the Nand2Tetris CPU on real h/w without having to
wire up hundreds of gates on prototyping boards?
Pramode C.E FPGA hacking with Free Software Tools

Field Programmable Gate Arrays (FPGA's)
Pramode C.E FPGA hacking with Free Software Tools

How does an FPGA work?
Pramode C.E FPGA hacking with Free Software Tools

Programming an FPGA
Circuit is described using Verilog / VHDL
Simulated to ensure correct operation
Synthesized to a netlist
Place-and-route
Send the "bitstream" to the FPGA
Pramode C.E FPGA hacking with Free Software Tools

Programming an FPGA
Simulation can be done using purely free software tools
(example: iverilog)
Proprietary tools required for generating the "bitstream" which
will congure the FPGA.
Pramode C.E FPGA hacking with Free Software Tools

The IceStorm Project
Home Page: cliord.at/icestorm
Target: Lattice Semiconductor's ICE40 FPGA's
Main Tools: yosys (synthesis), arachne-pnr (place and
route),icepack(le format conversion),iceprog(device
programming)
Pramode C.E FPGA hacking with Free Software Tools

Hello, World!
A simple Verilog model:
module And2(input a, b, output c);
assign c = a & b;
endmodule
Pramode C.E FPGA hacking with Free Software Tools

A NAND Gate
module Nand2(output c, input a, b);
assign c = ~(a & b);
endmodule
Pramode C.E FPGA hacking with Free Software Tools

A NAND Gate - by combining modules
module Nand2(output c, input a, b);
wire f;
and G1(f, a, b);
not G2(c, f);
endmodule
Pramode C.E FPGA hacking with Free Software Tools

But where is the hardware??
The Lattice IceStick evaluation board
Pramode C.E FPGA hacking with Free Software Tools

LED On!
Put on LED1 on the IceStick board. A le with pin-mappings for
LED1,LED2 etc is needed for proper operation.
module Led(output LED1, LED2, LED3, LED4, LED5);
assign LED1 = 1;
assign LED2 = 0;
assign LED3 = 0;
assign LED4 = 0;
assign LED5 = 0;
endmodule
Pramode C.E FPGA hacking with Free Software Tools

LED On!
Here is the build script for the previous program(led.v is the verilog
source and led.pcf is the pin mapping):
yosys -p "synth_ice40 -blif led.blif" led.v
arachne-pnr -d 1k -p led.pcf led.blif -o led.asc
icepack led.asc led.bin
iceprog led.bin
Pramode C.E FPGA hacking with Free Software Tools

LED On!
And here is led.pcf:
set_io LED1 99 # red
set_io LED2 98 # red
set_io LED3 97 # red
set_io LED4 96 # red
set_io LED5 95 # green
Pramode C.E FPGA hacking with Free Software Tools

Concurrency and Hardware
y = (a or b) and (c or d) implemented on an FPGA:
Pramode C.E FPGA hacking with Free Software Tools

Concurrency and Hardware
y = (a or b) and (c or d) evaluated by a microprocessor(note:
output produced by gcc -S):
movl a, %edx
movl b, %eax
movl %edx, %ecx
orl %eax, %ecx
movl c, %edx
movl d, %eax
orl %edx, %eax
andl %ecx, %eax
Pramode C.E FPGA hacking with Free Software Tools

A NAND Gate - in real Hardware!
PMOD1 and PMOD2 are pins 1 and 2 on the "PMOD" connector
of the IceStick board.
module Nand2(input PMOD1, PMOD2,
output LED1,LED2,LED3,LED4,LED5);
// Nand gate o/p is on LED1 only
assign LED1 = ~(PMOD1 & PMOD2);
assign LED2 = 0;
assign LED3 = 0;
assign LED4 = 0;
assign LED5 = 0;
endmodule
Pramode C.E FPGA hacking with Free Software Tools

WhoAmI?
module WhoAmI(input PMOD1,PMOD2,PMOD3,
output LED1,LED2,LED3,LED4,LED5);
// only LED1 is significant
wire f1,f2,f3,f4;
assign f1 = (~PMOD1) & PMOD2 & (~PMOD3);
assign f2 = (~PMOD1) & PMOD2 & PMOD3;
assign f3 = PMOD1 & (~PMOD2) & PMOD3;
assign f4 = PMOD1 & PMOD2 & PMOD3;
assign LED1 = f1 | f2 | f3 | f4;
//assign LED2,3,4,5 to 0 ... lines not shown.
endmodule
Pramode C.E FPGA hacking with Free Software Tools

WhoAmI?
module WhoAmI(input PMOD1,PMOD2,PMOD3,
output LED1,LED2,LED3,LED4,LED5);
// only LED1 is significant
always @(*)
begin
if(PMOD1 == 0) LED1 = PMOD2;
else LED1 = PMOD3;
end
//assign LED2,3,4,5 to 0 ... lines not shown
endmodule
Pramode C.E FPGA hacking with Free Software Tools

WhoAmI? The Answer!!
Pramode C.E FPGA hacking with Free Software Tools

WhoAmI, again!
module WhoAmIAgain(input PMOD1,PMOD2,
output LED1,LED2,LED3,LED4,LED5);
always @(posedge PMOD1)
begin
LED1 <= PMOD2;
end
assign LED2 = 0;
assign LED3 = 0;
assign LED4 = 0;
assign LED5 = 0;
endmodule
Pramode C.E FPGA hacking with Free Software Tools

WhoAmIAgain? The Answer!!
Pramode C.E FPGA hacking with Free Software Tools

More demos!
Rotating LED's
Random bit generation using a Linear Feedback Shift Register
A UART transmitter
A full CPU running a FORTH system!
Pramode C.E FPGA hacking with Free Software Tools

Random bitstream using an LFSR
Pramode C.E FPGA hacking with Free Software Tools

A UART Transmitter
Pramode C.E FPGA hacking with Free Software Tools

Some other languages/frameworks available for hardware
description
MyHDL - uses Python
Chisel - uses Scala
Clash - uses Haskell
HardCaml - uses Ocaml
PSHDL - a beginner level tool which generates VHDL
IceStudio - Verilog code from block diagrams!
Pramode C.E FPGA hacking with Free Software Tools

The Future
The IcoBoard
Pramode C.E FPGA hacking with Free Software Tools

The Future
The IceZum
Pramode C.E FPGA hacking with Free Software Tools

The Future
Check out icoboard.org for more exciting news!
Pramode C.E FPGA hacking with Free Software Tools

Thank You! Questions welcome!
Pramode C.E FPGA hacking with Free Software Tools
Tags