【开箱】iCEsugar开发板开箱

【开箱】iCEsugar开发板开箱

panedioic
2021-07-27 / 0 评论 / 6 阅读 / 正在检测是否收录...

RT。看到了这个开发板,于是买了一个回来玩玩233.
7.22到货
下面上图
(现在还没有)

初体验

在项目的 Github 仓库有示例文件。这个开发板的上手非常简单,只需要把bin文件拖拽进去就行了。
示例文件有很多,包含了各种demo,基本上把我一块买的各种PMOD扩展版都用到了。不过我也并没有一一全下载到板子上进行验证,也就点了个灯。
接下来就自己写代码玩吧!

环境搭建

开发板到手了之后,当然就要着手开发环境的搭建啦。虽然官方有提供一个已经搭建好环境的虚拟机镜像,但镜像是在百度云上的,由于那可怜的下载速度,正好我现在有现成的 Linux 环境,因此决定自己手动搭建下开发环境。
不过有一点不同的是,教程中搭建的环境是Ubuntu系统的,而我的是Manjaro系统。所以在细节的搭建上会有所不同。
请参考icestorm
从官方 Github 仓库得知FPGA工具链安装:IceStorm

从网站可知,安装FPGA工具链需要以下步骤:

  1. Installing prerequisites
  2. Installing the IceStorm Tools (icepack, icebox, iceprog, icetime, chip databases)
  3. Installing Arachne-PNR (place&route tool, predecessor to NextPNR)
  4. Installing NextPNR (place&route tool, Arachne-PNR replacement)
  5. Installing Yosys (Verilog synthesis)
注,今天为了写文时查资料发现了:Notes for Archlinux: just install icestorm-git,
arachne-pnr-git and yosys-git from the Arch User Repository (no need
to follow the install instructions above). 所以似乎是我想复杂了。。

我们一条一条来看。首先是:

# Installing prerequisites (this command is for Ubuntu 14.04):
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

这部分的命令很好理解,就是安装一些依赖项。虽然 Manjaro 没有apt-get,但使用pacman一个个自己装也不麻烦。(我原本还打算先搞后面的,遇到需要前面的再去搞,结果遇到一堆麻烦。在前面先把这些装完后面就会轻松很多。)

安装了上面那些依赖项后,后面的安装步骤就很简单了。只需要直接把官网上的命令一条条输进去就行了:

# Installing the IceStorm Tools (icepack, icebox, iceprog, icetime, chip databases):
git clone https://github.com/YosysHQ/icestorm.git icestorm
cd icestorm
make -j$(nproc)
sudo make install
cd ../

# 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
cd ../

# 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
cd ../

# Installing Yosys (Verilog synthesis):
git clone https://github.com/YosysHQ/yosys.git yosys
cd yosys
make -j$(nproc)
sudo make install
cd ../

做到这里,开发环境基本就搭建完成了。这里我就简单写几个我搭建时遇到的问题以供参考吧。
1.

mpsse.c:26:10: 致命错误:ftdi.h:没有那个文件或目录
   26 | #include <ftdi.h>
      |          ^~~~~~~~
编译中断。
make[1]: *** [<内置>:mpsse.o] 错误 1
make[1]: 离开目录“/home/ame/oss/icestorm/iceprog”
make: *** [Makefile:10:iceprog.all] 错误 2
make: *** 正在等待未完成的任务....
g++ -MD -MP -O2  -Wall -std=c++11 -I/usr/local/include -DPREFIX='"/usr/local"' -DCHIPDB_SUBDIR='"icebox"'   -c -o timings-u4k.o timings-u4k.cc
g++ -o icetime  icetime.o iceutil.o timings-lp384.o timings-lp1k.o timings-lp8k.o timings-hx1k.o timings-hx8k.o timings-up5k.o timings-u4k.o -lm -lstdc++
make[1]: 离开目录“/home/ame/oss/icestorm/icetime”

这个问题纯粹就是我上面的依赖项没装好,直接 sudo pacman -s ftdi 就可以了。

2.

python3 icebox_chipdb.py -5 > chipdb-5k.new
g++: 致命错误:已杀死 signal terminated program cc1plus
编译中断。
make[1]: *** [<内置>:timings-up5k.o] 错误 1
make[1]: 离开目录“/home/ame/oss/icestorm/icetime”
make: *** [Makefile:10:icetime.all] 错误 2
make: *** 正在等待未完成的任务....
python3 icebox_chipdb.py -4 > chipdb-lm4k.new
mv chipdb-5k.new chipdb-5k.txt
python3 icebox_chipdb.py -u > chipdb-u4k.new
mv chipdb-lm4k.new chipdb-lm4k.txt
mv chipdb-u4k.new chipdb-u4k.txt
make[1]: 离开目录“/home/ame/oss/icestorm/icebox”

这个问题出现的原因是因为系统的内存不够。我的虚拟机是4G的内存,于是我又加了4G的swap,就不报错了。
步骤如下:

sudo dd if=/dev/zero of=/swapfile bs=64M count=32
#count的大小就是增加的swap空间的大小,64M是块大小,所以空间大小是bs*count=2048MB
sudo mkswap /swapfile
#把刚才空间格式化成swap格式
chmod 0600 /swapfile  
sudo swapon /swapfile
#使用刚才创建的swap空间

在执行结束后使用下面的命令来释放空间:

swapoff -a

Coding

之后就是准备变成啦。这里我写了个简单的流水灯,以供参考:

// flow_led.v
module flow_led(
    input       clk,
    input       [3:0] SW,
    output      P2_1,
    output      P2_2,
    output      P2_3,
    output      P2_4,
    output      P2_9,
    output      P2_10,
    output      P2_11,
    output      P2_12
);

assign rst_n = SW[0];

reg [7:0] led;

reg [23:0] cnt;

initial begin
   cnt = 0;
   led = 8'b1111_1110;
end

always @(posedge clk or negedge rst_n)
begin
    if(!rst_n)
        cnt <= 1'b0;
    else
        if(cnt < 24'd2400000)
            cnt <= cnt + 1'b1;
        else
            cnt <= 24'd0;
end

always @(posedge clk or negedge rst_n)
begin
    if(!rst_n)
        led <= 8'b1111_1110;
    else
        if(cnt == 24'd2400000)
            led <= {led[6:0],led[7]};
        else
            led <= led;
end

assign {P2_1,P2_2,P2_3,P2_4,P2_12,P2_11,P2_10,P2_9} = led;

endmodule

就是有个小bug还没修,在开始运行时灯不是从最左边开始亮的,而是从中间开始的。应该是引脚没标好的问题。
至于引脚相关的数据就可以在官方仓库里找到了。这里我直接copy了一份。

# io.pcf
# For the iCESugar Board (iCE40UP5K-QFN48)

set_io LED_G 41
set_io LED_R 40
set_io LED_B 39

set_io SW[0] 18
set_io SW[1] 19
set_io SW[2] 20
set_io SW[3] 21

set_io clk   35

set_io RX    4
set_io TX    6

set_io USB_DP       10
set_io USB_DN       9
set_io USB_PULLUP   11

# PMOD 1
set_io P1_1     10
set_io P1_2     6
set_io P1_3     3
set_io P1_4     48
set_io P1_9     47
set_io P1_10    2
set_io P1_11    4
set_io P1_12    9

# PMOD 2
set_io P2_1     46
set_io P2_2     44
set_io P2_3     42
set_io P2_4     37
set_io P2_9     36 
set_io P2_10    38
set_io P2_11    43
set_io P2_12    45

# PMOD 3
set_io P3_1     34 
set_io P3_2     31
set_io P3_3     27
set_io P3_4     25
set_io P3_9     23
set_io P3_10    26
set_io P3_11    28
set_io P3_12    32

# PMOD 4
set_io P4_1     21
set_io P4_2     20
set_io P4_3     19
set_io P4_4     18

#spi
set_io SPI_SS   16
set_io SPI_SCK  15
set_io SPI_MOSI 17
set_io SPI_MISO 14

生成 & 下载

保存好后可以用下面的命令生成bit文件:

yosys -p 'synth_ice40 -top flow_led -blif flow_led.blif' flow_led.v
arachne-pnr -d 5k -o flow_led.asc -p io.pcf flow_led.blif
icepack flow_led.asc flow_led.bin

当然,你也可以直接 copy 一份 demo 中的 Makefile 稍微改改后使用。

在生成好之后可以像之前一样使用拖拽的方式下载到开发板上,当然,也可以使用官方提供的工具进行操作。
在上面工具链中安装的 iceprog 并不是这一步我们需要用到的工具,而是在 Github仓库中下载到的 icesprog 工具。注意这里是多了一个 s 的,当初我被这个问题困扰了好久。。。
为了方便使用,这里我是直接做了个软链: sudo ln -s ./icesugar/tools/icesprog.x64.linux /bin/icesprog 以方便之后使用。
最后,把开发板连到电脑上,接入虚拟机,我们便可用 sudo icesprog flow_led.bin 进行下载了。不久之后,就可以看到流水灯效果了。

References

Project IceStorm
FPGA开源工具链

https://www.jianshu.com/p/c4ef42f6b2ec
https://blog.csdn.net/zhangyingna667/article/details/107290495/
https://blog.csdn.net/weixin_33670713/article/details/91889143
https://www.cnblogs.com/xakoy/p/9039218.html
https://blog.csdn.net/zhaoyue007101/article/details/8458078

0

评论 (0)

取消