# Question about SPIFlash interface

**URL:** <https://forums.sifive.com/t/question-about-spiflash-interface/436>\
**Category:** Freedom E300\
**Created:** [March 29, 2017, 9:48am UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436 "2017-03-29T09:48:03Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![mune10](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/mune10/32/870_2.png) [@mune10](https://forums.sifive.com/u/mune10)\
**Post date:** [March 29, 2017, 9:48am UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436/1 "2017-03-29T09:48:04Z")

</div>

Does Freedom E300 supports “Quad” read access against the external QSPI flash chip?

I observed signals of the QSPI flash on HiFive1 board. All read access against an application code stored in the flash are single (0x03, read command) only. Also, I check the Chisel code of SPI (SPIFlash.scala). It seems they are configured as a single SPI operation.

regards,

---

<div class="post-metadata">

**Author:** ![mwachs5](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/mwachs5/32/13_2.png) [@mwachs5](https://forums.sifive.com/u/mwachs5)\
**Post date:** [March 29, 2017, 1:51pm UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436/2 "2017-03-29T13:51:35Z")

</div>

They are configured as single out of reset (to enable booting from a wide variety of SPI devices, at reset the HW uses a conservative access type). You can configure the QSPI interface from your SW. The Freedom E300 Platform manual describes how to change the command which is used for read accesses.

---

<div class="post-metadata">

**Author:** ![brucehoult](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/brucehoult/32/24_2.png) [@brucehoult](https://forums.sifive.com/u/brucehoult)\
**Post date:** [March 29, 2017, 2:09pm UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436/3 "2017-03-29T14:09:41Z")

</div>

Is how to disable (and later re-enable) the memory mapping documented?

I’d like to play with loading code into SRAM and then program a few pages of the upper part of the flash as a simple file system – maybe even JIT compile some new code and then run it from flash later.

I can figure out myself how to do the writing to flash, given the port addresses and the flash data sheet (which I have).

---

<div class="post-metadata">

**Author:** ![mwachs5](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/mwachs5/32/13_2.png) [@mwachs5](https://forums.sifive.com/u/mwachs5)\
**Post date:** [March 29, 2017, 4:54pm UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436/4 "2017-03-29T16:54:27Z")

</div>

See Chapter 13 of [https://dev.sifive.com/documentation/freedom-e300-platform-reference-manual/](https://dev.sifive.com/documentation/freedom-e300-platform-reference-manual/). Register `SPI_FCTRL` has a bit `EN` which defaults to 1, meaning by default the SPIFlash memory mapped interface is enabled. If you set this bit to 0, then the memory mapped interface is disabled and you can use the register interface to drive the SPIFlash interface. You can also change the command that the Flash interface will use once you re-enable the memory mapped interface using the `SPI_FFMT` register.

---

<div class="post-metadata">

**Author:** ![brucehoult](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/brucehoult/32/24_2.png) [@brucehoult](https://forums.sifive.com/u/brucehoult)\
**Post date:** [March 29, 2017, 7:23pm UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436/5 "2017-03-29T19:23:32Z")

</div>

Ahhhh. I already read the HIFive manual, the E3-Coreplex manual, the E310-G000 manual… One more 🙂

---

<div class="post-metadata">

**Author:** ![mune10](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/mune10/32/870_2.png) [@mune10](https://forums.sifive.com/u/mune10)\
**Post date:** [March 29, 2017, 10:46pm UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436/6 "2017-03-29T22:46:52Z")

</div>

I tried quad mode (0xEB) with HiFive1 board, but not works well. I also tried dual read mode (both 0xBB and 0x3B) . The dual mode works well. It seems the current QSPI interface design does not support sending address in quad mode. HiFive1 uses IS25LP128 that only supports 0xEB (both address and data are quad).

I also tested dual and quad mode with ArtyDevKit which has Micron N25Q128A. And confirmed the operation with quad read (0x6B, 1-1-4) mode. I use the following code to set the quad mode.

```
SPI0_REG(SPI_REG_FFMT) =
   SPI_INSN_CMD_EN |
   SPI_INSN_ADDR_LEN(3) |
   SPI_INSN_PAD_CNT(8) |
   SPI_INSN_CMD_PROTO(0) |
   SPI_INSN_ADDR_PROTO(0) |
   SPI_INSN_DATA_PROTO(2) |
   SPI_INSN_CMD_CODE(0x6b) |
   SPI_INSN_PAD_CODE(0x00);

```

Do you have any plan to support quad read (0xEB, 1-4-4) mode?

---

<div class="post-metadata">

**Author:** ![aou](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@aou](https://forums.sifive.com/u/aou)\
**Post date:** [March 31, 2017, 2:31am UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436/7 "2017-03-31T02:31:51Z")

</div>

> [@mune10](#):
>
> Do you have any plan to support quad read (0xEB, 1-4-4) mode?

The SPI controller on the HiFive1 is identical to the one on the Arty devkit, so it should support quad mode in the same way. How are you setting `SPI_REG_FFMT` for quad reads (0xEB)? Note that IS25LP128 expects 6 dummy cycles by default when using command 0xEB.

---

<div class="post-metadata">

**Author:** ![mune10](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/mune10/32/870_2.png) [@mune10](https://forums.sifive.com/u/mune10)\
**Post date:** [March 31, 2017, 8:11am UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436/8 "2017-03-31T08:11:05Z")

</div>

I tested several dummy cycles. Access cycles are looks good. The problem is that DQ3 is always high during the address cycle. Thus it read out data of wrong address.

---

<div class="post-metadata">

**Author:** ![sflin](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@sflin](https://forums.sifive.com/u/sflin)\
**Post date:** [March 31, 2017, 4:33pm UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436/9 "2017-03-31T16:33:58Z")

</div>

At first I was confused, too.  
I think there should be a list of terminology somewhere on this site or documents.

Here are my understandings;

- Freedom Unleashed: An high-end FPGA platform implements E300 Platform
- Freedom Everywhere: An low-end FPGA platform implements E300 Platform
- HiFive1 board: A board on which E310-G000 Soc is
- E310-G000 SoC: An SoC implementing E300 Platform
- E300 Platform: An SoC system architecture including E3 Coreplex Series
- E31 Complex: An CPU core implementing E3 Coreplex Series.
- E3 Coreplex Series: An CPU core architecture including RISC-V CPU core and some functions.

For example the E310-G000 SoC manual only includes implementation-specific specifications of E300 Platform architecture.

---

<div class="post-metadata">

**Author:** ![DrewatSiFive](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@DrewatSiFive](https://forums.sifive.com/u/DrewatSiFive)\
**Post date:** [April 3, 2017, 8:42pm UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436/10 "2017-04-03T20:42:09Z")

</div>

Hi Seiji,

Thanks for reporting this. We have verified that there is an issue which can cause the behavior you are seeing on DQ3. We are still working internally to understand the full extent of the issue and will update this thread once we have more information.

---

<div class="post-metadata">

**Author:** ![DrewatSiFive](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@DrewatSiFive](https://forums.sifive.com/u/DrewatSiFive)\
**Post date:** [April 13, 2017, 1:37am UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436/11 "2017-04-13T01:37:00Z")

</div>

Hi All, Following up on this there are 2 issues related to our SPI controller:

**Issue 1** :

**Issue** : The output enable signal for DQ[3] is not driven properly.

**Devices affected** : FE310-G000, FPGA bit files we made available before 5/2

**Symptoms** : Address and write data using DQ[3] for transmission will not  
function properly. Reads using DQ[3] are unaffected.

**Workaround** :  
Do not use opcode 0xEB in the Extended SPI protocol. In some devices, this  
command is also referred to as QUAD INPUT/OUTPUT FAST READ.  
Do not use the Native Quad SPI Protocol. In some devices, this command is  
also referred to as FAST READ.

* * *

**Issue 2** :

**Issue** : Certain frame lengths do not work properly.

**Device affected** : FE310-G000, FPGA bit files we made available before 5/2

**Symptoms** : Certain frame lengths do not work, and will result in the master  
sending one extra clock pulse. The slave device may then become out of  
sync.

**Workaround** :  
The following frame lengths are supported and can be used. Do not use  
other frame lengths.

- Serial: 0, 2, 4, 6, 8
- Dual: 0, 1, 3, 5, 7, 8
- Quad: 0, 1, 2, 3, 5, 6, 7, 8

* * *

These will be officially documented as errata in future documentation related to the FE310-G000. The FPGA bitstreams will be updated with new versions of the SPI controller soon.

Thanks again for reporting this.

---

<div class="post-metadata">

**Author:** ![mune10](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/mune10/32/870_2.png) [@mune10](https://forums.sifive.com/u/mune10)\
**Post date:** [May 3, 2017, 1:52pm UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436/12 "2017-05-03T13:52:09Z")

</div>

I have another question about the SiFive QSPIFlash interface. The IO and MMAP modes of QSPIFlash interface seems exclusive. So that an XIP application in Flash cannot write data to the same Flash by switching the mode from MMAP to IO. This will crash the application since the CPU cannot fetch the subsequent instruction from memory mapped Flash anymore after the IO mode change. Is this correct?

---

<div class="post-metadata">

**Author:** ![brucehoult](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/brucehoult/32/24_2.png) [@brucehoult](https://forums.sifive.com/u/brucehoult)\
**Post date:** [May 3, 2017, 2:07pm UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436/13 "2017-05-03T14:07:57Z")

</div>

That is correct.

You need to copy any necessary code and data into the SRAM before disabling the MMAP for the flash.

You could in theory also use code already in the instruction cache (loaded from flash), but it’s not easy to arrange this without actually running the code in some kind of dummy mode as there are no cache prefetch instructions. It would also be very bad if any of the cached code had a conflict and was evicted!

---

<div class="post-metadata">

**Author:** ![mune10](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/mune10/32/870_2.png) [@mune10](https://forums.sifive.com/u/mune10)\
**Post date:** [May 3, 2017, 2:13pm UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436/14 "2017-05-03T14:13:53Z")

</div>

Thanks. Can we use the data scratch pad to store and run the code?

Or we attach another Flash memory at the second SPI interface as for data storage.

---

<div class="post-metadata">

**Author:** ![mwachs5](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/mwachs5/32/13_2.png) [@mwachs5](https://forums.sifive.com/u/mwachs5)\
**Post date:** [May 3, 2017, 3:05pm UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436/15 "2017-05-03T15:05:02Z")

</div>

You can use the data scratchpad to store and run the code. This is the ideal thing to do if your program fits in the scratchpad. So you can run a program with SPI flash which copies the small program into Scrachpad and jump to it there.

---

<div class="post-metadata">

**Author:** ![mune10](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/mune10/32/870_2.png) [@mune10](https://forums.sifive.com/u/mune10)\
**Post date:** [May 3, 2017, 4:01pm UTC](https://forums.sifive.com/t/question-about-spiflash-interface/436/16 "2017-05-03T16:01:24Z")

</div>

I see. Thanks Megan.
