Forum Discussion

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

Flash Write/read

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.

I guess there are some series of operations to be performed before writing to a flash. I am not able to find any material on that.

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

3 Replies

  • 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.

    --- Quote End ---

    Are you using the correct flash write command or are you expecting the device behaves like a sram? Flash memory is not a sram: except reads, any other operation requires a special command sequence to be issued with a certain number of writes on specific addresses.

    --- Quote Start ---

    I guess there are some series of operations to be performed before writing to a flash. I am not able to find any material on that.

    --- Quote End ---

    Google the flash device part number and you'll find the datasheet. Read it and you'll get all the command codes for erase,write,identification,etc
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Since I am working on the DE2 board, I don't have access to all the pins on the flash chip. For eg: I dont have access to BYTE pin and the RY/BY (ready/busy) pin.

    I am saying this because the .csv file for the DE2 board does not contain these pin assignments. Hence, I want to know, whether write operation can be done without the use of these pins.

    I have attached the datasheet for the flash, but cant find any such sequence.

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

    Since you do have the datasheet, I can't understand why you don't read it.

    Anyway:

    - byte pin selects 8 or 16bit bus; this is usually hardwired high or low depending on how the flash memory is connected to your system, i.e. if you have only 8 data bits connected or all 16.

    - ry/by is optional: you can get the same information reading the status bits.

    The command sequences are summarized in table 16, page 37.