Skip to content

BRAM initialization error #5409

@RemyCiterin

Description

@RemyCiterin

Version

Yosys 0.44 (git sha1 80ba43d, g++ 13.3.0 -fPIC -O3)

On which OS did this happen?

Linux

Reproduction Steps

The Top.v file instantiate a BRAM initialized using Mem.hex and read the 3th byte at the address 1:

module mkTop (
  input clk100mhz, // 100 MHZ clock
  input reset,
  input [3:0] btn,

  output [7:0] led
);

  wire [31:0] DO;

  BlockRAM#(
    .ADDR_WIDTH(12),
    .DATA_WIDTH(32),
    .INIT_FILE("Mem.hex")
  ) blockRAM (
    .CLK(clk100mhz),
    .DI(32'hxxxxxxxx),
    .ADDR(12'h001),
    .WE(1'b0),
    .RE(1'b1),
    .DO(DO)
  );

  assign led = DO[23:16];
endmodule

and here is my wrapper for the BRAM (copied from https://github.com/blarney-lang/blarney/blob/master/Verilog/BlockRAM.v):

// Single-port block RAM
// =====================

module BlockRAM (
  CLK,     // Clock
  DI,      // Data in
  ADDR,    // Read address
  WE,      // Write enable
  RE,      // Read enable
  DO       // Data out
  );

  parameter ADDR_WIDTH = 1;
  parameter DATA_WIDTH = 1;
  parameter INIT_FILE  = "UNUSED";

  input  CLK;
  input  [DATA_WIDTH-1:0] DI;
  input  [ADDR_WIDTH-1:0] ADDR;
  input  WE, RE;
  output reg [DATA_WIDTH-1:0] DO;
  reg [DATA_WIDTH-1:0] RAM[2**ADDR_WIDTH-1:0];

  generate
    if (INIT_FILE != "UNUSED") begin
      initial $readmemh(INIT_FILE, RAM);
    end else begin
      integer i;
      initial
        for (i = 0; i < 2**ADDR_WIDTH; i=i+1)
          RAM[i] = 0;
    end
  endgenerate

  always @(posedge CLK)
  begin
    if (WE) begin
      RAM[ADDR] <= DI;
    end
    if (RE) begin
      if (WE) begin
        DO <= {DATA_WIDTH{1'hx}};
      end else begin
        DO <= RAM[ADDR];
      end
    end
  end

endmodule

Mem.hex.tar.gz

Then I generate the bytestream for a xilinx xc7a200tsbg484-1 using yosys+nextpnr.
I also created a small repo https://github.com/RemyCiterin/bram-bug-yosys-nextpnr-xilinx to reproduce the bug with this minimal example + dump the content of the BRAM

Expected Behavior

As I read the 3rd byte at the address 1 I expect the LED to display the number 0x82

Actual Behavior

Using a nexys-video board I observed the byte 0x80 with the LED. In fact it's not the only error I found, here are the 10 first values I observed:

00004297
d8808293
00005317
d8c10213
0062f863
00008023
00128293
fa60ece3
00005117
d3010013

and here are the 10 expected values from Mem.hex:

00004297    // raw_mem addr 00000000;  byte addr 00000000
d8828293    // raw_mem addr 00000001;  byte addr 00000004
00005317    // raw_mem addr 00000002;  byte addr 00000008
d8c30313    // raw_mem addr 00000003;  byte addr 0000000c
0062f863    // raw_mem addr 00000004;  byte addr 00000010
00028023    // raw_mem addr 00000005;  byte addr 00000014
00128293    // raw_mem addr 00000006;  byte addr 00000018
fe62ece3    // raw_mem addr 00000007;  byte addr 0000001c
00005117    // raw_mem addr 00000008;  byte addr 00000020
d7010113    // raw_mem addr 00000009;  byte addr 00000024

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending-verificationThis issue is pending verification and/or reproduction

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions