FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

LiteXによるSoC環境構築を試行する (10. VexRiscVでの波形取得)

https://raw.githubusercontent.com/enjoy-digital/litex/master/doc/litex.png

LiteXでの自作CPUの動作検証について、まだ正しくシミュレーションを開始できるところまでは至っていない。

その代わり、LiteXの環境でVexRiscVの波形を取得するところまでは動くようになった。

コマンドラインとしては以下のようになる。

./sim.py --trace --trace-fst --trace-start 0 --trace-end 1000000000000

このコマンドにより、FSTファイルが出力され、波形を観測できるようになる。

--trace-endを挿入しているのは、Ctrl-Cでプログラムを止めてしまうとFSTファイルが中途半端になり、正しくGTKWaveで取得できなくなるためだ。 したがって、実行C++ファイルを以下のように変更して、必ずFSTファイルをCloseするようにする。

diff --git a/litex/build/sim/core/veril.cpp b/litex/build/sim/core/veril.cpp
index 2ea9a348..7680cdfc 100644
--- a/litex/build/sim/core/veril.cpp
+++ b/litex/build/sim/core/veril.cpp
@@ -74,6 +74,9 @@ extern "C" void litex_sim_tracer_dump()
   if (dump_enabled && tfp_start <= main_time && main_time <= tfp_end) {
     tfp->dump((vluint64_t) main_time);
   }
+  if (dump_enabled && main_time > tfp_end) {
+    tfp->close();
+  }
 }