3 Replies Latest reply on Nov 13, 2020 1:49 PM by ApurvaS_36

    Serial Flash Library interfacing with external flash

    XiGa_1309021

      Hello,

       

      I am using the Serial Flash library to interface with an external flash IS25LQ016B.

       

      The hardware connection is QSPI, which has 4 data lines connected to the flash.

       

      To enable the QSPI of the flash, there is a QE bit that needs to be set before we can use the QSPI interface.

      The way to do that is to use regular SPI. Otherwise, the library cannot talk to the flash.

      So what I did is to initialized with 2 I/O with regular SPI.

       

      cy_serial_flash_qspi_init(smifMemConfigs[0], xmos_qspi_io0, xmos_qspi_io1, NC, NC, NC, NC, NC, NC, xmos_qspi_sck, xmos_qspi_cs_b, QSPI_BUS_FREQUENCY_HZ);
      

      In this function, it will actually enable the Quad mode by setting the QE bit, then the cy_serial_flash_qspi_write(), and cy_serial_flash_qspi_read() doesn't work as it will need QSPI interface, but the code is set up as normal SPI.

       

      Then I changed the code to:

      cy_serial_flash_qspi_init(smifMemConfigs[0], xmos_qspi_io0, xmos_qspi_io1, xmos_qspi_io2, xmos_qspi_io3, NC, NC, NC, NC, xmos_qspi_sck, xmos_qspi_cs_b, QSPI_BUS_FREQUENCY_HZ);
      

      So that PSoC works in QSPI mode since the QE bit is in NVM, it is set even with power cycling, so the read and write API works fine in this case.

       

       

      Does this make sense? or I miss something here.

       

      If the serial flash needs SPI to set the QE bit for the first time and then the PSoC has to switch to QSPI mode, what is the correct way to do that?

      Just call the init functions with different parameters sequentially?

       

       

      Thanks,

      Xiang

        • 1. Re: Serial Flash Library interfacing with external flash
          ApurvaS_36

          Hi Xiang,

           

          I would like to suggest you to go over the QSPI Flash Read and Write code example. The code example is written for interfacing Cypress flash with PSoC 6 and I would like to confirm that enabling QSPI mode of Cypress flash also works in the exact same manner as you have mentioned about IS25LQ016B.

          When the code example is run for the first time on a new flash device, the flash is in SPI mode by default. The cy_serial_flash_qspi_init() function still initializes all 4 I/O lines. Inside the Init function, the QE bit is read and checked if Quad mode is enabled or not. If Quad mode is not enabled, QE bit is set. You can avoid the extra step of initializing twice.

           

          However, If the method mentioned by you works for you then it should not be a problem.

           

          - Apurva

          • 2. Re: Serial Flash Library interfacing with external flash
            XiGa_1309021

            Hi Apurva,

             

            Thanks for your reply.

             

            When you say that the cy_serial_flash_qspi_init() function will initialize all 4 I/O pins, then based on my test it will also use the QSPI to read the QE bit, which will fail for the first time for the serial flash as the QE bit is not set out of the factory. 

             

            The serial flash module is an abstraction layer that can be based on the SPI, QSPI and Octal SPI module, for the user, how do we specify this in the code?

            I don't see an API or macro config associated with that.

             

            My observation is that if I put two pins in the cy_serial_flash_qspi_init() function, then it will use SPI for the whole program

            If I put 4 pins in the cy_serial_flash_qspi_init() function, then it will use QSPI.

             

            Xiang

            • 3. Re: Serial Flash Library interfacing with external flash
              ApurvaS_36

              Hi Xiang,

               

              I went through this datasheet of IS25LQ016B flash device. Hopefully it is the correct datasheet, and if not, then please point me to the right document.

              As per my understanding, the working of Cypress flash devices and IS25LQ016B device is similar in terms of enabling quad mode in the flash part.

               

              In IS25LQ016B part, The Quad Enable bit is the 6th bit of the Status Register and the command to read and write to this register is RDSR (05h) and WRSR (01h), respectively. There is no quad command for reading and writing to Status Register and these commands will always use only SI and SO lines. Irrespective of Whether quad mode has been enabled in the flash device or not, these commands will always make use of only two IO lines. This is also how Cypress flash devices work.

              Please correct me if I am wrong.

               

              >>based on my test it will also use the QSPI to read the QE bit, which will fail for the first time for the serial flash as the QE bit is not set out of the factory

              Can you please elaborate about the tests you have performed? Do you mean IS25LQ016B device uses four lines to read and write to the SR?

               

              - Apurva