qspips
Vitis Drivers API Documentation
xqspips_flash_intr_example.c File Reference

Overview

This file contains a design example using the QSPI driver (XQspiPs) in interrupt mode with a serial FLASH device.

This examples performs some transfers in Manual Chip Select and Start mode. It is recommended to use Manual CS + Auto start for best performance. The hardware which this example runs on, must have a serial FLASH (Numonyx N25Q, Winbond W25Q, Spansion S25FL, ISSI IS25WP) for it to run. This example has been tested with the Numonyx Serial Flash (N25Q128) and IS25WP series flash parts.

Note

None.

 MODIFICATION HISTORY:
 Ver   Who Date     Changes


1.00 sdm 11/25/10 First release 1.01 srt 06/12/12 Changed to meet frequency requirements of READ command for CR 663787 2.00a kka 22/08/12 Updated the example as XQspiPs_Transfer API has changed. Changed the prescalar to use divide by 8. The user can change the prescalar to a maximum of divide by 2 based on the reference clock in the system. Set the Holdb_dr bit in the configuration register using XQSPIPS_HOLD_B_DRIVE_OPTION. Setting this bit drives the HOLD bit of the QSPI controller. This is required for QSPI to be used in Non QSPI boot mode else there needs to be an external pullup on this line. See http://www.xilinx.com/support/answers/47596.htm 2.01a sg 02/03/13 Created a function FlashReadID. Removed multiple initialization using SetOptions. ms 04/05/17 Modified Comment lines in functions to recognize it as documentation block for doxygen generation. 3.5 tjs 07/16/18 Added support for low density ISSI flash parts. Added FlashQuadEnable API to enable quad mode in flash. 3.6 akm 04/15/19 Modified FlashQuadEnable, FlashWrie and FlashErase APIs, to wait for the on going operation to complete before performing the next operation. 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

void QspiHandler (void *CallBackRef, u32 StatusEvent, unsigned int ByteCount)
 This function is the handler which performs processing for the QSPI driver. More...
 
void FlashErase (XQspiPs *QspiPtr, u32 Address, u32 ByteCount)
 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)
 This function writes to the serial FLASH connected to the QSPI interface. More...
 
void FlashRead (XQspiPs *QspiPtr, u32 Address, u32 ByteCount, u8 Command)
 This function reads from the serial FLASH connected to the QSPI interface. More...
 
int FlashReadID (void)
 This function reads serial FLASH ID connected to the SPI interface. More...
 
void FlashQuadEnable (XQspiPs *QspiPtr)
 This function enables quad mode in the serial flash connected to the SPI interface. More...
 
int QspiFlashIntrExample (XScuGic *IntcInstancePtr, XQspiPs *QspiInstancePtr, u16 QspiDeviceId, u16 QspiIntrId)
 The purpose of this function is to illustrate how to use the XQspiPs device driver in interrupt mode. More...
 
int main (void)
 Main function to call the QSPI Flash example. More...
 

Function Documentation

void FlashErase ( XQspiPs QspiPtr,
u32  Address,
u32  ByteCount 
)

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.
Returns
None.
Note
None.
void FlashQuadEnable ( XQspiPs QspiPtr)

This function enables quad mode in the serial flash connected to the SPI interface.

Parameters
QspiPtris a pointer to the QSPI driver component to use.
Returns
None.
Note
None.
void FlashRead ( XQspiPs QspiPtr,
u32  Address,
u32  ByteCount,
u8  Command 
)

This function reads from the serial FLASH connected to the QSPI interface.

Parameters
QspiPtris a pointer to the QSPI driver component to use.
Addresscontains the address to read data from in the FLASH.
ByteCountcontains the number of bytes to read.
Commandis the command used to read data from the flash. QSPI device supports one of the Read, Fast Read, Dual Read and Fast Read commands to read data from the flash.
Returns
None.
Note
None.
int FlashReadID ( void  )

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

Returns
XST_SUCCESS if read id, otherwise XST_FAILURE.
Note
None.
void FlashWrite ( XQspiPs QspiPtr,
u32  Address,
u32  ByteCount,
u8  Command 
)

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.
Returns
None.
Note
None.
int main ( void  )

Main function to call the QSPI Flash example.

Returns
XST_SUCCESS if successful, otherwise XST_FAILURE.
Note
None

References QspiFlashIntrExample().

int QspiFlashIntrExample ( XScuGic *  IntcInstancePtr,
XQspiPs QspiInstancePtr,
u16  QspiDeviceId,
u16  QspiIntrId 
)

The purpose of this function is to illustrate how to use the XQspiPs device driver in interrupt mode.

This function writes and reads data from a serial FLASH.

Parameters
IntcInstancePtris a pointer to the instance of the INTC component.
QspiInstancePtris a pointer to the QSPIPS driver to use. .
QspiDeviceIdis the XPAR_<QSPIPS_instance>_DEVICE_ID value from xparameters.h.
QspiIntrIdis the QSPIPS Interrupt Id.
Returns
XST_SUCCESS if successful else XST_FAILURE.
Note

This function calls other functions which contain loops that may be infinite if interrupts are not working such that it may not return. If the device slave select is not correct and the device is not responding on bus it will read a status of 0xFF for the status register as the bus is pulled up.

References XQspiPs_Config::BaseAddress, FlashErase(), FlashQuadEnable(), FlashRead(), FlashReadID(), FlashWrite(), QspiHandler(), XQspiPs_CfgInitialize(), XQSPIPS_CLK_PRESCALE_8, XQSPIPS_FORCE_SSELECT_OPTION, XQSPIPS_HOLD_B_DRIVE_OPTION, XQspiPs_InterruptHandler(), XQspiPs_LookupConfig(), XQSPIPS_MANUAL_START_OPTION, XQspiPs_SelfTest(), XQspiPs_SetClkPrescaler(), XQspiPs_SetOptions(), XQspiPs_SetSlaveSelect(), and XQspiPs_SetStatusHandler().

Referenced by main().

void QspiHandler ( void *  CallBackRef,
u32  StatusEvent,
unsigned int  ByteCount 
)

This function is the handler which performs processing for the QSPI driver.

It is called from an interrupt context such that the amount of processing performed should be minimized. It is called when a transfer of QSPI data completes or an error occurs.

This handler provides an example of how to handle QSPI interrupts but is application specific.

Parameters
CallBackRefis a reference passed to the handler.
StatusEventis the status of the QSPI .
ByteCountis the number of bytes transferred.
Returns
None
Note
None.

Referenced by QspiFlashIntrExample().