Manjaro系统上配置Chisel开发环境
1. 安装依赖
sbt
sbt是scala的构建工具,大概相当于Java中的Maven。Arch系系统上可以一键安装
yay -S sbt
配置sbt国内镜像源:建立~/.sbt/repositories, 填写以下内容(按照这篇博客)
[repositories]
#本地源
local
#兼容 Ivy 路径布局
apache-ivy: https://repo1.maven.apache.org/maven2/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
#apache maven
apache-mvn: https://repo1.maven.apache.org/maven2/
#国内源,aliyun
aliyun: https://maven.aliyun.com/nexus/content/groups/public/
#添加国外源备用
typesafe: https://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
sonatype-oss-releases
maven-central
sonatype-oss-snapshots
Chisel
FIRRTL是Chisel到Verilog的中间语言,Verilator是仿真器,可以一键安装
yay -S chisel firrtl verilator
2. Chisel工程创建
vscode装Scala(Metals)插件,新建scala-helloworld工程
创建好的hello-world项目长这个样子
编辑build.sbt文件,加入以下内容以支持Chisel
addCompilerPlugin("edu.berkeley.cs" % "chisel3-plugin" % "3.5.4" cross CrossVersion.full)
libraryDependencies += "edu.berkeley.cs" %% "chisel3" % "3.5.4"
// We also recommend using chiseltest for writing unit tests
libraryDependencies += "edu.berkeley.cs" %% "chiseltest" % "0.5.4" % "test"
这段代码摘自Chisel3官方示例. 建议总是跟进官方示例,从而可以用最新版本。Maven Repository上也可以看到最新版本。
3. Hello Chisel
基本参照Chisel中文社区上翻译的Bootcamp教程来做,在src/main/scala/Main.scala中写以下代码
import chisel3._
import chisel3.util._
import chisel3.stage.ChiselStage
class PathThrough(width: Int) extends Module {
val io = IO(new Bundle {
val in = Input(UInt(width.W))
val out = Output(UInt(width.W))
})
io.out := io.in
}
object Main extends App {
println("Hello, Chisel!")
val verilog_code = (new ChiselStage).emitVerilog(new PathThrough(4))
println(verilog_code)
}
这是一个位数可以通过参数定制的buffer。开一个终端,输入sbt进入环境,run一下自动编译运行,打印出verilog代码。
![在这里插入图片描述](https://img-blog.csdnimg.cn/9345804138d94daa992d7350e4494152.png#pic_center
踩坑记录
- Bootcamp里的getVerilog函数是他自己写的,这里用Chisel自己的emitVerilog方法替换;
- 有些博客上给出的Chisel版本号(比如3.2.0-SNAPSHOT这种)镜像源里没有,会导致sbt compile的时候报错到处都找不到这个库,在build.sbt里把版本号改成官网上最新的就好了;