qspips
Vitis Drivers API Documentation
 All Data Structures Files Functions Variables Typedefs Groups Pages
xqspips_g128_flash_example.c File Reference

Overview

Implements a design example using the QSPI driver (XQspiPs) with a serial Flash device greater than 128Mb.

The example writes to flash and reads it back in I/O mode. The example performs some transfers in Auto mode and Manual start mode, to illustrate the modes available. It is recommended to use Manual CS + Auto start for best performance. The example illustrates single, parallel and stacked modes. Both the flash devices have to be of the same make and size. The hardware which this example runs on, must have a serial Flash (Micron N25Q or Spansion S25FL) for it to run. The example has been tested with the Micron Serial Flash (N25Q256, N25Q512 & N25Q00AA) and Spansion (S25FL256 & S25FL512)

MODIFICATION HISTORY:
Ver   Who Date     Changes


2.02a hk 05/07/13 First release raw 12/10/15 Added support for Macronix 256Mb and 1Gb flash parts ms 04/05/17 Modified Comment lines in functions to recognize it as documentation block for doxygen generation. tjs 06/16/17 Added support for IS25LP256D flash part (PR-4650) 3.10 akm 08/17/22 Fix logical error in NumSect calculation. 3.11 akm 07/10/23 Add support for system device-tree flow for example. 3.14 sb 03/25/25 Fixed gcc and g++ warnings. 3.15 vlt 12/18/25 Update Doxygen comments to include SDT flow details. 3.16 vn 08/26/26 Fix Doxygen warnings 3.16 tb 09/30/26 Align Doxygen comments with AMD documentation standards

#include "xqspips.h"
#include "xil_printf.h"

Macros

#define WRITE_STATUS_CMD   0x01
 Write status register command. More...
 
#define WRITE_CMD   0x02
 Page program command. More...
 
#define READ_CMD   0x03
 Normal read command. More...
 
#define WRITE_DISABLE_CMD   0x04
 Write disable command. More...
 
#define READ_STATUS_CMD   0x05
 Read status register command. More...
 
#define WRITE_ENABLE_CMD   0x06
 Write enable command. More...
 
#define FAST_READ_CMD   0x0B
 Fast read command. More...
 
#define DUAL_READ_CMD   0x3B
 Dual read command. More...
 
#define QUAD_READ_CMD   0x6B
 Quad read command. More...
 
#define BULK_ERASE_CMD   0xC7
 Bulk erase command. More...
 
#define SEC_ERASE_CMD   0xD8
 Sector erase command. More...
 
#define READ_ID   0x9F
 Read ID command. More...
 
#define READ_CONFIG_CMD   0x35
 Read config register command. More...
 
#define WRITE_CONFIG_CMD   0x01
 Write config register command. More...
 
#define BANK_REG_RD   0x16
 Bank register read. More...
 
#define BANK_REG_WR   0x17
 Bank register write. More...
 
#define EXTADD_REG_RD   0xC8
 Extended Address Register read; Micron name for the Bank register. More...
 
#define EXTADD_REG_WR   0xC5
 Extended address register write. More...
 
#define DIE_ERASE_CMD   0xC4
 Die erase command. More...
 
#define READ_FLAG_STATUS_CMD   0x70
 Read flag status command. More...
 
#define COMMAND_OFFSET   0
 Flash instruction. More...
 
#define ADDRESS_1_OFFSET   1
 MSB byte of address to read or write. More...
 
#define ADDRESS_2_OFFSET   2
 Middle byte of address to read or write. More...
 
#define ADDRESS_3_OFFSET   3
 LSB byte of address to read or write. More...
 
#define DATA_OFFSET   4
 Start of Data for Read/Write. More...
 
#define DUMMY_OFFSET   4
 Dummy byte offset for fast, dual and quad reads. More...
 
#define DUMMY_SIZE   1
 Number of dummy bytes for fast, dual and quad reads. More...
 
#define RD_ID_SIZE   4
 Read ID command + 3 bytes ID response. More...
 
#define BULK_ERASE_SIZE   1
 Bulk Erase command size. More...
 
#define SEC_ERASE_SIZE   4
 Sector Erase command + Sector address. More...
 
#define BANK_SEL_SIZE   2
 BRWR or EARWR command + 1 byte bank value. More...
 
#define RD_CFG_SIZE   2
 1 byte Configuration register + RD CFG command. More...
 
#define WR_CFG_SIZE   3
 WRR command + 1 byte each Status and Config Reg. More...
 
#define DIE_ERASE_SIZE   4
 Die Erase command + Die address. More...
 
#define OVERHEAD_SIZE   4
 Command and address byte count. More...
 
#define FLASH1BASE   0x0000000
 Base address of Flash1. More...
 
#define SIXTEENMB   0x1000000
 Sixteen MB. More...
 
#define FLASH_QUAD_EN_MASK   0x02
 Mask for quad enable bit in Flash configuration register. More...
 
#define FLASH_SRWD_MASK   0x80
 Status register write disable bit mask. More...
 
#define BANKMASK   0xF000000
 Bank mask. More...
 
#define MICRON_ID_BYTE0   0x20
 Micron manufacturer ID. More...
 
#define MICRON_ID_BYTE2_128   0x18
 Micron 128Mbit size ID. More...
 
#define MICRON_ID_BYTE2_256   0x19
 Micron 256Mbit size ID. More...
 
#define MICRON_ID_BYTE2_512   0x20
 Micron 512Mbit size ID. More...
 
#define MICRON_ID_BYTE2_1G   0x21
 Micron 1Gbit size ID. More...
 
#define SPANSION_ID_BYTE0   0x01
 Spansion manufacturer ID. More...
 
#define SPANSION_ID_BYTE2_128   0x18
 Spansion 128Mbit size ID. More...
 
#define SPANSION_ID_BYTE2_256   0x19
 Spansion 256Mbit size ID. More...
 
#define SPANSION_ID_BYTE2_512   0x20
 Spansion 512Mbit size ID. More...
 
#define WINBOND_ID_BYTE0   0xEF
 Winbond manufacturer ID. More...
 
#define WINBOND_ID_BYTE2_128   0x18
 Winbond 128Mbit size ID. More...
 
#define MACRONIX_ID_BYTE0   0xC2
 Macronix manufacturer ID. More...
 
#define MACRONIX_ID_BYTE2_256   0x19
 Macronix 256Mbit size ID. More...
 
#define MACRONIX_ID_BYTE2_512   0x1A
 Macronix 512Mbit size ID. More...
 
#define MACRONIX_ID_BYTE2_1G   0x1B
 Macronix 1Gbit size ID. More...
 
#define ISSI_ID_BYTE0   0x9D
 ISSI manufacturer ID. More...
 
#define ISSI_ID_BYTE2_256   0x19
 ISSI 256Mbit size ID. More...
 
#define SPANSION_INDEX_START   0
 Spansion start index. More...
 
#define FLASH_CFG_TBL_SINGLE_128_SP   SPANSION_INDEX_START
 Spansion 128Mbit single mode config table index. More...
 
#define FLASH_CFG_TBL_STACKED_128_SP   (SPANSION_INDEX_START + 1)
 Spansion 128Mbit stacked mode config table index. More...
 
#define FLASH_CFG_TBL_PARALLEL_128_SP   (SPANSION_INDEX_START + 2)
 Spansion 128Mbit parallel mode config table index. More...
 
#define FLASH_CFG_TBL_SINGLE_256_SP   (SPANSION_INDEX_START + 3)
 Spansion 256Mbit single mode config table index. More...
 
#define FLASH_CFG_TBL_STACKED_256_SP   (SPANSION_INDEX_START + 4)
 Spansion 256Mbit stacked mode config table index. More...
 
#define FLASH_CFG_TBL_PARALLEL_256_SP   (SPANSION_INDEX_START + 5)
 Spansion 256Mbit parallel mode config table index. More...
 
#define FLASH_CFG_TBL_SINGLE_512_SP   (SPANSION_INDEX_START + 6)
 Spansion 512Mbit single mode config table index. More...
 
#define FLASH_CFG_TBL_STACKED_512_SP   (SPANSION_INDEX_START + 7)
 Spansion 512Mbit stacked mode config table index. More...
 
#define FLASH_CFG_TBL_PARALLEL_512_SP   (SPANSION_INDEX_START + 8)
 Spansion 512Mbit parallel mode config table index. More...
 
#define MICRON_INDEX_START   (FLASH_CFG_TBL_PARALLEL_512_SP + 1)
 Micron start index. More...
 
#define FLASH_CFG_TBL_SINGLE_128_MC   MICRON_INDEX_START
 Micron 128Mbit single mode config table index. More...
 
#define FLASH_CFG_TBL_STACKED_128_MC   (MICRON_INDEX_START + 1)
 Micron 128Mbit stacked mode config table index. More...
 
#define FLASH_CFG_TBL_PARALLEL_128_MC   (MICRON_INDEX_START + 2)
 Micron 128Mbit parallel mode config table index. More...
 
#define FLASH_CFG_TBL_SINGLE_256_MC   (MICRON_INDEX_START + 3)
 Micron 256Mbit single mode config table index. More...
 
#define FLASH_CFG_TBL_STACKED_256_MC   (MICRON_INDEX_START + 4)
 Micron 256Mbit stacked mode config table index. More...
 
#define FLASH_CFG_TBL_PARALLEL_256_MC   (MICRON_INDEX_START + 5)
 Micron 256Mbit parallel mode config table index. More...
 
#define FLASH_CFG_TBL_SINGLE_512_MC   (MICRON_INDEX_START + 6)
 Micron 512Mbit single mode config table index. More...
 
#define FLASH_CFG_TBL_STACKED_512_MC   (MICRON_INDEX_START + 7)
 Micron 512Mbit stacked mode config table index. More...
 
#define FLASH_CFG_TBL_PARALLEL_512_MC   (MICRON_INDEX_START + 8)
 Micron 512Mbit parallel mode config table index. More...
 
#define FLASH_CFG_TBL_SINGLE_1GB_MC   (MICRON_INDEX_START + 9)
 Micron 1Gbit single mode config table index. More...
 
#define FLASH_CFG_TBL_STACKED_1GB_MC   (MICRON_INDEX_START + 10)
 Micron 1Gbit stacked mode config table index. More...
 
#define FLASH_CFG_TBL_PARALLEL_1GB_MC   (MICRON_INDEX_START + 11)
 Micron 1Gbit parallel mode config table index. More...
 
#define WINBOND_INDEX_START   (FLASH_CFG_TBL_PARALLEL_1GB_MC + 1)
 Winbond start index. More...
 
#define FLASH_CFG_TBL_SINGLE_128_WB   WINBOND_INDEX_START
 Winbond 128Mbit single mode config table index. More...
 
#define FLASH_CFG_TBL_STACKED_128_WB   (WINBOND_INDEX_START + 1)
 Winbond 128Mbit stacked mode config table index. More...
 
#define FLASH_CFG_TBL_PARALLEL_128_WB   (WINBOND_INDEX_START + 2)
 Winbond 128Mbit parallel mode config table index. More...
 
#define MACRONIX_INDEX_START   (FLASH_CFG_TBL_PARALLEL_128_WB + 1 - 3)
 Macronix start index. More...
 
#define FLASH_CFG_TBL_SINGLE_256_MX   MACRONIX_INDEX_START
 Macronix 256Mbit single mode config table index. More...
 
#define FLASH_CFG_TBL_STACKED_256_MX   (MACRONIX_INDEX_START + 1)
 Macronix 256Mbit stacked mode config table index. More...
 
#define FLASH_CFG_TBL_PARALLEL_256_MX   (MACRONIX_INDEX_START + 2)
 Macronix 256Mbit parallel mode config table index. More...
 
#define FLASH_CFG_TBL_SINGLE_512_MX   (MACRONIX_INDEX_START + 3)
 Macronix 512Mbit single mode config table index. More...
 
#define FLASH_CFG_TBL_STACKED_512_MX   (MACRONIX_INDEX_START + 4)
 Macronix 512Mbit stacked mode config table index. More...
 
#define FLASH_CFG_TBL_PARALLEL_512_MX   (MACRONIX_INDEX_START + 5)
 Macronix 512Mbit parallel mode config table index. More...
 
#define FLASH_CFG_TBL_SINGLE_1G_MX   (MACRONIX_INDEX_START + 6)
 Macronix 1Gbit single mode config table index. More...
 
#define FLASH_CFG_TBL_STACKED_1G_MX   (MACRONIX_INDEX_START + 7)
 Macronix 1Gbit stacked mode config table index. More...
 
#define FLASH_CFG_TBL_PARALLEL_1G_MX   (MACRONIX_INDEX_START + 8)
 Macronix 1Gbit parallel mode config table index. More...
 
#define ISSI_INDEX_START   (FLASH_CFG_TBL_PARALLEL_1G_MX + 1)
 ISSI start index. More...
 
#define FLASH_CFG_TBL_SINGLE_256_ISSI   ISSI_INDEX_START
 ISSI 256Mbit single mode config table index. More...
 
#define FLASH_CFG_TBL_STACKED_256_ISSI   (ISSI_INDEX_START + 1)
 ISSI 256Mbit stacked mode config table index. More...
 
#define FLASH_CFG_TBL_PARALLEL_256_ISSI   (ISSI_INDEX_START + 2)
 ISSI 256Mbit parallel mode config table index. More...
 
#define LQSPI_CR_FAST_QUAD_READ   0x0000006B
 Fast Quad Read output. More...
 
#define LQSPI_CR_1_DUMMY_BYTE   0x00000100
 1 Dummy Byte between address and return data. More...
 
#define DUAL_STACK_CONFIG_WRITE
 LQSPI configuration register value for dual stacked flash mode. More...
 
#define DUAL_QSPI_CONFIG_WRITE
 LQSPI configuration register value for dual parallel flash mode. More...
 
#define PAGE_COUNT   32
 Number of flash pages to be written. More...
 
#define MAX_PAGE_SIZE   1024
 Max page size to initialize write and read buffer. More...
 
#define TEST_ADDRESS   0x000000
 Flash address to which data is to be written. More...
 
#define UNIQUE_VALUE   0x06
 Start value of the data pattern. More...
 

Functions

int QspiG128FlashExample (XQspiPs *QspiInstancePtr, UINTPTR BaseAddress)
 Illustrates how to use the XQspiPs device driver in single, parallel and stacked modes using flash devices greater than 128Mb. More...
 
void FlashErase (XQspiPs *QspiPtr, u32 Address, u32 ByteCount, u8 *WriteBfrPtr)
 Erases the sectors in the serial Flash connected to the QSPI interface. More...
 
void FlashWrite (XQspiPs *QspiPtr, u32 Address, u32 ByteCount, u8 Command, u8 *WriteBfrPtr)
 Writes to the serial Flash connected to the QSPI interface. More...
 
int FlashReadID (XQspiPs *QspiPtr, u8 *WriteBfrPtr, u8 *ReadBfrPtr)
 Reads serial Flash ID connected to the SPI interface. More...
 
void FlashRead (XQspiPs *QspiPtr, u32 Address, u32 ByteCount, u8 Command, u8 *WriteBfrPtr, u8 *ReadBfrPtr)
 Performs an I/O read. More...
 
int SendBankSelect (XQspiPs *QspiPtr, u8 *WriteBfrPtr, u32 BankSel)
 Selects the current bank. More...
 
void BulkErase (XQspiPs *QspiPtr, u8 *WriteBfrPtr)
 Performs a bulk erase operation when the flash device has a single die. More...
 
void DieErase (XQspiPs *QspiPtr, u8 *WriteBfrPtr)
 Performs a die erase operation on all the die in the flash device. More...
 
u32 GetRealAddr (XQspiPs *QspiPtr, u32 Address)
 Translates the address based on the type of interconnection. More...
 
int main (void)
 Runs the QSPI greater than 128Mb flash example. More...
 

Variables

FlashInfo Flash_Config_Table [34]
 Flash Config Table. More...
 
u32 FlashMake
 Flash manufacturer ID. More...
 
u32 FCTIndex
 Flash configuration table index. More...
 
int Test = 1
 The following variable allows a test value to be added to the values that are written to the Flash such that unique values can be generated to guarantee the writes to the Flash were successful. More...
 
u8 ReadBuffer [(PAGE_COUNT *MAX_PAGE_SIZE)+(DATA_OFFSET+DUMMY_SIZE)*8]
 The following variables hold the data read from and written to the flash and they are global to avoid having large buffers on the stack. More...
 
u8 WriteBuffer [(PAGE_COUNT *MAX_PAGE_SIZE)+DATA_OFFSET]
 Write buffer. More...
 
u32 MaxData = PAGE_COUNT*256
 The following constants specify the max amount of data and the size of the the buffer required to hold the data and overhead to transfer the data to and from the Flash. More...