Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spiflash: A proposed SPI controller for reading #2

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

ghost
Copy link

@ghost ghost commented Dec 23, 2019

On this pull request, I propose an SPI flash controller module exclusively for reading data or registers out of a flash device. Currently, it has:

  • _SPIFlashReaderBase: a base class from which can be inherited to create a new controller module, such as one that reads the ID of the flash device by issuing the opcode 0x9F (or 0x9E)
  • SPIFlashSlowReader: a module for normal reads from the device, meaning no dummy cycles of waiting is needed right after sending the address bytes to the device, while the read frequency is often capped.
  • SPIFlashFastReader: a module for "fast reads", meaning a faster frequency than normal reads while a number of dummy cycles of waiting is needed right after sending the address bytes.

Note that only the SlowReader but not the FastReader has been successfully tested on the ECP5 evaluation board.

In order to use the clock signal clk as the SPI clock for this module design, ECP5 requires the user NOT to request for SPI clock that corresponds to the on-chip oscillator (MCLK) but to instantiate a USRMCLK Instance. Therefore, to use this module and bulid the configuration bitstream on nextpnr without errors (see this comment), the user must avoid requesting for the normal clock pin from Ball U3 by some means. One way is to use my proposed modification of nmigen-boards.

I look forward to seeing further comments, thanks.

@@ -23,10 +23,11 @@ def local_scheme(version):
#long_description="""TODO""",
license="BSD",
setup_requires=["setuptools_scm"],
install_requires=["nmigen"],
install_requires=["nmigen~=0.1.rc1"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be part of this PR. Is there a special feature from nmigen 0.1rc1 that this PR requires?
In any case I don't think it makes sense to track releases yet, since everything is still in flux.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far the only issue with 0.1RC1 I have encountered is that what was called nmigen.tools is now nmigen.utils, and RC1 doesn't seem to give any backward compatibility. Since Minerva has already been updated to RC1, for the purpose of HeavyX nmigen-stdio does require 0.1RC1 in order to bulid the bitstream.

I also noticed nmigen-soc is using 0.1RC1. @whitequark may I know why 0.1RC1 is used there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably an oversight. Both nmigen-stdio and nmigen-soc should require nmigen~=X where X is the latest stable version, currently 0.1.

from ..spiflash import *


def simulation_test(dut, process):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be an option to look at the VCD manually, but the test should be ideally self-checking.

@ghost
Copy link
Author

ghost commented Jan 3, 2020

I factored out the USRMCLK primitive and fixed most of the styling on f87fa5e.

Currently test_spiflash.py only asserts whether the data read by the SPI readers match the memory content of a simulated SPI flash device; looking at the VCD is not necessary.

I haven't changed the nMigen version number lest it hasn't been finalised.

@ghost ghost force-pushed the spi branch 2 times, most recently from 7c592d2 to 5406337 Compare January 11, 2020 08:40
@ghost ghost changed the title Add an SPI controller for reading spiflash: A proposed SPI controller for reading Jan 30, 2020
* N28Q125A calls the 1-MISO 1-MOSI protocol "extended" because it supports sending the command on 1 pin while receiving the data on 2 or 4 pins like "dual" or "quad".
@mithro
Copy link

mithro commented Feb 6, 2020

@HarryHo90sHK you might find some of the code I started working on at https://github.com/mithro/litex/tree/d7184b97494012a8c21ee93df231b758a61e9dec/litex/soc/cores/spi useful. It was suppose to create a spiflash module system like the DRAM module system in LiteDRAM.

@ghost ghost force-pushed the spi branch 4 times, most recently from f44b9f6 to c52d386 Compare February 6, 2020 10:23
@ghost ghost force-pushed the spi branch 3 times, most recently from d819dae to 5833e63 Compare February 6, 2020 10:37
@ghost ghost force-pushed the spi branch 2 times, most recently from cb6366f to ef12c2a Compare February 7, 2020 14:36
@ghost ghost force-pushed the spi branch 2 times, most recently from b88ea15 to 3b2619a Compare February 7, 2020 18:34
@ghost
Copy link
Author

ghost commented Apr 23, 2020

6a1a23c fixed a typo only. Thank you @mithro for the comment and I think it is possible to adopt better encapsulation on the SPI logic. Essentially, an SPI master performs the following sequence in all types of READ commands:

Type Duration Direction
Command equivalent of sending 8 bits Master → Slave
Address equivalent of sending 24 bits Master → Slave
Dummy Cycles ≥0 cycles --
Data equivalent of sending ≥1 byte Slave → Master

Adding support for all CPOL/CPHA pairs might be useful, though the N25Q128A chip I have been testing with only uses (0,0) and (1,1), not (0,1) or (1,0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants