| ospipsv Vitis Drivers API Documentation

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

Functions
xospipsv_flash_non_blocking_read_example.c File Reference

## Overview

This file contains a design example using the OSPIPSV driver (xospipsv) The example writes to flash in IO mode and reads it back using non-blocking APIs in DMA mode.

It runs in polled mode. The hardware which this example runs on, must have an octal serial Flash (Micron) for it to run.

This example has been tested with the Micron Octal Serial Flash (mt35xu01gbba).

Note

None.

     MODIFICATION HISTORY:

     Ver   Who Date     Changes

     1.0   sk  02/03/20 First release
     1.3   sk  05/27/20 Added Stacked mode support.
     1.4   sk  02/18/21 Added support for Macronix flash and DualByte commands.
     1.9   sb  06/06/23 Added support for system device-tree flow.
     1.10  akm 01/31/24 Use OSPI controller reset for resetting flash device.
     1.10  sb  02/09/24 Add support for Infineon flash part S28HS02G.
     1.11  sb  05/02/24 Add support for Macronix flash part mx66uw2g345gxrix0.
     1.12  akm 01/01/25  Pass valid write command in DAC mode.
     1.12  sb  03/12/25 Fixed gcc and g++ warnings.

## Functions
int | OspiPsvFlashNonBlockingReadExample (XOspiPsv *OspiPsvInstancePtr, u16 OspiPsvDeviceId)
| The purpose of this function is to illustrate how to use the XOspiPsv device driver using OSPI flash devices greater than or equal to 128Mb. More...
int | FlashReadID (XOspiPsv *OspiPsvPtr)
| Reads the flash ID and identifies the flash in FCT table. More...
int | FlashErase (XOspiPsv *OspiPsvPtr, u32 Address, u32 ByteCount, u8 *WriteBfrPtr)
| This function erases the sectors in the serial Flash connected to the OSPIPSV interface. More...
int | FlashIoWrite (XOspiPsv *OspiPsvPtr, u32 Address, u32 ByteCount, u8 *WriteBfrPtr)
| This function writes to the serial Flash connected to the OSPIPSV interface. More...
int | FlashLinearWrite (XOspiPsv *OspiPsvPtr, u32 Address, u32 ByteCount, u8 *WriteBfrPtr)
| This function writes to the serial Flash connected to the OSPIPSV interface. More...
int | FlashRead (XOspiPsv *OspiPsvPtr, u32 Address, u32 ByteCount, u8 *WriteBfrPtr, u8 *ReadBfrPtr)
| This function performs read. More...
u32 | GetRealAddr (XOspiPsv *OspiPsvPtr, u32 Address)
| This functions translates the address based on the type of interconnection. More...
int | BulkErase (XOspiPsv *OspiPsvPtr, u8 *WriteBfrPtr)
| This functions performs a bulk erase operation when the flash device has a single die. More...
int | DieErase (XOspiPsv *OspiPsvPtr, u8 *WriteBfrPtr)
| This functions performs a die erase operation on all the die in the flash device. More...
int | FlashEnterExit4BAddMode (XOspiPsv *OspiPsvPtr, int Enable)
| This API enters the flash device into 4 bytes addressing mode. More...
int | FlashSetSDRDDRMode (XOspiPsv *OspiPsvPtr, int Mode)
| This API enters the flash device into Octal DDR mode or exit from octal DDR mode (switches to Extended SPI mode). More...
int | SpansionSetEccMode (XOspiPsv *OspiPsvPtr)
| This function configures the ECC mode in Flash device. More...
int | MxConfigDummy (XOspiPsv *OspiPsvPtr)
| This function configures the Dummy cycles in Flash device. More...
int | main (void)
| Main function to call the OSPIPSV Flash Polled example. More...
u32 | XOspiPsv_Get_Proto (XOspiPsv *OspiPsvInstancePtr, int Read)
| The purpose of this function is to determine the number of lines used for command, address and data. More...

## Function Documentation

int BulkErase | ( | XOspiPsv * | OspiPsvPtr,
|  | u8 * | WriteBfrPtr
| ) |  |

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

Works for both Spansion and Micron

Parameters

  OspiPsvPtr | is a pointer to the OSPIPSV driver component to use.
  WriteBfrPtr | is the pointer to command+address to be sent

Returns
  XST_SUCCESS if successful, else XST_FAILURE.

Note
  None.

int DieErase | ( | XOspiPsv * | OspiPsvPtr,
|  | 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

  OspiPsvPtr | is a pointer to the OSPIPSV driver component to use.
  WriteBfrPtr | is the pointer to command+address to be sent

Returns
  XST_SUCCESS if successful, else XST_FAILURE.

Note
  None.

int FlashEnterExit4BAddMode | ( | XOspiPsv * | OspiPsvPtr,
|  | int | Enable
| ) |  |

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

As per the Micron spec, before issuing the command to enter into 4 byte addr mode, a write enable command is issued.

Parameters

  OspiPsvPtr | is a pointer to the OSPIPSV 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 | ( | XOspiPsv * | OspiPsvPtr,
|  | u32 | Address,
|  | u32 | ByteCount,
|  | u8 * | WriteBfrPtr
| ) |  |

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

Parameters

  OspiPsvPtr | is a pointer to the OSPIPSV 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.
  WriteBfrPtr | is Pointer to the write buffer (which is to be transmitted)

Returns
  XST_SUCCESS if successful, else XST_FAILURE.

Note
  None.

int FlashIoWrite | ( | XOspiPsv * | OspiPsvPtr,
|  | u32 | Address,
|  | u32 | ByteCount,
|  | u8 * | WriteBfrPtr
| ) |  |

This function writes to the serial Flash connected to the OSPIPSV 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. This can be used in IO or DMA mode.

Parameters

  OspiPsvPtr | is a pointer to the OSPIPSV driver component to use.
  Address | contains the address to write data to in the Flash.
  ByteCount | contains the number of bytes to write.
  WriteBfrPtr | Pointer to the write buffer (which is to be transmitted)

Returns
  XST_SUCCESS if successful, else XST_FAILURE.

Note
  None.

int FlashLinearWrite | ( | XOspiPsv * | OspiPsvPtr,
|  | u32 | Address,
|  | u32 | ByteCount,
|  | u8 * | WriteBfrPtr
| ) |  |

This function writes to the serial Flash connected to the OSPIPSV 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. This can be used when controller is in Linear mode.

Parameters

  OspiPsvPtr | is a pointer to the OSPIPSV driver component to use.
  Address | contains the address to write data to in the Flash.
  ByteCount | contains the number of bytes to write.
  WriteBfrPtr | is Pointer to the write buffer (which is to be transmitted)

Returns
  XST_SUCCESS if successful, else XST_FAILURE.

Note
  None.

int FlashRead | ( | XOspiPsv * | OspiPsvPtr,
|  | u32 | Address,
|  | u32 | ByteCount,
|  | u8 * | WriteBfrPtr,
|  | u8 * | ReadBfrPtr
| ) |  |

This function performs read.

DMA is the default setting.

Parameters

  OspiPsvPtr | is a pointer to the OSPIPSV 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.
  WriteBfrPtr | is Pointer to the write buffer which contains data to be transmitted
  ReadBfrPtr | is 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 | ( | XOspiPsv * | OspiPsvPtr | ) |

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

Parameters

  OspiPsvPtr | is a pointer to the OSPIPSV driver component to use.

Returns
  XST_SUCCESS if successful, else XST_FAILURE.

Note
  None.

int FlashSetSDRDDRMode | ( | XOspiPsv * | OspiPsvPtr,
|  | int | Mode
| ) |  |

This API enters the flash device into Octal DDR mode or exit from octal DDR mode (switches to Extended SPI mode).

Parameters

  OspiPsvPtr | is a pointer to the OSPIPSV driver component to use.
  Mode | is either 1 or 0 if 1 then enter octal DDR mode if 0 exits.

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

u32 GetRealAddr | ( | XOspiPsv * | OspiPsvPtr,
|  | 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

  OspiPsvPtr | is a pointer to the OSPIPSV 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;

Note
  In addition to get the actual address to work on flash this function also selects the CS based on the configuration detected.

int main | ( | void |  | ) |

Main function to call the OSPIPSV Flash Polled example.

Returns
  XST_SUCCESS if successful, otherwise XST_FAILURE.

Note
  None

References OspiPsvFlashNonBlockingReadExample().

int MxConfigDummy | ( | XOspiPsv * | OspiPsvPtr | ) |

This function configures the Dummy cycles in Flash device.

Parameters

  OspiPsvPtr | is a pointer to the OSPIPSV driver component to use.

Returns
  XST_SUCCESS or XST_FAILURE.

int OspiPsvFlashNonBlockingReadExample | ( | XOspiPsv * | OspiPsvInstancePtr,
|  | u16 | OspiPsvDeviceId
| ) |  |

The purpose of this function is to illustrate how to use the XOspiPsv device driver using OSPI flash devices greater than or equal to 128Mb.

This function reads data in either DMA or DAC mode.

Parameters

  OspiPsvInstancePtr | is a pointer to the OSPIPSV driver component to use.
  OspiPsvDeviceId | is the Device ID of the OSpi Device and is the XPAR_<OSPI_instance>_DEVICE_ID value from xparameters.h.

Returns
  XST_SUCCESS if successful, else XST_FAILURE.

Note
  None.

References XOspiPsv::Config, XOspiPsv_Config::ConnectionMode, FlashEnterExit4BAddMode(), FlashErase(), FlashIoWrite(), FlashLinearWrite(), FlashRead(), FlashReadID(), FlashSetSDRDDRMode(), MxConfigDummy(), SpansionSetEccMode(), XOspiPsv_CfgInitialize(), XOSPIPSV_DAC_EN_OPTION, XOspiPsv_DeviceReset(), XOspiPsv_DeviceResetViaOspi(), XOspiPsv_GetOptions(), XOSPIPSV_HWPIN_RESET, XOspiPsv_LookupConfig(), XOSPIPSV_SELECT_FLASH_CS0, XOspiPsv_SelectFlash(), XOspiPsv_SetClkPrescaler(), XOspiPsv_SetOptions(), and XOspiPsv_SetSdrDdrMode().

Referenced by main().

int SpansionSetEccMode | ( | XOspiPsv * | OspiPsvPtr | ) |

This function configures the ECC mode in Flash device.

In some flashes by default 2-bit ECC is enabled, which prevents byte-programming( <16-Bytes). This function enables byte-programming by setting the ECC configuration to 1-bit error detection/correction.

Parameters

  OspiPsvPtr | is a pointer to the OSPIPSV driver component to use.

Returns
  XST_SUCCESS or XST_FAILURE.

Note
  This function is specific to some spansion flashes(S28HS02GT).

u32 XOspiPsv_Get_Proto | ( | XOspiPsv * | OspiPsvInstancePtr,
|  | int | Read
| ) |  |

The purpose of this function is to determine the number of lines used for command, address and data.

Parameters

  OspiPsvInstancePtr | is a pointer to the OSPIPSV driver component to use.
  Read | is to tell whether a read or write

Returns
  returns value to program the lines for command, address and data.

Note
  None.

References XOspiPsv::OpMode, XOSPIPSV_IDAC_MODE, and XOSPIPSV_READ_1_1_1.