You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

UART串行传输8位数据时SystemVerilog代码编译错误求助

Fixing Your UART Serial Transmission Code Issues

Hey there! Let's work through your two main issues here—the compilation error and the broken loop logic.

1. Why the "Too many indices going into RXSD_pkt" error?

This error pops up because you're trying to index into RXSD_pkt like it's an array (using RXSD_pkt[i]), but RXSD_pkt is actually a single-bit scalar variable (not an 8-bit vector/array) in your code.

From your description, you have an 8-bit packet in your transaction class (pkt.RXD). So you either:

  • Accidentally defined RXSD_pkt as a single bit instead of an 8-bit vector (like bit[7:0] RXSD_pkt), or
  • Meant to access pkt.RXD[i] directly instead of RXSD_pkt[i] (if RXSD_pkt isn't properly assigned the value of pkt.RXD).

2. Your loop has incorrect termination logic

Right now, your loop starts at i = ($size(pkt.RXD)-1) (which is 7 for an 8-bit vector) and uses i <= 0 as the condition. Since 7 is never less than or equal to 0, this loop will never execute at all—that's a big problem for transmitting your data! You need to change the condition to i >= 0 so the loop runs from 7 down to 0.

Corrected Code

Here's the fixed version, assuming you want to transmit the 8-bit pkt.RXD over UART, one bit per clock cycle:

// First, make sure RXSD_pkt is an 8-bit vector (if you're using it)
bit[7:0] RXSD_pkt;
RXSD_pkt = pkt.RXD; // Assign the transaction's packet to your local vector

// Fixed loop
for (int i = ($size(pkt.RXD)-1); i >= 0; i = i-1) begin 
    // Drive each bit of the packet onto the UART RXD line
    RXSD_vif.DRV.cb_RXSD_DRV.RXD <= RXSD_pkt[i];
    // Don't forget to wait for the next clock cycle!
    @(RXSD_vif.DRV.cb_RXSD_DRV);
end

Key Notes:

  • Wait for the clock: I added @(RXSD_vif.DRV.cb_RXSD_DRV); inside the loop—this ensures you drive one bit per clock cycle (since your clock block uses the rising edge). Without this, you'd drive all bits in zero time, which isn't correct for UART.
  • Simplify if possible: If you don't need the RXSD_pkt intermediate variable, you can simplify it to directly use pkt.RXD[i]:
    for (int i = ($size(pkt.RXD)-1); i >= 0; i = i-1) begin 
        RXSD_vif.DRV.cb_RXSD_DRV.RXD <= pkt.RXD[i];
        @(RXSD_vif.DRV.cb_RXSD_DRV);
    end
    
  • Proper variable declaration: Make sure i is declared properly (using int i inside the loop or before it) to avoid undeclared variable errors.

Quick Recap

  • Fix the loop condition to i >= 0 so it actually runs through all 8 bits.
  • Ensure RXSD_pkt is an 8-bit vector (or use pkt.RXD directly) to fix the indexing error.
  • Add a clock wait inside the loop to transmit one bit per cycle.

内容的提问来源于stack exchange,提问作者rachit shah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:51:25