[1]SpinalHDL教程——安装环境配置

[1]SpinalHDL安装环境

最好的教程是官方文档!不过推荐英文文档

英文版

中文版

一、安装java环境

SpinalHDL相当于是scala的一个包,而scala是运行在jvm上的。所以我们先安装jdk。

安装jdk(openjdk-19)略

二、安装Scala

百度搜索Scala,进入Scala官网(有兴趣可以看看get start文档,能快速了解scala语言特性)

进入其下载界面https://www.scala-lang.org/download/

其实他get start界面也有下载(

下载一个scala官方提供的windows下崽器(?)cs,开好网络(最好科学一下),双击打开

整个时间比较长,大概半小时左右(科学的情况下),你可以泡杯咖啡打吧游戏~

ps.需要注意的是,这个下载器有的时候感觉会卡住,如果你看见你电脑网络没有下行速度,而下载器也一动不动,那可以尝试关掉黑框框重新打开。当然,整个安装时间是比较长的。

安装完以后,黑框框会自己消失,然后重启电脑以刷新环境变量(如果你会命令行刷新环境变量也行)

如何命令行刷新环境变量:

Ctrl+R 输入 cmd,输入set PATH=C: 然后回车,关闭重新打开,然后环境变量就刷新了

三、准备样板工程

1.克隆工程

git clone --depth 1 https://github.com/SpinalHDL/SpinalTemplateSbt.git MySpinalProject
cd MySpinalProject
rm -rf .git
git init
git add .
git commit -m "Initial commit from template"

2.目录结构

Note

The structure described here is the default structure, but it can be easily modified.

译文:目录结构身娇腰柔易推倒~

In the root of the project are the following files:

File Description
build.sbt Scala configuration for sbt
build.sc Scala configuration for mill, an alternative to sbt
hw/ The folder containing hardware descriptions
project/ More Scala configuration
README.md A text/markdown file describing your project
.gitignore List of files to ignore in versioning
.mill-version More configuration for mill
.scalafmt.conf Configuration of rules to auto-format the code

As you probably guessed it, the interesting thing here is hw/. It contains four folders: spinal/, verilog/ and vhdl/ for your IPs and gen/ for IPs generated with Spinal.

hw/spinal/ contains a folder named after your project name. This name must be set in build.sbt (along with the company name) and in build.sc; and it must be the one in package yourprojectname at the beginning of .scala files.

In hw/spinal/yourprojectname/, are the descriptions of your IPs, simulation tests, formal tests; and there is Config.scala, which contains the configuration of Spinal.

Note

sbt must be used only at the root of the project, in the folder containing build.sbt.

四、CLI with sbt

  1. cli是命令行
  2. sbt是scala的构建工具,类似于gcc的make

好,让我们开始

1.初始化

sbt 有非常长的启动时间(类似于npm init)

sbt

首次编译并且获取依赖

compile

只用compile一次,后面会自动compile,进行增量编译(前提是不把这个命令窗关了)

2.生成verilog

type runMain, space, and tab

sbt:projectname> runMain 
;                               projectname.MyTopLevelVerilog
projectname.MyTopLevelFormal    projectname.MyTopLevelVhdl
projectname.MyTopLevelSim

tab and tab again,选择你要干啥(看选项易得)

3.持久化运行

~ runMain projectname.MyTopLevelVerilog

四、VSCode

1.前提条件:

安装好jdk11、jdk17,比如最新的jdk19好像不大行。

注意:需要在环境变量中添加JAVA_HOME,值要填安装的根目录(bin文件夹所在的那个目录),然后你可以在PATH中使用%JAVA_HOME%\bin形式,通过修改JAVA_HOME的值来做到版本切换

笔者一开始搞得时候是openjdk19,然后报错说找不到java,而我已经加了JAVA_HOME的环境变量,然后我装了java17,能用,再切回java19,也能用。。。。后来想想也许是set PATH=C:的方法不能全局刷新环境变量,比如vsc,所以至少注销然后重新登陆。

2.使用

右下角会跳出小标,一个是选import buid,另一个sbtmil二选一选sbt

然后找到/hw/projectname/MyTopLevel.scala这么一段代码

object MyTopLevelVerilog extends App {
  Config.spinal.generateVerilog(MyTopLevel())
}

会看见上面飘着run|debug点击run生成verilog代码

五、Idea

方法一

文件-->打开-->正常打开项目,等待他构建sbt

找到\hw\spinal\projectname\MyTopLevel.scala右击出现菜单栏,然后找到”运行文件“

方法二(官方文档这么说的)

文件-->新建-->来自现有代码的项目,全勾上(以下为官方文档的描述)

the choose the Import project from external model SBT and be sure to check all boxes

找到\hw\spinal\projectname\MyTopLevel.scala右击出现菜单栏,然后找到”运行文件“

posted @ 2023-01-14 22:29  msuad  阅读(445)  评论(0编辑  收藏  举报