本工具链搭建环境基于虚拟机Ubuntu 18.04
更换更新下载源
Ubuntu 12.04 (LTS)代号为precise。
Ubuntu 14.04 (LTS)代号为trusty。
Ubuntu 15.04 代号为vivid。
Ubuntu 15.10 代号为wily。
Ubuntu 16.04 (LTS)代号为xenial。
1、首先备份Ubuntu系统的官方源文件
打开Ubuntu的命令终端,进入源文件 sources.list 所在的目录:
2、然后执行备份命令,执行 sudo cp sources.list sources.list.backup 对源文件内容进行备份,以防万一。
cd /etc/apt
sudo cp sources.list sources.list.backup
修改源文件内容
1、阿里源文件内容如下:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
值得注意的是 sources.list 文件的条目都是有格式的(通过上面的内容大家也看的出来),一般有如下形式:
deb http://site.example.com/debian distribution component1 component2 component3
deb-src http://site.example.com/debian distribution component1 component2 component3
所以后面几个参数是对软件包的分类(Ubuntu下是main, restricted,universe ,multiverse这四个)
所以把内容写成:
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed universe multiverse
2、让更新源生效:
sudo apt-get update
效果如图:
安装依赖环境
在网站(http://www.clifford.at/icestorm/)查看开源工具所依赖的环境,命令如下:
sudo apt-get install build-essential clang bison flex libreadline-dev \
gawk tcl-dev libffi-dev git mercurial graphviz \
xdot pkg-config python python3 libftdi-dev \
qt5-default python3-dev libboost-all-dev cmake libeigen3-dev
上面的命令基本都是常用的软件。
安装软件
在官网(http://www.clifford.at/icestorm/)查看安装步骤
Installing the IceStorm Tools (icepack, icebox, iceprog, icetime, chip databases):
git clone https://github.com/cliffordwolf/icestorm.git icestorm
cd icestorm
make -j$(nproc)
sudo make install
Installing Arachne-PNR (place&route tool, predecessor to NextPNR):
git clone https://github.com/cseed/arachne-pnr.git arachne-pnr
cd arachne-pnr
make -j$(nproc)
sudo make install
Installing NextPNR (place&route tool, Arachne-PNR replacement):
git clone https://github.com/YosysHQ/nextpnr nextpnr
cd nextpnr
cmake -DARCH=ice40 -DCMAKE_INSTALL_PREFIX=/usr/local .
make -j$(nproc)
sudo make install
Installing Yosys (Verilog synthesis):
git clone https://github.com/cliffordwolf/yosys.git yosys
cd yosys
make -j$(nproc)
sudo make install
这个过程虽然不难,但是对于不习惯用Liunx系统的人来说还是很困难的,我也花费了很长时间去搭建环境,所以对于不会搭建的人,可以直接使用搭建好的虚拟机,但是后续的开发就要大家一起努力了。
公众号:OpenFPGA
后台回复:虚拟机
就能得到最新链接
流水灯示例
使用开源工具链和其他EDA软件没有太大区别,下面说下我使用过程的步骤:
1、使用文本编译器编辑编辑Verilog文件,本人习惯用Sublime,如下:
`default_nettype none
//***************************************//
//# @Author: 碎碎思
//# @Date: 2019-04-14 19:54:50
//# @Last Modified by: zlk
//# @Last Modified time: 2019-04-14 21:36:06
//****************************************//
module Run_LED
(
input CLK,
input RST_n,
output LED0,
output LED1,
output LED2,
output LED3,
output LED4,
output LED5,
output LED6,
output LED7
);
////////////////////////////////////////////
reg [7:0]LED;
////////////////////////////////////////////
//
//首先定义一个时间计数寄存器counter,每当达到预定的100ms时,
//计数寄存器就清零,否则的话寄存器就加1。
//然后计算计数器计数的最大值。时钟频率为12MHZ,
//也就是周期为1/12M 为83ns,要计数的最大值为T100MS= 100ms/83ns-1 = 120_4818。
//
reg[24:0] counter;
parameter T100MS = 25'd120_4818;
always @ (posedge CLK or negedge RST_n)
if(!RST_n) //高电平复位
counter<=25'd0;< span="">
else if(counter==T100MS)
counter<=25'd0;< span="">
else
counter<=counter+1'b1;< span="">
////////////////////////////////////////////
always @ (posedge CLK or negedge RST_n)
if(!RST_n)
LED<=8'b1111_1111; //初值,最低位led[0]灯亮
else if(counter==T100MS)
begin
if(LED==8'b0000_0000) //当溢出最高位时
LED<=8'b1111_1111; //回到复位时的状态
else
LED<=led<<1; //循环左移一位
end
assign {LED0,LED1,LED2,LED3,LED4,LED5,LED6,LED7}=LED;
endmodule // Run_LED
2、编辑引脚约束文件.pcf文件
# 12 MHz clock
set_io -nowarn CLK 35
# RESET Button
set_io -nowarn RST_n 43
# RS232
set_io -nowarn RX 6
set_io -nowarn TX 9
# RGB LED Driver
set_io -nowarn LED_RED_N 39
set_io -nowarn LED_GRN_N 40
set_io -nowarn LED_BLU_N 41
# SPI Flash
set_io -nowarn FLASH_SCK 15
set_io -nowarn FLASH_SSB 16
set_io -nowarn FLASH_IO0 14
set_io -nowarn FLASH_IO1 17
set_io -nowarn FLASH_IO2 12
set_io -nowarn FLASH_IO3 13
# PMOD 1A
set_io -nowarn P1A1 4
set_io -nowarn P1A2 2
set_io -nowarn P1A3 47
set_io -nowarn P1A4 45
set_io -nowarn P1A7 3
set_io -nowarn P1A8 48
set_io -nowarn P1A9 46
set_io -nowarn P1A10 44
# PMOD 1B
set_io -nowarn P1B1 43
set_io -nowarn P1B2 38
set_io -nowarn P1B3 34
set_io -nowarn P1B4 31
set_io -nowarn P1B7 42
set_io -nowarn P1B8 36
set_io -nowarn P1B9 32
set_io -nowarn P1B10 28
# PMOD 2
set_io -nowarn P2_1 27
set_io -nowarn P2_2 25
set_io -nowarn P2_3 21
set_io -nowarn P2_4 19
set_io -nowarn P2_7 26
set_io -nowarn P2_8 23
set_io -nowarn P2_9 20
set_io -nowarn P2_10 18
# LEDs and Buttons (PMOD swich&led)-->PMOD1A
set_io -nowarn LED0 4
set_io -nowarn LED1 3
set_io -nowarn LED2 2
set_io -nowarn LED3 48
set_io -nowarn LED4 47
set_io -nowarn LED5 46
set_io -nowarn LED6 45
set_io -nowarn LED7 44
# LEDs and Buttons (PMOD swich&led)-->PMOD1A
set_io -nowarn BTN0 4
set_io -nowarn BTN1 3
set_io -nowarn BTN2 2
set_io -nowarn BTN3 48
set_io -nowarn BTN4 47
set_io -nowarn BTN5 46
set_io -nowarn BTN6 45
set_io -nowarn BTN7 44
3、生成bit文件
通过http://www.clifford.at/icestorm/可知,产生可执行文件只需要下面三个命令即可:
yosys -p 'synth_ice40 -top Run_LED -blif run_led.blif' Run_LED.v
arachne-pnr -d 5k -o run_led.asc -p openice.pcf run_led.blif
icepack run_led.asc run_led.bin
第一个命令中 –top 后参数是顶层文件的module名 –blif 后参数是产生blif文件名,“”后的文件是Verilog文件,其中有多个文件,只需要在后面继续添加即可;
第二个命令时利用pcf和.blif文件生成.asc文件;
最后一个命令就是生成.bin文件。
简单描述就是综合(yosys),布线(arachne-pnr & nextpnr), 打包烧录(icestorm)
如果这时候修改了一个文件.v 或者 .pcf文件那么还是需要重新输入上面三句命令,这样还是很麻烦,下面给出两个解决办法:
1、脚本
新建一个脚本autorun.sh
输出上面三句命令
每次修改只需要执行./autorun.sh即可
2、Makefile
新建Makefile文件
输入下面命令
filename = Run_LED
pcf_file = openice.pcf
ICELINK_DIR=$(shell df | grep iCELink | awk '{print $$6}')
${warning iCELink path: $(ICELINK_DIR)}
build:
yosys -p "synth_ice40 -blif $(filename).blif" $(filename).v
arachne-pnr -d 5k -P sg48 -p $(pcf_file) $(filename).blif -o $(filename).asc
icepack $(filename).asc $(filename).bin
clean:
rm -rf $(filename).blif $(filename).asc $(filename).bin
3、命令行输入make ,即可产生相应的文件
两种方式对比:
Makefile对于大型项目管理非常nice,但是对于新手还需要一段时间进行学习和适应;
脚本方式就是简单,但是对于大型项目,比如很多.v文件,管理起来就比较捉襟。
4、下载文件到FPGA
将上面.bin文件 通过iceprog run_led.bin命令就可以直接下载到目标器件里运行。
对于iverilog仿真器的应用,下一次再更新吧。
也可以先参考这篇文章《一文学会使用全球第四大数字芯片仿真器iverilog!》。
谢谢大家支持。