Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playing around spinal in scala console fails #1284

Open
soartang opened this issue Jan 17, 2024 · 6 comments
Open

Playing around spinal in scala console fails #1284

soartang opened this issue Jan 17, 2024 · 6 comments

Comments

@soartang
Copy link

soartang commented Jan 17, 2024

I'm learning spinal in windows.

I downloaded the latest SpinalTemplateSbt and msys2. I'm good with compile and run, but have problems playing around spinalhdl in console. Below is my build.sbt with Eclipse Adoptium JDK 17.0.81

ThisBuild / version := "1.0"
ThisBuild / scalaVersion := "2.12.18"
ThisBuild / organization := "org.example"

val spinalVersion = "1.10.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)
...

Below is what I typed in console. I tried msys and native windows cmd, both gave the same errors.

scala> import spinal.core._
import spinal.core._

scala> val a = Bits(8 bits)
java.lang.NullPointerException: Cannot invoke "spinal.core.GlobalData.nodeAreInferringWidth()" because the return value of "spinal.core.BitVector.globalData()" is null
  at spinal.core.BitVector.setWidth(BitVector.scala:163)
  at spinal.core.BitsFactory.Bits(Bits.scala:33)
  at spinal.core.BitsFactory.Bits$(Bits.scala:33)
  at spinal.core.package$.Bits(core.scala:35)
  ... 55 elided

I can see the results of my code immediately in console. Making it work is really helpful for new learners. Appreciate it!

@Dolu1990
Copy link
Member

Hi,

SpinalHDL can't realy be used in console mode in this way. You have to provide a toplevel component :

SpinalVerilog(new MyTopLevel)

And have all your hardware statements in that toplevel herarchy

Reason is that SpinalHDL has a lot of hidden stuff happening under the hood which require some setup (done by the SpinalVerilog function)

@andreasWallner
Copy link
Collaborator

FYI in case the sbt startup time is annoying you and that's the reason why you want to use the REPL: you can just start sbt once and repeatedly run runMain, etc. in there - that makes it much quicker to use. (sorry in case you already knew)

@soartang
Copy link
Author

soartang commented Jan 18, 2024

FYI in case the sbt startup time is annoying you and that's the reason why you want to use the REPL: you can just start sbt once and repeatedly run runMain, etc. in there - that makes it much quicker to use. (sorry in case you already knew)

Thanks for pointing out this. Personally I prefer the console way (works like python console which I use a lot). Though '~runMain' produces immediate results, it runs the whole code and print everything all at once.

With console, it seems to be more newbie-friendly. For example, to find out the difference between 'd := a |<< c' and 'd := a << c', I can put them in console and see the difference.

@soartang
Copy link
Author

soartang commented Jan 18, 2024

Hi,

SpinalHDL can't realy be used in console mode in this way. You have to provide a toplevel component :

SpinalVerilog(new MyTopLevel)

And have all your hardware statements in that toplevel herarchy

Reason is that SpinalHDL has a lot of hidden stuff happening under the hood which require some setup (done by the SpinalVerilog function)

Go it. Assume I'd like to learn the difference of '##' and '@@', as a newbie, the preferable way to do so is to type the following code (Pardon me if it has errors):

val a = U"8'h5"
val b = U"8'hA"
println( a @@ b )
println( a ## b)

Is there a way?

@Dolu1990
Copy link
Member

Personnaly, i'm using Intellij Idea and that template project :
https://github.com/SpinalHDL/SpinalTemplateSbt

Else you can use sbt to generate some verilog, see the readme of that template project.

Else you can do some one liner as :
SpinalVerilog(new Component{val a = U"8'h5"; val b = U"8'hA"}).printRtl()

But the thing is that you need your repl to have the SpinalHDL compiler plugin in. i never tried.

@soartang
Copy link
Author

Personnaly, i'm using Intellij Idea and that template project : https://github.com/SpinalHDL/SpinalTemplateSbt

Else you can use sbt to generate some verilog, see the readme of that template project.

Else you can do some one liner as : SpinalVerilog(new Component{val a = U"8'h5"; val b = U"8'hA"}).printRtl()

But the thing is that you need your repl to have the SpinalHDL compiler plugin in. i never tried.

OK, i'll figure it out. Thank you Dolu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants