Yosys 优化 GPIO RX 模块远离

问题描述 投票:0回答:1

最近开始玩iE40 icestick评估板。我遇到了什么 我认为是奇怪的行为:

Yosys 似乎想要优化一个模块,该模块需要一个端口连接到一个 RX GPIO 引脚。 IMO 这永远不应该发生,因为永远不应该考虑这个引脚的状态 持续的。我在下面的最小 verilog 程序中重新创建了它:

以下代码,合成:

yosys -p 'synth_ice40 -noflatten -noabc -top top -json out/top.json'
生成以下内容 logic。 移除
(* keep *)
模块上方的
rxi
会生成以下 logic。 请注意,
rxi
模块现在不见了,我认为这是不对的。这是预期的行为吗?

module top                                                                       
(                                                                                
    input CLK,                                                                   
    input RX,                                                                    
    output TX,                                                                   
);                                                                               
    reg[7:0] rx_buf;                                                             
    reg[7:0] tx_buf;                                                             
                                                                                 
    (* keep *) // <-- Prevents `rxi` from being optimized away.                  
    rx rxi                                                                       
    (                                                                            
        .clk(CLK),                                                               
        .rx(RX),                                                                 
        .rx_buf(rx_buf)                                                          
    );                                                                           
                                                                                 
    tx txi                                                                       
    (                                                                            
        .clk(CLK),                                                               
        .tx_buf(tx_buf),                                                         
        .tx(TX)                                                                  
    );                                                                           
                                                                                 
    always @(posedge clk) begin                                                  
        tx_buf <= rx_buf;                                                        
    end                                                                          
endmodule                                                                        
                                                                                 
module tx                                                                        
(                                                                                
    input wire clk,                                                              
    input wire[7:0] tx_buf,                                                      
    output wire tx                                                               
);                                                                               
    always @(posedge clk) begin                                                  
        tx <= tx_buf[0];                                                         
        tx_buf <= {tx_buf[0], tx_buf[7:1]};                                      
    end                                                                          
endmodule                                                                        
                                                                                 
module rx                                                                        
(                                                                                
    input wire clk,                                                              
    input wire rx,                                                               
    output reg[7:0] rx_buf                                                       
);                                                                               
    always @(posedge clk) begin                                                  
        rx_buf <= {rx, rx_buf[7:1]};                                             
    end                                                                          
endmodule 

我的引脚定义是:

set_io --warn-no-port RX 9                                                           
set_io --warn-no-port TX 8                                                                                                                         
set_io CLK 21                                                                        

(* keep *)
给了我预期的逻辑,但我不认为该模块可以被正确优化掉?

verilog fpga lattice hdl yosys
1个回答
0
投票

经过一些更改后在 Vivado 中构建 *** 在下面标记为 ***。
这些更改应该有助于其他综合工具。
原始帖子甚至没有在 Vivado 中编译。

module top                                                                       
(                                                                                
    input CLK,                                                                   
    input RX,
    // *** removed extra comma ***                                                                    
    output TX                                                                   
);  

    // *** change to wire ***                                                                         
    wire [7:0] rx_buf;                                                             
    reg  [7:0] tx_buf;                                                             
                                                                                 
    (* keep *) // <-- Prevents `rxi` from being optimized away.                  
    rx rxi                                                                       
    (                                                                            
        .clk(CLK),                                                               
        .rx(RX),                                                                 
        .rx_buf(rx_buf)                                                          
    );                                                                           
                                                                                 
    tx txi                                                                       
    (                                                                            
        .clk(CLK),                                                               
        .tx_buf(tx_buf),                                                         
        .tx(TX)                                                                  
    );                                                                           
                        
    // *** CLK not clk ***                                                                            
    always @(posedge CLK) begin                                                  
        tx_buf <= rx_buf;                                                        
    end                                                                          
endmodule                                                                        
                                                                                 
module tx                                                                        
(                                                                                
    input wire clk,                                                              
    input wire[7:0] tx_buf,
    output wire tx                                                               
);
  // *** various reg, wire issues & register inference issues ***
  reg [7:0] tx_buf_reg;
                                                                               
    always @(posedge clk) begin                                                  
        tx_buf_reg <= {tx_buf[0], tx_buf[7:1]};                                      
    end             
    
  assign tx = tx_buf_reg[0];                                                         
                                                                 
endmodule                                                                        
                                                                                 
module rx                                                                        
(                                                                                
    input wire clk,                                                              
    input wire rx,                                                               
    output reg[7:0] rx_buf                                                       
);                                                                               
    always @(posedge clk) begin                                                  
        rx_buf <= {rx, rx_buf[7:1]};                                             
    end                                                                          
endmodule     

示意图显示了从 RX 到 TX 的完整数据路径:

© www.soinside.com 2019 - 2024. All rights reserved.