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

如何解决I2S Verilog代码在Vivado与Design Compiler中的综合警告

I2S Verilog代码综合警告修复方案

一、Vivado未使用寄存器警告([Synth 8-3332])

警告原因

i2s_rx模块中,右声道寄存器rx_right的最高位(bit15)从未被有效更新,综合器判定该寄存器位冗余,因此触发移除警告。问题根源在于采样移位方向错误:I2S协议要求先传输最高位(MSB),但原代码是将新采样的sdata补到寄存器低位,导致最高位始终为初始值0,无法被后续逻辑使用。

修复代码

修改i2s_rx模块的移位逻辑,将新采样数据放到寄存器高位,确保MSB到LSB的正确采样顺序:

`timescale 1ns / 1ns

module i2s_rx #(
    parameter AUDIO_DW = 16
)(
    input i_rx_sclk,
    input i_rx_rst_n,
    input i_rx_lrclk,
    input i_rx_sdata,

    output reg [AUDIO_DW-1:0] o_rx_left_chan,
    output reg [AUDIO_DW-1:0] o_rx_right_chan
);

reg [AUDIO_DW-1:0] rx_left;
reg [AUDIO_DW-1:0] rx_right;
reg rx_lrclk_r;
wire rx_lrclk_nedge;

assign rx_lrclk_nedge = !i_rx_lrclk & rx_lrclk_r;

always @(posedge i_rx_sclk or negedge i_rx_rst_n)
    if (!i_rx_rst_n) begin
        rx_lrclk_r <= 0;
        rx_left <= 0;
        rx_right <= 0;
    end else begin
        rx_lrclk_r <= i_rx_lrclk;
        if (rx_lrclk_r) begin
            // 修正移位方向:新数据放到高位,符合I2S MSB优先传输规则
            rx_right <= {i_rx_sdata, rx_right[AUDIO_DW-1:1]};
        end else 
            rx_left <= {i_rx_sdata, rx_left[AUDIO_DW-1:1]};
    end

always @(posedge i_rx_sclk or negedge i_rx_rst_n)
    if (!i_rx_rst_n) begin
        o_rx_left_chan <= 0;
        o_rx_right_chan <= 0;
    end else if (rx_lrclk_nedge) begin
        o_rx_left_chan <= rx_left;
        // 右声道最后一位在lrclk下降沿时采样,同样修正移位逻辑
        o_rx_right_chan <= {i_rx_sdata, rx_right[AUDIO_DW-1:1]};
    end

endmodule

二、Design Compiler冗余赋值警告(VO-4)

警告原因

第255行的assign o_tx_sclk = i_tx_sclk;属于冗余赋值:直接将输入端口与输出端口用wire连接,综合器认为该assign语句无实际逻辑意义,因此触发警告。同时i2s_tx模块存在笔误:输入端口i_tx_raight_chan应为i_tx_right_chan,会导致右声道数据无法正确传入。

修复代码

  1. 移除冗余的assign语句,直接在模块端口映射中关联输入输出;
  2. 修正右声道输入端口的笔误:
`timescale 1ns / 1ns

module i2s_tx #(
    parameter AUDIO_DW = 16
)(
    input i_tx_sclk,
    input [AUDIO_DW-1:0] i_tx_prescaler,
    input i_tx_rst_n,
    
    // 直接将输入端口作为输出,移除冗余assign
    output wire o_tx_sclk = i_tx_sclk,
    output reg o_tx_lrclk,
    output reg o_tx_sdata,

    input [AUDIO_DW-1:0] i_tx_left_chan,
    // 修正笔误:raight → right
    input [AUDIO_DW-1:0] i_tx_right_chan
);

reg [AUDIO_DW-1:0] tx_bit_cnt;
reg [AUDIO_DW-1:0] tx_left;
reg [AUDIO_DW-1:0] tx_right;

always @(negedge i_tx_sclk or negedge i_tx_rst_n) begin
    if (!i_tx_rst_n) begin
        tx_bit_cnt <= 1;
        tx_left <= 0;
        tx_right <= 0;
        o_tx_lrclk <= 0;
        o_tx_sdata <= 0;
        
    end else begin
        if (tx_bit_cnt >= i_tx_prescaler) begin
            tx_bit_cnt <= 1;
        end else begin
            tx_bit_cnt <= tx_bit_cnt + 1;
        end
        
        if (tx_bit_cnt == i_tx_prescaler && o_tx_lrclk) begin
            tx_left <= i_tx_left_chan;
            tx_right <= i_tx_right_chan;
        end                
        
        o_tx_lrclk <= (tx_bit_cnt == i_tx_prescaler) ? ~o_tx_lrclk : o_tx_lrclk;
    
        o_tx_sdata <= o_tx_lrclk ? tx_right[AUDIO_DW - tx_bit_cnt] : tx_left[AUDIO_DW - tx_bit_cnt];
    end
end

endmodule

额外验证

修复后需确认:

  • I2S传输的MSB/LSB顺序符合协议要求;
  • 右声道数据能正确传入tx模块并输出;
  • 综合工具无冗余寄存器或冗余赋值警告。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 01:18:17