本文旨在介绍和学习如何使用Amaranth语言进行FPGA设计。Amaranth语言是基于Python库实现,并且可以被编译转换为Verilog语言,从而运行在真实FPGA硬件上。
安装AmaranthHDL
Building FPGA Gateware with Verilog and nMigen: A Tutorial
下面是一个快速学习Amaranth语言的文章。
vivonomicon.com/2020/04...
github.com/kbob/nmigen-...
github.com/robertbaruch...
下面是一个基于Amaranth实现的RISCV软核,跟上面的文章来自同一个作者。
vivonomicon.com/2020/06...
通过nMigen实现的设计代码可以通过yosys转换为verilog。
Amaranth HDL toolchain 0.4.dev7 documentation
github.com/amaranth-lan...
github.com/amaranth-lan...
M-Labs快速的感受一下
先通过给的一个简单例子开始了解Amaranth是怎么回事。
Getting started - Amaranth HDL toolchain 0.4.dev29 documentation
定义一个计数器类
这里的例子是提供了一个Counter的实现。方便说明,这里直接贴代码。
上面的类就定义了一个简单的定时器,代码也很易于理解,也相当于构建了一个可以被重复使用的模块,有很强的复用性。下面看下如何验证它的功能。
测试定时器
执行后,我们可以看到在同目录下生成了up_counter.vcd文件,并可以通过gtkwave程序来查看vcd文件。如下图所示,可以看到各个信号在各个cycle的变化。
生成Verilog代码
完成了功能验证,就可以将定时器代码转换为Verilog代码。
生成的Verilog代码如下。可以看出代码结构比较清晰,并且每一行都注释了来源,很利于调试代码(不知道代码复杂之后会不会也是如此清晰)。
总结
基于上面的例子总体感受还是比较舒服,python实现也比较简单,既支持仿真验证功能,同时输出vcd时序文件,也能够将Python代码实现转换为Verilog文件。如果能做到足够成熟稳定,我想能够解决一个痛点,那就是快速原型搭建及验证,和最终代码实现之间的鸿沟。可靠度足够的情况,可以用于快速实现设计,并验证新的Idea。最后可直接将转换得到的Verilog代码用于工程实践。
“The Amaranth project provides an open-source toolchain for developing hardware based on synchronous digital logic using the Python programming language, as well as evaluation board definitions, a System on Chip toolkit, and more. It aims to be easy to learn and use, reduce or eliminate common coding mistakes, and simplify the design of complex hardware with reusable components. The Amaranth toolchain consists of the Amaranth hardware definition language, the standard library, the simulator, and the build system, covering all steps of a typical FPGA development workflow. At the same time, it does not restrict the designer’s choice of tools: existing industry-standard (System)Verilog or VHDL code can be integrated into an Amaranth-based design flow, or, conversely, Amaranth code can be integrated into an existing Verilog-based design flow.”
温馨提示:答案为网友推荐,仅供参考