完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
软件:
|
|
|
|
|
|
|
|
nmigen可以实现基于python的FPGA数字系统设计/验证, 但需要借助专用的工具完成Fhdl到硬件的实现。
nmigen支持基于quartus作为后端实现的工具,我们可以利用WSL平台执行windows程序的功能, 将windows下的quartus与WSL下的nmigen配合,完成FPGA系统的设计,验证,综合,映射,以及最终部署 到DE0_NANO开发板上运行。 nmigen支持quartus工具链,在WSL系统下,我们需要首先设置下运行环境,以便nmigen能够正确的找到WIN10 下的工具。需要设置的环境变量如下,可添加到.bashrc中: QTS_HOME=/mnt/d/intelFPGA/18.1/quartus PATH=$PATH:$QTS_HOME/bin64 export PATH LD_LIBRARY_PATH=$QTS_HOME/linux64 export LD_LIBRARY_PATH export QUARTUS_PG export QUARTUS_MA export QUARTUS_FI export QUARTUS_CP export QUARTUS_ST export QUARTUS_AS alias quartus_pg alias quartus_ma alias quartus_fi alias quartus_cpf="quartus_cpf.exe" alias quartus_stalias quartus_as |
|
|
|
安装nmigen-soc/nmigen-stdio/nmigen-boards
(注:用下面的方法不用单独安装nmigen, pip会自动根据依赖关系安装nmigen) sudo pip3 install git+https://github.com/nmigen/nmigen-soc sudo pip3 install git+https://github.com/nmigen/nmigen-stdio sudo pip3 install git+https://github.com/nmigen/nmigen-boards nmigen默认使用yosys作为综合工具,而不是直接使用quartus,所以需要安装yosys, 安装yosys可以直接从github源下载安装, 也可以直接安装编译好的源: #ubuntu 18.04/20.02可以直接apt安装: sudo apt install yosys nmigen-boards里面没有支持DE0_Nano, 我们可以通过复制一个相似的平台创建一个, 比如de0_cv.py 创建一个项目目录, 复制/nmigen-boards/下的de0_cv.py,改名de0_nano.py 按照DE0_Nano的资源,更新如下: #!/usr/bin/env python3 # DE0_Nano support file import os import subprocess from nmigen.build import * from nmigen.vendor.intel import * from nmigen_boards.resources import * __all__ = ["DE0NanoPlatform"] class DE0NanoPlatform(IntelPlatform): device = "EP4CE22" # package = "F17" # FBGA-484 speed = "C6" default_clk = "clk50" resources = [ Resource("clk50", 0, Pins("R8", di), Clock(50e6), Attrs(io_standar)), Resource("epcs", 0, Subsignal("data0", Pins("H2", di)), Subsignal("dclk", Pins("H1", di)), Subsignal("ncs0", Pins("D2", di)), Subsignal("asd0", Pins("C1", di)), Attrs(io_standar) ), Resource("i2c", 0, Subsignal("sclk", Pins("F2", di)), Subsignal("sdat", Pins("F1", di)), Attrs(io_standar) ), Resource("g_sensor", 0, Subsignal("cs_n", Pins("G5", di)), Subsignal("int", Pins("M2", di)), Attrs(io_standar) ), Resource("adc", 0, Subsignal("cs_n", Pins("A10", di)), Subsignal("saddr", Pins("B10", di)), Subsignal("sclk", Pins("B14", di)), Subsignal("sdat", Pins("A9", di)), Attrs(io_standar) ), *LEDResources( pin, invert=True, attrs=Attrs(io_standar)), *ButtonResources( pin, invert=True, attrs=Attrs(io_standar)), *SwitchResources( pin, attrs=Attrs(io_standar)), UARTResource(0, # uart r, t, attrs=Attrs(io_standar)), *SDCardResources(0, cl, cm, dat, dat, dat, dat, w, attrs=Attrs(io_standar)), SDRAMResource(0, cl, ck, c, w, ra, ca, b, , d, dq, attrs=Attrs(io_standar)), ] connectors = [ Connector("j", 1, "A8 D3 B8 C3 A2 A3 B3 B4 A4 B5 " "- - A5 D5 B6 A6 B7 D6 A7 C6 " "C8 E6 E7 D8 E8 F8 F9 E9 - - " "C9 D9 E11 E10 C11 B11 A12 D11 D12 B12 "), Connector("j", 2, "T9 F13 R9 T15 T14 T13 R13 T12 R12 T11 " "- - T10 R11 P11 R10 N12 P9 N9 N11" "L16 K16 R16 L15 P15 P16 R14 N16 - - " "N15 P14 L14 N14 M10 L13 J16 K15 J13 J14 "), Connector("j", 3, "- E15 E16 M16 A14 B16 C14 C16 C15 " "D16 D15 D14 F15 F16 F14 G16 G15 - " "- - - - - - - - "), ] def toolchAIn_program(self, products, name): quartus_pgm = os.environ.get("QUARTUS_PGM", "quartus_pgm") with products.extract("{}.sof".format(name)) as bitstream_filename: subprocess.check_call([quartus_pgm, "--haltcc", "--mode", "JTAG", "--operation", "P;" + bitstream_filename]) |
|
|
|
一个blinker.py例程测试下:
#!/usr/bin/env python3 from nmigen import * from de0_nano import DE0NanoPlatform class Blinker(Elaboratable): def __init__(self, max_prd): self.max_prd = max_prd def elaborate(self, platform): led = platform.request("led", 0); m = Module() counter = Signal(range(self.max_prd + 1)) period = Signal(range(self.max_prd + 1)) # load/init period value m.d.comb += period.eq(self.max_prd) with m.If(counter == 0): m.d.sync += [ led.eq(~led), counter.eq(period) ] with m.Else(): m.d.sync += [ counter.eq(counter - 1) ] return m if __name__ == "__main__": plat = DE0NanoPlatform() plat.build(Blinker(40000000), do_program=True) 将DE0_Nano连上电脑, 运行 > ./Blinker.py 完成项目的编译,综合,映射,下载运行.... |
|
|
|
只有小组成员才能发言,加入小组>>
795 浏览 0 评论
1154 浏览 1 评论
2530 浏览 5 评论
2863 浏览 9 评论
移植了freeRTOS到STMf103之后显示没有定义的原因?
2713 浏览 6 评论
keil5中manage run-time environment怎么是灰色,不可以操作吗?
1075浏览 3评论
195浏览 2评论
459浏览 2评论
370浏览 2评论
M0518 PWM的电压输出只有2V左右,没有3.3V是怎么回事?
455浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 12:48 , Processed in 0.984178 second(s), Total 56, Slave 47 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号