TinyFPGA BX で RISC-V を動かしてみる(nextpnr 編)

投稿者: | 2019年12月16日

Now using nextpnr instead of Arachne-pnr.

さて、一つ目の宿題をやってみます。前回は placing and routing に Arachne-pnr を使いましたが、今回は nextpnr を試してみます。

nextpnr は、こちらからダウンロードしてインストールしました。バージョンはコミット dd7f7a5 です。

Makefile を書き換える

まず、TinyFPGA-BX/examples/picosoc のオリジナル Makefile に次のような修正を加えます。

diff --git a/examples/picosoc/Makefile b/examples/picosoc/Makefile
index d174349..d6f1d61 100644
--- a/examples/picosoc/Makefile
+++ b/examples/picosoc/Makefile
@@ -1,30 +1,30 @@
 
+CC=riscv64-unknown-elf-gcc
+OBJCOPY=riscv64-unknown-elf-objcopy
+
 upload: hardware.bin firmware.bin
    tinyprog -p hardware.bin -u firmware.bin
 
 
-hardware.blif: hardware.v spimemio.v simpleuart.v picosoc.v picorv32.v
-   yosys -ql hardware.log -p 'synth_ice40 -top hardware -blif hardware.blif' $^
+hardware.json: hardware.v spimemio.v simpleuart.v picosoc.v picorv32.v
+   yosys -ql hardware.log -p 'synth_ice40 -top hardware -json hardware.json' $^
 
-hardware.asc: hardware.pcf hardware.blif
-   arachne-pnr -d 8k -P cm81 -o hardware.asc -p hardware.pcf hardware.blif
+hardware.asc: hardware.pcf hardware.json
+   nextpnr-ice40 --lp8k --package cm81 --asc hardware.asc --pcf hardware.pcf --json hardware.json
 
 hardware.bin: hardware.asc
-   icetime -d hx8k -c 12 -mtr hardware.rpt hardware.asc
+   icetime -d lp8k -c 12 -mtr hardware.rpt hardware.asc
    icepack hardware.asc hardware.bin
 
 
 firmware.elf: sections.lds start.S firmware.c
-   riscv32-unknown-elf-gcc -march=rv32imc -nostartfiles -Wl,-Bstatic,-T,sections.lds,--strip-debug,-Map=firmware.map,--cref  -ffreestanding -nostdlib -o firmware.elf start.S firmware.c
+   $(CC) -march=rv32imc -mabi=ilp32 -nostartfiles -Wl,-Bstatic,-T,sections.lds,--strip-debug,-Map=firmware.map,--cref  -ffreestanding -nostdlib -o firmware.elf start.S firmware.c
 
 firmware.bin: firmware.elf
-   riscv32-unknown-elf-objcopy -O binary firmware.elf /dev/stdout > firmware.bin
+   $(OBJCOPY) -O binary firmware.elf /dev/stdout > firmware.bin
 
 
 clean:
    rm -f firmware.elf firmware.hex firmware.bin firmware.o firmware.map \
-         hardware.blif hardware.log hardware.asc hardware.rpt hardware.bin
+         hardware.blif hardware.log hardware.asc hardware.rpt hardware.bin \
+         hardware.json

修正点は、

  • Yosys の出力形式を BLIF から JSON に変更(nextpnr は BLIF に対応していない?)
  • Arachne-pnr に代えて nextpnr を使う(オプションは上述の通り)
  • ついでに icetime のオプションを直しておいた(hx8k は間違い)

です。

Placing & Routing

やってみましょう。

make

まずは Device utilisation(utilization の間違い?)です。

Info: Device utilisation:
Info:            ICESTORM_LC:  5500/ 7680    71%
Info:           ICESTORM_RAM:    20/   32    62%
Info:                  SB_IO:    13/  256     5%
Info:                  SB_GB:     8/    8   100%
Info:           ICESTORM_PLL:     0/    2     0%
Info:            SB_WARMBOOT:     0/    1     0%

LC の使用量が Arachne-pnr よりも若干少ないようです。

次に icetime による f_MAX の評価結果です。

icetime -m -dlp8k hardware.asc 
// Reading input .asc file..
// Reading 8k chipdb file..
// Creating timing netlist..
// Timing estimate: 45.24 ns (22.10 MHz)

おおっ。なんか f_MAX が上がっているようです。

TinyFPGA BX のフラッシュに書き込んでみましたが、nextpnr の出力もちゃんと動作することを確認できました。

最後にレイアウトビューです。Arachne-pnr とちょっと違うレイアウトですね!

今日はここまで。