Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
17 years ago

Help with Flash memory reading

hi,

I am new to digital design and FPGAs, and I am having trouble with the flash Memory on the Cyclone II development board.

I am playing around with a simple (6502) based cpu core (actually the FPGA64 commodore 64 emulator) and I am trying to use the flashRAM as a ROM.

The addresses to the flash are being held steady for over 400ns but all I get back on the flash data lines is $FE, which never changes even when the address changes.

I have a simple wave file exported from Signal TapII, along with the vhdl of my memory manger code which I will try to attach as a zip file.

I wrote a simple verilog program to increment the memory address of the flash every two clock cycles (using the 27mhz clock), and that seemed to work just fine. I have no idea why this code doesn't work.

I would really appreciate some input as I have read plenty but this is my first time using real physical hardware and I am struggling :(

Thanks

Simon :)

18 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    When you set

    data = 16'hbde7;

    oe = 1;

    we = 0;and the other signals to useful fixed levels, what do you expect to happen at the flash device?

    There is another point, I previously forgot. To read from a bidirectional pin, you have to drive the output to high impedance state, e. g. Data = 16'bz.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I set this:

    assign CE = 0;

    assign WP = 1;

    assign RESET = 1;

    assign BYTE = 1;

    assign Adress = 1;

    to fixed levels because at the read and write operation they have the same level...

    If i set the switch SW_OE = 0 and SW_WE =1 i expect that the Data hBDE7 was set at Adress 1 in de flash...when I then pull the switch SW_OE to 1 and the SW_WE to 0 I expect that he gives the Data (hBDE7) to the LED's SW_OE is connected with OE and SW_WE with WE...

    how would the code looks like, when I want to read it? I mean...when I set at the Data 16'bz how can I read then the data again from Data? I mean...I set it with z...do you know what I mean?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Yes, I think you are operating the flash interface correct now, both for read and write (exept for the missing 16'bz setting, I think).

    --- Quote Start ---

    i expect that the Data hBDE7 was set at Adress 1 in de flash

    --- Quote End ---

    But actually nothing happens, as I already told you

    --- Quote Start ---

    You can't write data to a flash memory by simply activating WE. Consult the flash datasheet at the DE2-70 system cd, you'll see that it's a rather complex action to write data to a flash. Basically it can be done in HDL code, but not in a few lines of code.

    --- Quote End ---

    This didn't mean the bus signals, it's about a complex command sequence.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    ok... do you know where I can find a ready written code for that?

    I have also a second question...how can I include a VHDL-file in a Verilog code?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I don't know a HDL code for flash programming. Mostly, this is done from embedded processor, e. g. NIOS II. But as I said, it's surely possible, involving a state machine to step through the various states of unlocking sequence. Also a flash has to be erased before reprogramming.

    Including a VHDL component in Verilog is easy, it's actually done in Quartus megafunctions in many places (using both directions). You simply interface a VHDL component as it would be a Verilog module. There is a restriction with ModelSim that you can use old style# ( ) parameter syntax for generics only. In Quartus, you can also use defparam syntax to set VHDL generics. For the opposite direction, you write a component declaration that correspondends to a Verilog module and instantiate it as it would be a VHDL.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi.. I am trying to write/ read from the flash. I am working on an Altera DE2 board. I am just trying to write some value (8-bit) in into a fixed memory location in a flash, and am trying to read it. I am able to read values from flash code but not able to write the values I want.

    i.e The value being read is not the value I wrote in that memory, which shows that 'write' operation is not taking place.

    Please help me out.. (attached below :code )

    module flashcontroller(

    //REF_CLK,

    RESET_N,

    CLK,

    SW,

    SWIN,

    //controller outputs

    LEDR,

    FL_ADDR,

    FL_DQ,

    FL_CE_N,

    FL_OE_N,

    FL_WE_N,

    FL_RST_N,

    );

    //input REF_CLK;

    input RESET_N;

    input CLK;

    input SW;

    input [7:0] SWIN;

    inout [7:0] FL_DQ ;

    output [21:0] FL_ADDR;

    output FL_CE_N;

    output FL_OE_N;

    output FL_WE_N;

    output FL_RST_N;

    output [7:0] LEDR;

    wire[21:0] rFL_MAX;

    reg [21:0] rFL_ADDR;

    reg [7:0] rFL_DQ;

    reg rFL_RST_N;

    reg [7:0] rLEDR;

    reg rFL_WE_N;

    reg rFL_OE_N;

    reg rFL_CE_N;

    // assign rFL_MAX = 22'b1111111111111111111111;

    // assign FL_DQ = 8'b10000001;

    // assign FL_WE_N = 1'b1;

    // assign FL_OE_N = 1'b0;

    // assign FL_CE_N = 1'b0;

    assign FL_RST_N = rFL_RST_N;

    assign FL_ADDR = rFL_ADDR;

    assign LEDR = rLEDR;

    assign FL_DQ = rFL_DQ;

    assign FL_CE_N = rFL_CE_N;

    assign FL_OE_N = rFL_OE_N;

    assign FL_WE_N = rFL_WE_N;

    always@(posedge CLK or negedge RESET_N)

    begin

    if (!RESET_N)

    begin

    rFL_RST_N <= 0;

    rFL_ADDR <= 0;

    end

    else if (SW == 1)

    begin

    rFL_RST_N <= 1;

    rFL_DQ <= 8'bz;

    rFL_WE_N <= 1'b1;

    rFL_OE_N <= 1'b0;

    rFL_CE_N <= 1'b0;

    rLEDR <= FL_DQ;

    end

    else

    begin

    rFL_RST_N <= 1;

    rFL_WE_N <= 1'b0;

    rFL_OE_N <= 1'b1;

    rFL_CE_N <= 1'b0;

    rFL_DQ <= SWIN;

    rLEDR <= SWIN;

    // rFL_RST_N <= 1;

    // if (rFL_ADDR > rFL_MAX)

    // begin

    // rFL_ADDR <= 0;

    // end

    // else

    // begin

    // rFL_ADDR <= rFL_ADDR+1;

    // end

    end

    end

    endmodule
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Hi.. I am trying to write/ read from the flash. I am working on an Altera DE2 board. I am just trying to write some value (8-bit) in into a fixed memory location in a flash, and am trying to read it. I am able to read values from flash code but not able to write the values I want.

    i.e The value being read is not the value I wrote in that memory, which shows that 'write' operation is not taking place.

    Please help me out.. (attached below :code )

    module flashcontroller(

    //REF_CLK,

    RESET_N,

    CLK,

    SW,

    SWIN,

    //controller outputs

    LEDR,

    FL_ADDR,

    FL_DQ,

    FL_CE_N,

    FL_OE_N,

    FL_WE_N,

    FL_RST_N,

    &nbsp;);

    //input REF_CLK;

    input RESET_N;

    input CLK;

    input SW;

    input [7:0] SWIN;

    inout [7:0] FL_DQ ;

    output [21:0] FL_ADDR;

    output FL_CE_N;

    output FL_OE_N;

    output FL_WE_N;

    output FL_RST_N;

    output [7:0] LEDR;

    wire[21:0] rFL_MAX;

    reg [21:0] rFL_ADDR;

    reg [7:0] rFL_DQ;

    reg rFL_RST_N;

    reg [7:0] rLEDR;

    reg rFL_WE_N;

    reg rFL_OE_N;

    reg rFL_CE_N;

    // assign rFL_MAX = 22'b1111111111111111111111;

    // assign FL_DQ = 8'b10000001;

    // assign FL_WE_N = 1'b1;

    // assign FL_OE_N = 1'b0;

    // assign FL_CE_N = 1'b0;

    assign FL_RST_N = rFL_RST_N;

    assign FL_ADDR = rFL_ADDR;

    assign LEDR = rLEDR;

    assign FL_DQ = rFL_DQ;

    assign FL_CE_N = rFL_CE_N;

    assign FL_OE_N = rFL_OE_N;

    assign FL_WE_N = rFL_WE_N;

    always@(posedge CLK or negedge RESET_N)

    begin

    if (!RESET_N)

    begin

    rFL_RST_N <= 0;

    rFL_ADDR <= 0;

    end

    else if (SW == 1)

    begin

    rFL_RST_N <= 1;

    rFL_DQ <= 8'bz;

    rFL_WE_N <= 1'b1;

    rFL_OE_N <= 1'b0;

    rFL_CE_N <= 1'b0;

    rLEDR <= FL_DQ;

    end

    else

    begin

    rFL_RST_N <= 1;

    rFL_WE_N <= 1'b0;

    rFL_OE_N <= 1'b1;

    rFL_CE_N <= 1'b0;

    rFL_DQ <= SWIN;

    rLEDR <= SWIN;

    // rFL_RST_N <= 1;

    // if (rFL_ADDR > rFL_MAX)

    // begin

    // rFL_ADDR <= 0;

    // end

    // else

    // begin

    // rFL_ADDR <= rFL_ADDR+1;

    // end

    end

    end

    endmodule

    --- Quote End ---

    Hi. I sorry because my English is not good.

    I read at this topic http://www.alteraforum.com/forum/showthread.php?t=2541&page=2

    Have done it yet? I'm trying to read data on kit de2 but i'm not success. Please send me your code or some advise.

    Thank you so much. :D
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi all,

    I am using cyclone 3 starter kit. I am not able to program my flash memory. when i try to reset the factory settings the loading is stuck at 71% . in the programming window the FPGA name appears as none after 71%. But the same cycloneIII_3c25_noise _standard file, if i loaded it as .sof file it is getting loaded 100%. Looks like i have damaged the flash memory. One another thing is my FPGA is getting heated rapidly. Does anyone have any idea on what the damage to the flash memory would have to do with the heating?

    Any response will be highly helpful !

    thanks :)