qspipsu: xqspipsu_generic_flash_lqspi_example.c File Reference

| qspipsu Xilinx SDK Drivers API Documentation

- Overview
- Data Structures
- APIs
- File List
- Examples

Functions
xqspipsu_generic_flash_lqspi_example.c File Reference

## Overview

This file contains a design example using the QSPIPSU driver (XQspiPsu) with a serial Flash device greater than or equal to 128Mb.

The example writes to flash in GQSPI mode and reads it back in Linear QSPI mode.This examples runs with GENFIFO Manual start. It runs in interrupt mode.This example runs in single mode.

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 (N25Q512A) and ISSI Serial Flash parts of IS25WP and IS25LP series flashes in single mode using A53 and R5 processors.

Note

In dual parallel mode flash connection, ZynqMP GQSPI writes data in bytes(Even bytes in lower flash and odd bytes in upper flash), where as LQSPI reads the data in bitwise. so this is causing data mismatch while reading in LQSPI mode. so this application proceeds with single mode irrespective of flash connection.

     MODIFICATION HISTORY:

     Ver   Who Date     Changes

     1.0   hk  08/21/14 First release
           sk  06/17/15 Used Tx/Rx flags for Transmitting/Receiving.
                    sk  11/23/15 Added Support for Macronix 1Gb part.
     1.2    nsk 07/01/16 Add LQSPI support
     1.3    nsk 09/19/16 Update documentation
           ms  04/05/17 Modified Comment lines in functions to
                        recognize it as documentation block and modified filename
                        tag to include the file in doxygen examples.
     1.4    tjs     06/16/17 Added support for IS25LP256D flash part (PR-4650)

     1.5    tjs 09/15/17 Replaced #ifdef COMMENTS to #if USE_FOUR_BYTE (CR-984966)
     1.7   tjs 11/16/17 Removed the unsupported 4 Byte write and sector erase
                        commands.
     1.7    tjs     12/01/17 Added support for MT25QL02G Flash from Micron. CR-990642
     1.7    tjs 12/19/17 Added support for S25FL064L from Spansion. CR-990724
     1.7    tjs 01/11/18 Added support for MX66L1G45G flash from Macronix CR-992367
     1.7    tjs 26/03/18 In dual parallel mode enable both CS when issuing Write
                                     enable command. CR-998478
     1.8    tjs 05/02/18 Added support for IS25LP064 and IS25WP064.
     1.8    tjs 16/07/18 Added support for the low density ISSI flash parts.
     1.8    tjs 09/14/18 Fixed compilation warnings.
     1.9   akm 02/27/19 Added support for IS25LP128, IS25WP128, IS25LP256,
                         IS25WP256, IS25LP512, IS25WP512 Flash Devices
     1.9   akm 04/03/19 Fixed data alignment warnings on IAR compiler.
     1.9   akm 04/03/19 Fixed compilation error in XQspiPsu_LqspiRead()
                         function on IAR compiler.

## Functions
int | QspiPsuInterruptFlashExample (XScuGic *IntcInstancePtr, XQspiPsu *QspiPsuInstancePtr, u16 QspiPsuDeviceId, u16 QspiPsuIntrId)
| The purpose of this function is to illustrate how to use the XQspiPsu device driver in single, parallel and stacked modes using flash devices greater than or equal to 128Mb. More...
int | FlashReadID (XQspiPsu *QspiPsuPtr)
| Reads the flash ID and identifies the flash in FCT table. More...
int | FlashErase (XQspiPsu *QspiPsuPtr, u32 Address, u32 ByteCount, u8 *WriteBfrPtr)
| This function erases the sectors in the serial Flash connected to the QSPIPSU interface. More...
int | FlashWrite (XQspiPsu *QspiPsuPtr, u32 Address, u32 ByteCount, u8 Command, u8 *WriteBfrPtr)
| This function writes to the serial Flash connected to the QSPIPSU interface. More...
int | FlashRead (XQspiPsu *QspiPsuPtr, u32 Address, u32 ByteCount, u8 Command, u8 *WriteBfrPtr, u8 *ReadBfrPtr)
| This function performs a read. More...
u32 | GetRealAddr (XQspiPsu *QspiPsuPtr, u32 Address)
| This functions translates the address based on the type of interconnection. More...
int | BulkErase (XQspiPsu *QspiPsuPtr, u8 *WriteBfrPtr)
| This functions performs a bulk erase operation when the flash device has a single die. More...
int | DieErase (XQspiPsu *QspiPsuPtr, u8 *WriteBfrPtr)
| This functions performs a die erase operation on all the die in the flash device. More...
void | QspiPsuHandler (void *CallBackRef, u32 StatusEvent, unsigned int ByteCount)
| Callback handler. More...
int | FlashEnterExit4BAddMode (XQspiPsu *QspiPsuPtr, unsigned int Enable)
| This API enters the flash device into 4 bytes addressing mode. More...
int | FlashEnableQuadMode (XQspiPsu *QspiPsuPtr)
| This API enables Quad mode for the flash parts which require to enable quad mode before using Quad commands. More...
int | main (void)
| Main function to call the QSPIPSU Flash example. More...
int | XQspiPsu_LqspiRead (XQspiPsu *InstancePtr, u8 *RecvBufPtr, u32 Address, unsigned ByteCount)
| Read the flash in Linear QSPI mode. More...

## Function Documentation

int BulkErase | ( | XQspiPsu * | QspiPsuPtr,
|  | u8 * | WriteBfrPtr
| ) |  |

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

Works for both Spansion and Micron

Parameters

  QspiPtr | is a pointer to the QSPIPSU driver component to use.
  WritBfrPtr | is the pointer to command+address to be sent

Returns
  XST_SUCCESS if successful, else XST_FAILURE.

Note
  None.

int DieErase | ( | XQspiPsu * | QspiPsuPtr,
|  | 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

  QspiPtr | is a pointer to the QSPIPSU driver component to use.
  WritBfrPtr | is the pointer to command+address to be sent

Returns
  XST_SUCCESS if successful, else XST_FAILURE.

Note
  None.

int FlashEnableQuadMode | ( | XQspiPsu * | QspiPsuPtr | ) |

This API enables Quad mode for the flash parts which require to enable quad mode before using Quad commands.

For S25FL-L series flash parts this is required as the default configuration is x1/x2 mode.

Parameters

  QspiPtr | is a pointer to the QSPIPSU driver component to use.

Returns
  - XST_SUCCESS if successful.
  - XST_FAILURE if it fails.

int FlashEnterExit4BAddMode | ( | XQspiPsu * | QspiPsuPtr,
|  | unsigned int | Enable
| ) |  |

This API enters the flash device into 4 bytes addressing mode.

As per the Micron and ISSI spec, before issuing the command to enter into 4 byte addr mode, a write enable command is issued. For Macronix and Winbond flash parts write enable is not required.

Parameters

  QspiPtr | is a pointer to the QSPIPSU driver component to use.
  Enable | is a either 1 or 0 if 1 then enters 4 byte if 0 exits.

Returns
  - XST_SUCCESS if successful.
  - XST_FAILURE if it fails.

int FlashErase | ( | XQspiPsu * | QspiPsuPtr,
|  | u32 | Address,
|  | u32 | ByteCount,
|  | u8 * | WriteBfrPtr
| ) |  |

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

Parameters

  QspiPtr | is a pointer to the QSPIPSU driver component to use.
  Address | contains the address of the first sector which needs to be erased.
  ByteCount | contains the total size to be erased.
  Pointer | to the write buffer (which is to be transmitted)

Returns
  XST_SUCCESS if successful, else XST_FAILURE.

Note
  None.

int FlashRead | ( | XQspiPsu * | QspiPsuPtr,
|  | u32 | Address,
|  | u32 | ByteCount,
|  | u8 | Command,
|  | u8 * | WriteBfrPtr,
|  | u8 * | ReadBfrPtr
| ) |  |

This function performs a read.

Default setting is in DMA mode.

Parameters

  QspiPtr | is a pointer to the QSPIPSU driver component to use.
  Address | contains the address of the first sector which needs to be erased.
  ByteCount | contains the total size to be erased.
  Command | is the command used to read data from the flash. Supports normal, fast, dual and quad read commands.
  Pointer | to the write buffer which contains data to be transmitted
  Pointer | to the read buffer to which valid received data should be written

Returns
  XST_SUCCESS if successful, else XST_FAILURE.

Note
  None.

int FlashReadID | ( | XQspiPsu * | QspiPsuPtr | ) |

Reads the flash ID and identifies the flash in FCT table.

Parameters

  None. |

Returns
  XST_SUCCESS if successful, else XST_FAILURE.

Note
  None.

int FlashWrite | ( | XQspiPsu * | QspiPsuPtr,
|  | u32 | Address,
|  | u32 | ByteCount,
|  | u8 | Command,
|  | u8 * | WriteBfrPtr
| ) |  |

This function writes to the serial Flash connected to the QSPIPSU 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

  QspiPtr | is a pointer to the QSPIPSU driver component to use.
  Address | contains the address to write data to in the Flash.
  ByteCount | contains the number of bytes to write.
  Command | is the command used to write data to the flash. QSPIPSU device supports only Page Program command to write data to the flash.
  Pointer | to the write buffer (which is to be transmitted)

Returns
  XST_SUCCESS if successful, else XST_FAILURE.

Note
  None.

u32 GetRealAddr | ( | XQspiPsu * | QspiPsuPtr,
|  | 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

  QspiPtr | is a pointer to the QSPIPSU driver component to use.
  Address | which 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
  In addition to get the actual address to work on flash this function also selects the CS and BUS based on the configuration detected.

int main | ( | void |  | ) |

Main function to call the QSPIPSU Flash example.

Parameters

  None |

Returns
  XST_SUCCESS if successful, otherwise XST_FAILURE.

Note
  None

References QspiPsuInterruptFlashExample().

void QspiPsuHandler | ( | void * | CallBackRef,
|  | u32 | StatusEvent,
|  | unsigned int | ByteCount
| ) |  |

Callback handler.

Parameters

  None. |

Returns
  None

Note
  None.

int QspiPsuInterruptFlashExample | ( | XScuGic * | IntcInstancePtr,
|  | XQspiPsu * | QspiPsuInstancePtr,
|  | u16 | QspiPsuDeviceId,
|  | u16 | QspiPsuIntrId
| ) |  |

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

Parameters

  None. |

Returns
  XST_SUCCESS if successful, else XST_FAILURE.

Note
  None.

int XQspiPsu_LqspiRead | ( | XQspiPsu * | InstancePtr,
|  | u8 * | RecvBufPtr,
|  | u32 | Address,
|  | unsigned | ByteCount
| ) |  |

Read the flash in Linear QSPI mode.

Parameters

  InstancePtr | is a pointer to the XQspiPs instance.
  RecvBufPtr | is a pointer to a buffer for received data.
  Address | is the starting address within the flash from from where data needs to be read.
  ByteCount | contains the number of bytes to receive.

Returns
  - XST_SUCCESS if read is performed
  - XST_FAILURE if Linear mode is not set

Note
  None.

References XQspiPsu::IsReady, and XQSPIPSU_LQSPI_CR_LINEAR_MASK.