Solve the problem of cannot assign to memory or cannot assign a packed type to an unpacked type when vivado assigns reg

Save money: solutions

Check how the assigned value isreg declared , whether it is [m:n]placed in the wrong position , and think carefully whether it should be declared as a vector or an array , [m:n]and whether it should be placed before or after the variable name.

Although it saves money, you might as well scroll down : ) and see my journey. If it is useful, please like and collect it~

background

Sometimes when we assign a value to a certain reg, the following prompt will appear:
vivado报错cannot assign to memory、cannot assign a packed type to an unpacked type

Error: cannot assign to memory
Error: cannot assign a packed type to an unpacked type

Troubleshooting process

After careful inspection, I found that when declaring regthe type of register, the declaration was 数组not 向量. Right now:

/* 出现错误的代码 */
reg reg_tagv_wen[1:0];//声明成了数组,这里即2个1位的reg

/* 修正后的代码 */
//修正完成后,上方赋值语句不再报错。
reg [1:0] reg_tagv_wen;//声明成了向量,这里即1个两位的reg

For arrays , you must explicitly specify which element in the array to assign to .
For vectors , you can assign values ​​to several bits at the same time .

This error occurred to me because my original intention was to declare it as a 2-bit vector , but I [1:0]placed it in the wrong position , after the variable name, and declared it as an array (two 1-bit regs) , so Caused an error.

The solution is to [1:0]move it to the front and declare it as a vector.

universal solution

The general solution is: check how the assigned reg is declared, whether it is [m:n]placed in the wrong position, and carefully consider whether it should be declared as a vector or an array, and [m:n]whether it should be placed before or after the variable name.

Guess you like

Origin blog.csdn.net/weixin_52027058/article/details/128188462