Fpga
-
Upload
pramodece -
Category
Technology
-
view
481 -
download
0
Transcript of Fpga
Can you build the Nand2Tetris CPU on real h/w without having towire up hundreds of gates on prototyping boards?
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" whichwill con�gure the FPGA.
Pramode C.E FPGA hacking with Free Software Tools
The IceStorm Project
Home Page: cli�ord.at/icestorm
Target: Lattice Semiconductor's ICE40 FPGA's
Main Tools: yosys (synthesis), arachne-pnr (place androute),icepack(�le format conversion),iceprog(deviceprogramming)
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 forLED1,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 verilogsource 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" connectorof 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, 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
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
Some other languages/frameworks available for hardwaredescription
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
Check out icoboard.org for more exciting news!
Pramode C.E FPGA hacking with Free Software Tools