qspips
Vitis Drivers API Documentation
xqspips_g128_flash_example.c File Reference

Overview

This file contains 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. This examples 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. This 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. This example has been tested with the Micron Serial Flash (N25Q256, N25Q512 & N25Q00AA) and Spansion (S25FL256 & S25FL512)

Note

None.

 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.

Functions

int QspiG128FlashExample (XQspiPs *QspiInstancePtr, u16 QspiDeviceId)
 The purpose of this function is to illustrate 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)
 This function 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)
 This function writes to the serial Flash connected to the QSPI interface. More...
 
int FlashReadID (XQspiPs *QspiPtr, u8 *WriteBfrPtr, u8 *ReadBfrPtr)
 This function reads serial Flash ID connected to the SPI interface. More...
 
void FlashRead (XQspiPs *QspiPtr, u32 Address, u32 ByteCount, u8 Command, u8 *WriteBfrPtr, u8 *ReadBfrPtr)
 This function performs an I/O read. More...
 
int SendBankSelect (XQspiPs *QspiPtr, u8 *WriteBfrPtr, u32 BankSel)
 This functions selects the current bank. More...
 
void BulkErase (XQspiPs *QspiPtr, u8 *WriteBfrPtr)
 This functions performs a bulk erase operation when the flash device has a single die. More...
 
void DieErase (XQspiPs *QspiPtr, u8 *WriteBfrPtr)
 This functions performs a die erase operation on all the die in the flash device. More...
 
u32 GetRealAddr (XQspiPs *QspiPtr, u32 Address)
 This functions translates the address based on the type of interconnection. More...
 
int main (void)
 Main function to call the QSPI Flash example. More...
 

Variables

FlashInfo Flash_Config_Table [34]
 Flash Config Table. More...
 

Function Documentation

void BulkErase ( XQspiPs QspiPtr,
u8 *  WriteBfrPtr 
)

This functions performs a bulk erase operation when the flash device has a single die.

Works for both Spansion and Micron

Parameters
QspiPtris a pointer to the QSPI driver component to use.
WriteBfrPtris the pointer to command+address to be sent
Returns
None
Note
None.

References XQspiPs_PolledTransfer().

Referenced by FlashErase().

void DieErase ( XQspiPs QspiPtr,
u8 *  WriteBfrPtr 
)

This functions performs a die erase operation on all the die in the flash device.

This function uses the die erase command for Micron 512Mbit and 1Gbit

Parameters
QspiPtris a pointer to the QSPI driver component to use.
WriteBfrPtris the pointer to command+address to be sent
Returns
None
Note
None.

References Flash_Config_Table, SendBankSelect(), and XQspiPs_PolledTransfer().

Referenced by FlashErase().

void FlashErase ( XQspiPs QspiPtr,
u32  Address,
u32  ByteCount,
u8 *  WriteBfrPtr 
)

This function erases the sectors in the serial Flash connected to the QSPI interface.

Parameters
QspiPtris a pointer to the QSPI driver component to use.
Addresscontains the address of the first sector which needs to be erased.
ByteCountcontains the total size to be erased.
WriteBfrPtris Pointer to the write buffer (which is to be transmitted)
Returns
None.
Note
None.

References BulkErase(), XQspiPs::Config, XQspiPs_Config::ConnectionMode, DieErase(), Flash_Config_Table, GetRealAddr(), SendBankSelect(), XQspiPs_GetLqspiConfigReg, XQSPIPS_LQSPI_CR_U_PAGE_MASK, XQspiPs_PolledTransfer(), XQspiPs_SetLqspiConfigReg, and XQspiPs_SetSlaveSelect().

void FlashRead ( XQspiPs QspiPtr,
u32  Address,
u32  ByteCount,
u8  Command,
u8 *  WriteBfrPtr,
u8 *  ReadBfrPtr 
)

This function performs an I/O read.

Parameters
QspiPtris a pointer to the QSPI driver component to use.
Addresscontains the address of the first sector which needs to be erased.
ByteCountcontains the total size to be erased.
Commandis the command used to read data from the flash. Supports normal, fast, dual and quad read commands.
WriteBfrPtris pointer to the write buffer which contains data to be transmitted
ReadBfrPtris pointer to the read buffer to which valid received data should be written
Returns
none.
Note
None.

References Flash_Config_Table, GetRealAddr(), SendBankSelect(), and XQspiPs_PolledTransfer().

int FlashReadID ( XQspiPs QspiPtr,
u8 *  WriteBfrPtr,
u8 *  ReadBfrPtr 
)

This function reads serial Flash ID connected to the SPI interface.

It then deduces the make and size of the flash and obtains the connection mode to point to corresponding parameters in the flash configuration table. The flash driver will function based on this and it presently supports Micron and Spansion - 128, 256 and 512Mbit and Winbond 128Mbit

Parameters
QspiPtris a pointer to the QSPI driver component to use.
WriteBfrPtris pointer to the write buffer (which is to be transmitted)
ReadBfrPtris pointer to the read buffer to which valid received data should be written.
Returns
XST_SUCCESS if read id, otherwise XST_FAILURE.
Note
None.

References XQspiPs::Config, XQspiPs_Config::ConnectionMode, and XQspiPs_PolledTransfer().

void FlashWrite ( XQspiPs QspiPtr,
u32  Address,
u32  ByteCount,
u8  Command,
u8 *  WriteBfrPtr 
)

This function writes to the serial Flash connected to the QSPI interface.

All the data put into the buffer must be in the same page of the device with page boundaries being on 256 byte boundaries.

Parameters
QspiPtris a pointer to the QSPI driver component to use.
Addresscontains the address to write data to in the Flash.
ByteCountcontains the number of bytes to write.
Commandis the command used to write data to the flash. QSPI device supports only Page Program command to write data to the flash.
WriteBfrptris the pointer to the write buffer(which is to be transmitted)
Returns
None.
Note
None.

References Flash_Config_Table, GetRealAddr(), SendBankSelect(), and XQspiPs_PolledTransfer().

u32 GetRealAddr ( XQspiPs QspiPtr,
u32  Address 
)

This functions translates the address based on the type of interconnection.

In case of stacked, this function asserts the corresponding slave select.

Parameters
QspiPtris a pointer to the QSPI driver component to use.
Addresswhich is to be accessed (for erase, write or read)
Returns
RealAddr is the translated address - for single it is unchanged; for stacked, the lower flash size is subtracted; for parallel the address is divided by 2.
Note
None.

References XQspiPs::Config, XQspiPs_Config::ConnectionMode, Flash_Config_Table, XQspiPs_GetLqspiConfigReg, XQSPIPS_LQSPI_CR_U_PAGE_MASK, XQspiPs_SetLqspiConfigReg, and XQspiPs_SetSlaveSelect().

Referenced by FlashErase(), FlashRead(), and FlashWrite().

int main ( void  )

Main function to call the QSPI Flash example.

Returns
XST_SUCCESS if successful, otherwise XST_FAILURE.
Note
None

References QspiG128FlashExample().

int QspiG128FlashExample ( XQspiPs QspiInstancePtr,
u16  QspiDeviceId 
)

The purpose of this function is to illustrate how to use the XQspiPs device driver in single, parallel and stacked modes using flash devices greater than 128Mb.

This function reads and writes data in I/O mode.

Parameters
QspiInstancePtris a pointer to the QSPIPS driver to use.
QspiDeviceIdis the XPAR_<QSPIPS_instance>_DEVICE_ID value from xparameters.h
Returns
XST_SUCCESS if successful, else XST_FAILURE.
Note
None.

References XQspiPs_Config::BaseAddress, XQspiPs_Config::ConnectionMode, Flash_Config_Table, FlashErase(), FlashRead(), FlashReadID(), FlashWrite(), XQspiPs_CfgInitialize(), XQSPIPS_CLK_PRESCALE_8, XQSPIPS_FORCE_SSELECT_OPTION, XQSPIPS_HOLD_B_DRIVE_OPTION, XQspiPs_LookupConfig(), XQSPIPS_MANUAL_START_OPTION, XQspiPs_SelfTest(), XQspiPs_SetClkPrescaler(), XQspiPs_SetLqspiConfigReg, XQspiPs_SetOptions(), and XQspiPs_SetSlaveSelect().

Referenced by main().

int SendBankSelect ( XQspiPs QspiPtr,
u8 *  WriteBfrPtr,
u32  BankSel 
)

This functions selects the current bank.

Parameters
QspiPtris a pointer to the QSPI driver component to use.
WriteBfrPtrto the write buffer which contains data to be transmitted.
BankSelis the bank to be selected in the flash device(s).
Returns
XST_SUCCESS if bank selected, otherwise XST_FAILURE.
Note
None.

References XQspiPs_PolledTransfer().

Referenced by DieErase(), FlashErase(), FlashRead(), and FlashWrite().

Variable Documentation

FlashInfo Flash_Config_Table[34]