top of page

[chisel/scala] Create an array of Modules


What I want to do

  • I have a class (parts) that I created and that inherits from Module.

  • I want to place multiple instances (components) of this class in a circuit.


What I tried

I tried to create an array using Vec, but it didn't work.

When I write code like this, the following compilation error occurs:

class MyParts extends Module{
	val io = IO(・・・)
}

val parts:Vec[Module] = VecInit(Seq.fill(3)(Module(new MyParts)))
overloaded method apply with alternatives:
[error]   [T <: chisel3.Data](elt0: T, elts: T*): chisel3.Vec[T] <and>
[error]   [T <: chisel3.Data](elts: Seq[T]): chisel3.Vec[T]
[error]  cannot be applied to (Seq[MyParts])


Solution

In the end, Vec is not necessary, just use Seq.

val parts = Seq.fill(3)(Module(new MyParts))

At first, I misunderstood that "Seq cannot have chisel hardware as an element, so I need to use Vec for that."

In fact, "In Seq, chisel types cannot be used as indexes to access array elements." ( Reference ) is accurate.

Recent Posts

See All

Comments


Let's do our best with our partner:​ ChatReminder

iphone6.5p2.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Let's do our best with our partner:​ ChatReminder

納品:iPhone6.5①.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Theme diary: Decide the theme and record for each genre

It is a diary application that allows you to post and record with themes and sub-themes for each genre.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png
bottom of page