Search
[chisel/scala] Create an array of Modules
- M.R

- May 1, 2024
- 1 min read
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.






Comments