Jump to content
  • 0

Nexys 4 store data in flash


savmil

Question

Hello to everyone,

i have some problem to store data in a flash located on Nexys 4.

Vivado tell me that is a s25fl128s, i have searched on the web and i found that STARTUPE2 USRCCLKO control post configuration access to spi.

I create a fsm that connect clk of my top level entity to this pin and i create a tri-state component to use inout port to connect to spi interface, i want to use flash in single spi mode.

I try to read from a register by writing a command, i see this command is correct in ila interface (in term of timing and information), but when i want to read data, i don't see anything.

Can you help me?

Thanks in advice

Link to comment
Share on other sites

12 answers to this question

Recommended Posts

@savmil,

Heh, I'm in the process of writing a (rather long) blog article about how to build a flash controller within your design.  Here's a link to the last flash controller I've written, and then here's some thoughts to get you going:

  1. If the flash isn't responding right, rule number one is to first get and examine a trace of what values you are sending to the flash.  Make sure that trace matches the spec for the flash.
  2. I use a flash simulator with most of my designs.  It works with Verilator.  You can find an example of the flash simulator I am using for the Nexys Video board here.  (It's probably still close enough to work with your board--the Spansion devices are quite similar.)
  3. If it's still not working, send a command for which you expect a known response--something like the 0x9f command to read the manufacturer ID.  From this known response, you can debug any delays you have in the logic.
  4. After all this, you can then try to switch to QSPI if you want.  If things go bad, I've found that sending (via normal SPI) two words of 0xff on dat[0] or MOSI (same wire) and then raising CS_n again should usually get you back into SPI mode.

If you have more problems beyond that, then let me encourage you to be more specific, share waveforms and/or logic, and let us know what's really going on within your code.

Dan

Link to comment
Share on other sites

@D@n, Thanks for help me.

1. i think logically signal is right because i see same signal that are showed in datasheet, but i want to control another time.

2. Thanks for simulation model i try with this.

3. I try a command like this because i want to create a FSM that works with all command

4. For now i want to have a simple controller because my concern is to store data.

Thanks for all, if i can't resolve problem with this information i post another message, first i read your article that is very detailed. thanks another time.

 

Link to comment
Share on other sites

@savmil,

If your goal is to store data, then be aware: flash memory doesn't work like other memory.  There are two operations required of storing data.

The first operation turns the bits from zeros to ones.  It is typically applied to sectors only, meaning that if you want to change an 0xa0 to a 0xa3, you will first need to wipe the entire sector clean of data.  This is controlled by the ERASE command.  (Sectors are usually around 64kB, although some devices allow access to 2kB sectors.)  Once the sector has been erased, *EVERY BYTE* within it will be 0xff.  This operation can take up to a couple of seconds to complete--see your data sheet for more details.

The second operation is more selective.  That's the PROGRAM operation.  This operation turns one bits to zeros.  So, going back to our example of trying to change a 0xa0 to a 0xa3, you first ERASEd the whole sector.  That would turn this byte (and many others) into 0xff.  You could then program this byte to be a 0xa3.  Indeed, you can program up to a PAGE at a time (typically 256 bytes).  While programming  flash memory is faster than erasing, it is still incredibly slow.

Indeed, it is so slow to do that all of my FPGA CPU designs treat the flash as a ROM rather than any other type of memory.

If you look at the flashdrvr.cpp program component within my design, you'll see the code I use to adjust the contents of the flash memory.  This driver is usually called from within another program, both external to the FPGA, such as zipload.cpp, which loads a program and/or a design configuration file into flash memory.

Dan

Link to comment
Share on other sites

@D@n,

My goal is to store and read data from flash but i want first create a FSM that send a correct command and read something.

Thanks for information and for your work in that link you gave to me, but i found my problem and now i feel very stupid, i switched in my constraint file MOSI pin with MISO.

I want to thank you for your blog because i see that are present a lot of interesting article.

Sorry if i annoyed you and forum.

 

 

Link to comment
Share on other sites

@D@n,

I see and i don't want to use microblaze but i don' t understand what i'm doing wrong.

I control a lot of time my signal but for me i see that are correct, i attached a snapshot if you would to see.

Pin naming:

        cs_n is chip select;

        quad_spi_line_i is MOSI;

        quad_spi_line_o is MISO;

        p_1_out is a 50 MHZ clock;

Command is 05h, i read on the manual that before i have to send a command i have to set cs_n to low, wait for a rising edge of clock and after send command that is captured each rising edge of clock, for me flash have to sample 05h command but i have for all time one as output.

 

flashcommand.png

Link to comment
Share on other sites

Hi @savmil,

I may be wrong about this, but it looks like your intended command of 05h may not be transmitting correctly; the datasheet for the S25FL128S says that data is clocked in to the part on each rising edge of the serial clock and the clock cycles are measured starting on the first falling edge of the SCK after the falling edge of ~CS.

Presuming I am interpreting this correctly, since the CS line goes high on the 8th falling edge of SCK (which is required otherwise the command will fail), it appears you are actually transmitting a command of 82h rather than 05h, which as far as I can tell from the list of commands does not correspond to anything.

Thanks,
JColvin

Link to comment
Share on other sites

@savmil,

@JColvin is right.  Here's a trace showing what sending a 0x05 should look like.  In this trace, the o_qspi_dat[0] line is the same as the MOSI line in your design.

 

qspi-wren.thumb.png.0451017295c282a6af6f688111423d83.png

Of course, since this is a read-status command, you'll want to keep the CS_n line high for longer ... (I had thought this was a write-enable command when I created the trace ...)

Dan

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...