How to byte program SPI flash via QSPI

Document created by Jing Pan Employee on Dec 11, 2017
Version 1Show Document
  • View in full screen mode

How to byte program SPI flash via QSPI

QSPI module are used in many Kinetis MCU, like K8x, K27/28 and KL8x. QSPI expands the internal flash range and can run in a fast speed. Compared to DSPI, QSPI is very complex and often takes a lot of time to learn. In KSDK there are two QSPI demo which shows how to program SPI flash in DMA mode and polling mode. Both of them program the QSPI flash with a word type array. But can the QSPI module program SPI Flash in byte? Yes, this article shows how to do it.

Device: FRDM_KL82Z

Tool: MCUXpresso IDE

Debug firmware: JLINK

I build the test project base on KL82 SDK/driver_example/qspi/polling_transfer. To byte program SPI flash, a new LUT item must be added.


   {/* Seq0 :Quad Read */

         /* CMD:       0xEB - Quad Read, Single pad */

         /* ADDR:       0x18 - 24bit address, Quad pads */

         /* DUMMY:     0x06 - 6 clock cyles, Quad pads */

         /* READ:       0x80 - Read 128 bytes, Quad pads */



       [32] = QSPI_LUT_SEQ(QSPI_CMD, QSPI_PAD_1, 0x02, QSPI_ADDR, QSPI_PAD_1, 0x18),

       [13] = QSPI_LUT_SEQ(QSPI_WRITE, QSPI_PAD_1, 0x1, 0, 0, 0),


       /* Match MISRA rule */

       [63] = 0};

This item tells system how to program a single byte.

Then when we write the data to TxBuffer, we must write the byte 4 times. This is because a write transaction on the flash with data size of less than 32 bits will lead to the removal of four data entry from Txbuffer. The valid bit will be used and the rest of the bits will be discard.

Then before we start programming, we must set the data size.



After byte program, we can see the result from 0x68000000.

Attachment is the demo project. You can find that 0x03 was written to 0x68000005 after running.