Pregunta

I'm going to write an SPI driver for an ARM devlopment board. It is not used with Linux.

Yesterday, I read the QSPI driver that Xilinx provided and I tried it successfully. However, I would really like to write my own SPI driver.

Here are my questions:

  1. What is the difference between QSPI and SPI on usage?
  2. If I write a driver based on QSPI, will it work?
  3. If I write a driver from scratch, what is the basic procedure (READ / WRITE / INITIALIZE)?
  4. And finally, why must SPI send and receive at the same time?

Thanks everybody.

¿Fue útil?

Solución

I think it may be easier to start with your last question first.

Why must SPI send and receive at the same time?

The easy answer is that it is part of the protocol. As data is shifted out on the MOSI line from the Master to the Slave, the data in the Slave's buffer is shifted to the Master on the MISO line. This allows the hardware to use a single register in each device for both the data being sent and the data being received. There is a good diagram of the process here:

http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus

The not so easy answer is that SPI is not a well defined standard. There are different types of implementation depending on the devices you are using. There is even a variant where the MOSI and MISO lines are combined and used in a bi-directional manner (3-wire SPI). However, most of the implementations I have dealt with send and receive over two different lines and that tends to be the standard methodology.

What is the difference between QSPI and SPI on usage?

QSPI or Quad SPI actually does not adhere to the standard methodology and breaks the concept of sending and receiving at the same time. It utilizes four bi-directional I/O lines to send and receive data and is often used for memory applications (because it is faster than SPI). With QSPI you are not sending and receiving at the same time.

If I write a driver based on QSPI, will it work?

Certainly! You just have to familiarize yourself with the hardware that you are using. Again, SPI is very different from Quad SPI and you can often find hardware implementations that make it very easy to use QSPI. For example, your Zynq 7000 has a QSPI Controller that has a lot of features to simplify the coding process. It will also operate in a "legacy mode" that acts as a normal SPI controller. On top of that, the Zynq 7000 has two other standard SPI controllers that are not setup for QSPI. I would highly encourage you to read the technical documentation here:

http://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf

If I write a driver from scratch, what is the basic procedure?

That is very hardware dependent. I did a quick overview of your hardware, but detailing the steps here would take far too long. However, the technical manual for your device appears to have great step-by-step instructions for configuring and using both the QSPI and SPI controllers. Here is an example from the SPI section:

17.3.1 Start-up Sequence

Example: Start-up Sequence

  1. Reset controller: Assert and de-assert the Ref and CPU_1x resets, refer to section 17.4.1 Resets.
  2. Program clocks: Program the SPI_Ref_Clk, refer to section 17.4.2 Clocks.
  3. Tx/Rx signal routing: Refer to section 17.5 I/O Interfaces.
  4. Controller configuration: Refer to section 17.3.2 Controller Configuration.
  5. Interrupt configuration: Configure the ISR to handle the interrupt conditions. The simplest ISR reads data from the RxFIFO and writes content to the TxFIFO. The PS interrupt controller is described in Chapter 7, Interrupts. The interrupt mechanism for the SPI controller is described in section 17.3.5 Interrupt Service Routine.
  6. Start data transfers:

    Master Mode operation select: Manual/Auto start and SS, refer to section 17.3.3 Master Mode Data Transfer.

    Slave Mode operation, refer to section 17.3.4 Slave Mode Data Transfer.

I hope that helps!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top