cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Contributor
Contributor
668 Views
Registered: ‎10-01-2013

fopen fails on Vivado 2017.4 Windows simulation

Jump to solution

Using Vivado 2017.4 simulator. 

  • Binary data file located at project.srcs/sim_1/frames.raw
  • File added to simulation sources
  • File automatically copied to project.sim\sim_1\behav\xsim
  • fopen() always returns fp = -20000, which fread() later rejects with an error

Testbench snippet:

    reg [7:0] rxd;
    integer fp, ret;
    initial begin
      fp = $fopen("frames.raw", "rb");
      if(fp == 0) begin
        $display("Failed opening data file!\n");
        $finish(1);
      end
      ret = $fread(fp, rxd);
    end

 

TCL console reports: ERROR: File descriptor (-1) passed to $fread in file C:/<path>/project.srcs/sim_1/tb.v at line 163 is not valid.

Debugger shows fp == -20000, and the fread() did not load the expected values.

 

Switching directory using TCL console does not help:

    cd C:/<path>/sim_1

    pwd
    C:/<path>/sim_1

 

Moving the file to C:/frames.raw and opening with these methods does not help:

    fp = $fopen("C:/frames.raw", "rb");

    fp = $fopen("C:\frames.raw", "rb");

 

Intentionally changing file name to non-existent file returns fp = 0 instead.  So the error above is not a file-not-found error.

    fp = $fopen("nonexistent.raw", "rb");

 

Windows properties dialog shows Authenticated Users have read/write/execute/modify permission on the files (both in sim_1 and behav\xsim)

 

Similar problems were reported here without a clear resolution:

https://forums.xilinx.com/t5/Simulation-and-Verification/Vivado-cannot-find-data-file-for-my-System-Verilog-simulation/m-p/830250

https://forums.xilinx.com/t5/Simulation-and-Verification/fopen-returns-255/td-p/873249

 

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Contributor
Contributor
605 Views
Registered: ‎10-01-2013

Re: fopen fails on Vivado 2017.4 Windows simulation

Jump to solution

Problem solved.  It was simply a syntax error in fread() that did not generate a warning.  Should have been:

    ret = $fread(rxd, fp);

not

    ret = $fread(fp, rxd);

View solution in original post

1 Reply
Highlighted
Contributor
Contributor
606 Views
Registered: ‎10-01-2013

Re: fopen fails on Vivado 2017.4 Windows simulation

Jump to solution

Problem solved.  It was simply a syntax error in fread() that did not generate a warning.  Should have been:

    ret = $fread(rxd, fp);

not

    ret = $fread(fp, rxd);

View solution in original post