【SpinalHDL】1. Getting Started

1. Getting Started

1.1 SpinalHDL开发环境的搭建

开发环境的搭建参考SpinalHDL 开发环境搭建一步到位(图文版) - 极术社区 - 连接开发者与智能计算生态就可以了,so detail.

重点在于sbt切换为国内源,可以参考如下链接Windows上安装java8、scala2.11.12、sbt1.3.12和IntelliJ IDEA的SpinalHDL环境并跑通VexRiscv_45coding的博客-CSDN博客_scala 2.11.12 idea
Windows上安装java8、scala2.11.12、sbt1.3.12和IntelliJ IDEA的SpinalHDL环境并跑通VexRiscv_45coding的博客-CSDN博客_scala 2.11.12 idea

重点说明下sbt切换国内源的问题:
(1)sbt安装目录/conf目录下sbtconfig.txt修改如下:

-Dsbt.log.format=true
-Dfile.encoding=UTF8
-Dsbt.override.build.repos=true

(2)在C:\Users\用户名\.sbt目录下添加repositories文件,并添加如下内容:

[repositories]
   
   local
   huaweicloud-maven: https://repo.huaweicloud.com/repository/maven/
   maven-central: https://repo1.maven.org/maven2/
   sbt-releases-repo: https://repo.typesafe.com/typesafe/ivy-releases/,  [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
   sbt-plugin-repo: https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]

主要实现huaweicloud作为国内源。

1.2 SpinalHDL的工程结构(基于sbt)

(1) build.sbt文件

scala工程采用sbt工具构建工程时,必须包含build.sbt文件。在spinalhdl工程中,build.sbt文件中增加spinalhdl库文件路径等内容,其典型文件内容举例如下:

name := "SpinalTemplateSbt"
ThisBuild / version := "1.0" 
ThisBuild / scalaVersion := "2.11.12"

val spinalVersion = "1.8.0"
val spinalCore = "com.github.spinalhdl" %% "spinalhdl-core" % spinalVersion
val spinalLib = "com.github.spinalhdl" %% "spinalhdl-lib" % spinalVersion
val spinalIdslPlugin = compilerPlugin("com.github.spinalhdl" %% "spinalhdl-idsl-plugin" % spinalVersion)

lazy val SpinalTemplateSbt = (project in file("."))
  .settings(
    name := "SpinalTemplateSbt",
    libraryDependencies ++= Seq(spinalCore, spinalLib, spinalIdslPlugin)
  )

fork := true

其中verision为build.sbt的版本号,一般不需要修改;
scalaVersion为2.11.12,目前SpinalHDL只支持2.13.x、2.12.x和2.11.x的Scala版本,暂不支持Scala3,推荐使用Scala 2.11.12
spinalVersion为1.10.1,目前SpinalHDL的最新版本。
fork := true,这句话是为了实现仿真所增加的内容,不使用仿真时该语句可不添加。
其中spinalVersion可以设置为latest.release,保证每次使用都采用最新版本。


当然也可以不指定版本,每次都使用最近的SpinalHDL版本,build.sbt可以做如下的修改。

  
name := "SpinalDemo"  
  
version := "0.1.0"  
  
scalaVersion := "2.11.12"  
  
libraryDependencies ++= Seq(  
  "com.github.spinalhdl" % "spinalhdl-core_2.11" % "latest.release",  
  "com.github.spinalhdl" % "spinalhdl-lib_2.11" % "latest.release",  
  compilerPlugin("com.github.spinalhdl" % "spinalhdl-idsl-plugin_2.11" % "latest.release")  
)  
  
fork := true
(2) SpinalHDL文件的工程结构

以一个简单的例子做说明吧。

// import spinalhdl core library  
import spinal.core._  
  
// Component = module in verilog  
class Demo01 extends Component {  
  val a = Reg(UInt(8 bits))  
}  
  
object Demo01 {  
  def main (args: Array[String]): Unit = {  
    SpinalVerilog(new Demo01)  
    SpinalConfig(genVhdlPkg = false).generateVhdl(new Demo01)  
  }  
}

上述例子中实现一个位宽为8 bit的寄存器的声明。
其中

import spinal.core._

导入SpinalHDL的核心库;
继承自Component组件的module_xxx类定义了一个类似verilog中module的模块,内部为module的具体的实现,这里暂时不做具体的阐述;

// Component = module in verilog  
class module_xxx extends Component {  
  val a = Reg(UInt(8 bits))  
} 

最后object对象定义的main函数为scala语言的入口函数,SpinalVerilog语句实现了将Scala语句转换为Verilog语句的功能。

object module_xxx {  
  def main (args: Array[String]): Unit = {  
    SpinalVerilog(new module_xxx)  
  }  
}

这样就可以使用SpinalHDL进行愉快的玩耍了。

  • 5
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值