qspips
Vitis Drivers API Documentation
 All Data Structures Files Functions Variables Typedefs Groups Pages
Qspips_flash_intr_example

Macros

#define WRITE_STATUS_CMD   0x01
 Write status register command. More...
 
#define WRITE_CMD   0x02
 Write (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 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 OVERHEAD_SIZE   4
 Command and address byte count. More...
 
#define SECTOR_SIZE   0x10000
 Sector size in bytes. More...
 
#define NUM_SECTORS   0x100
 Number of sectors. More...
 
#define NUM_PAGES   0x10000
 Number of pages. More...
 
#define PAGE_SIZE   256
 Page size in bytes. More...
 
#define PAGE_COUNT   16
 Number of flash pages to be written. More...
 
#define TEST_ADDRESS   0x00090000
 Flash address to which data is to be written. More...
 
#define UNIQUE_VALUE   0x05
 Start value of the data pattern. More...
 
#define MAX_DATA   (PAGE_COUNT * PAGE_SIZE)
 Maximum amount of data transferred to and from the FLASH. More...
 

Functions

void QspiHandler (void *CallBackRef, u32 StatusEvent, unsigned int ByteCount)
 Handles the processing for the QSPI driver. More...
 
void FlashErase (XQspiPs *QspiPtr, u32 Address, u32 ByteCount)
 Erases the sectors in the serial FLASH connected to the QSPI interface. More...
 
void FlashWrite (XQspiPs *QspiPtr, u32 Address, u32 ByteCount, u8 Command)
 Writes to the serial FLASH connected to the QSPI interface. More...
 
void FlashRead (XQspiPs *QspiPtr, u32 Address, u32 ByteCount, u8 Command)
 Reads from the serial FLASH connected to the QSPI interface. More...
 
int FlashReadID (void)
 Reads serial FLASH ID connected to the SPI interface. More...
 
void FlashQuadEnable (XQspiPs *QspiPtr)
 Enables quad mode in the serial flash connected to the SPI interface. More...
 
int QspiFlashIntrExample (XQspiPs *QspiInstancePtr, UINTPTR BaseAddress)
 Illustrates how to use the XQspiPs device driver in interrupt mode. More...
 
int main (void)
 Runs the QSPI Flash interrupt example. More...
 

Variables

volatile int TransferInProgress
 The following variables are shared between non-interrupt processing and interrupt processing such that they must be global. More...
 
int Error
 The following variable tracks any errors that occur during interrupt processing. More...
 
int Test = 0xF
 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 [MAX_DATA+DATA_OFFSET+DUMMY_SIZE]
 Read buffer. More...
 
u8 WriteBuffer [PAGE_SIZE+DATA_OFFSET]
 Write buffer. More...
 

Macro Definition Documentation

#define ADDRESS_1_OFFSET   1

MSB byte of address to read or write.

#define ADDRESS_2_OFFSET   2

Middle byte of address to read or write.

#define ADDRESS_3_OFFSET   3

LSB byte of address to read or write.

#define BULK_ERASE_CMD   0xC7

Bulk erase command.

#define BULK_ERASE_SIZE   1

Bulk Erase command size.

#define COMMAND_OFFSET   0

FLASH instruction.

#define DATA_OFFSET   4

Start of Data for Read/Write.

Referenced by QspiFlashIntrExample().

#define DUAL_READ_CMD   0x3B

Dual read command.

Referenced by QspiFlashIntrExample().

#define DUMMY_OFFSET   4

Dummy byte offset for fast, dual and quad reads.

#define DUMMY_SIZE   1

Number of dummy bytes for fast, dual and quad reads.

Referenced by FlashRead(), and QspiFlashIntrExample().

#define FAST_READ_CMD   0x0B

Fast read command.

Referenced by QspiFlashIntrExample().

#define MAX_DATA   (PAGE_COUNT * PAGE_SIZE)

Maximum amount of data transferred to and from the FLASH.

Referenced by QspiFlashIntrExample().

#define NUM_PAGES   0x10000

Number of pages.

#define NUM_SECTORS   0x100

Number of sectors.

#define OVERHEAD_SIZE   4

Command and address byte count.

#define PAGE_COUNT   16

Number of flash pages to be written.

Referenced by QspiFlashIntrExample().

#define PAGE_SIZE   256

Page size in bytes.

Referenced by QspiFlashIntrExample().

#define QUAD_READ_CMD   0x6B

Quad read command.

Referenced by QspiFlashIntrExample().

#define RD_ID_SIZE   4

Read ID command + 3 bytes ID response.

#define READ_CMD   0x03

Normal read command.

Referenced by QspiFlashIntrExample().

#define READ_ID   0x9F

Read ID command.

#define READ_STATUS_CMD   0x05

Read status register command.

#define SEC_ERASE_CMD   0xD8

Sector erase command.

#define SEC_ERASE_SIZE   4

Sector Erase command + Sector address.

#define SECTOR_SIZE   0x10000

Sector size in bytes.

#define TEST_ADDRESS   0x00090000

Flash address to which data is to be written.

Referenced by QspiFlashIntrExample().

#define UNIQUE_VALUE   0x05

Start value of the data pattern.

Referenced by QspiFlashIntrExample().

#define WRITE_CMD   0x02

Write (page program) command.

Referenced by QspiFlashIntrExample().

#define WRITE_DISABLE_CMD   0x04

Write disable command.

#define WRITE_ENABLE_CMD   0x06

Write enable command.

#define WRITE_STATUS_CMD   0x01

Write status register command.

Function Documentation

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

Erases the sectors in the serial FLASH connected to the QSPI interface.

Parameters
[in,out]QspiPtrPointer to the QSPI driver component to use.
[in]AddressThe address of the first sector which needs to be erased.
[in]ByteCountThe total size to be erased.
void FlashQuadEnable ( XQspiPs *  QspiPtr)

Enables quad mode in the serial flash connected to the SPI interface.

Parameters
[in,out]QspiPtrPointer to the QSPI driver component to use.
void FlashRead ( XQspiPs *  QspiPtr,
u32  Address,
u32  ByteCount,
u8  Command 
)

Reads from the serial FLASH connected to the QSPI interface.

Parameters
[in,out]QspiPtrPointer to the QSPI driver component to use.
[in]AddressThe address to read data from in the FLASH.
[in]ByteCountThe number of bytes to read.
[in]CommandThe 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.
int FlashReadID ( void  )

Reads serial FLASH ID connected to the SPI interface.

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

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
[in,out]QspiPtrPointer to the QSPI driver component to use.
[in]AddressThe address to write data to in the FLASH.
[in]ByteCountThe number of bytes to write.
[in]CommandThe command used to write data to the flash. QSPI device supports only Page Program command to write data to the flash.
int main ( void  )

Runs the QSPI Flash interrupt example.

Returns
XST_SUCCESS if successful, otherwise XST_FAILURE.
int QspiFlashIntrExample ( XQspiPs *  QspiInstancePtr,
UINTPTR  BaseAddress 
)

Illustrates how to use the XQspiPs device driver in interrupt mode.

The function writes and reads data from a serial FLASH.

Parameters
[in]QspiInstancePtrPointer to the QSPIPS driver to use.
[in]BaseAddressThe base address of the device
Returns
XST_SUCCESS if successful else XST_FAILURE.
Note
In XSCT/classic flow, the device configuration is looked up based on DeviceId. The 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 reads a status of 0xFF for the status register as the bus is pulled up.

References XQspiPs_Config::BaseAddress, DATA_OFFSET, DUAL_READ_CMD, DUMMY_SIZE, FAST_READ_CMD, FlashErase(), FlashQuadEnable(), FlashRead(), FlashReadID(), FlashWrite(), XQspiPs_Config::IntrId, XQspiPs_Config::IntrParent, MAX_DATA, PAGE_COUNT, PAGE_SIZE, QspiHandler(), QUAD_READ_CMD, READ_CMD, ReadBuffer, Test, TEST_ADDRESS, UNIQUE_VALUE, WRITE_CMD, WriteBuffer, 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().

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

Handles the 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
[in]CallBackRefA reference passed to the handler.
[in]StatusEventThe status of the QSPI.
[in]ByteCountThe number of bytes transferred.

References Error.

Referenced by QspiFlashIntrExample().

Variable Documentation

int Error

The following variable tracks any errors that occur during interrupt processing.

Referenced by QspiHandler().

Read buffer.

int Test = 0xF

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.

volatile int TransferInProgress

The following variables are shared between non-interrupt processing and interrupt processing such that they must be global.

u8 WriteBuffer[PAGE_SIZE+DATA_OFFSET]

Write buffer.