| spi Vitis Drivers API Documentation

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

Functions
xspi_intel_flash_example.c File Reference

## Overview

This file contains a design example using the SPI driver (XSpi) and hardware device with an Intel Serial Flash Memory (S33) in the interrupt mode.

This example erases a sector, writes to a Page within the sector, reads back from that Page and compares the data.

The example works with an Intel Serial Flash Memory (S33). The number of bytes per page in this device is 256. For further details about the device refer to the Intel Serial Flash Memory (S33) Data sheet

This example assumes that the underlying processor is MicroBlaze.

Note

None.

    MODIFICATION HISTORY:

    Ver   Who  Date     Changes

    1.00a sd   02/26/08 First release
    3.00a ktn  10/22/09 Converted all register accesses to 32 bit access.
                  Updated to use the HAL APIs/macros. Replaced call to
                  XSpi_Initialize API with XSpi_LookupConfig and
                  XSpi_CfgInitialize.
    4.2   ms   01/23/17 Added xil_printf statement in main function to
                        ensure that "Successfully ran" and "Failed" strings
                        are available in all examples. This is a fix for
                        CR-965028.
          ms   04/05/17 Modified Comment lines to follow doxygen rules.
    4.11  sb   07/11/23 Added support for system device-tree flow.

## Functions
int | SpiIntelFlashWriteEnable (XSpi *SpiPtr)
| This function enables writes to the Intel Serial Flash memory. More...
int | SpiIntelFlashWrite (XSpi *SpiPtr, u32 Addr, u32 ByteCount)
| This function writes the data to the specified locations in the Intel Serial Flash memory. More...
int | SpiIntelFlashRead (XSpi *SpiPtr, u32 Addr, u32 ByteCount)
| This function reads the data from the Intel Serial Flash Memory. More...
int | SpiIntelFlashBulkErase (XSpi *SpiPtr)
| This function erases the entire contents of the Intel Serial Flash. More...
int | SpiIntelFlashSectorErase (XSpi *SpiPtr, u32 Addr)
| This function erases the contents of the specified Sector in the Intel Serial Flash. More...
int | SpiIntelFlashGetStatus (XSpi *SpiPtr)
| This function reads the Status register of the Intel Serial Flash. More...
int | SpiIntelFlashWriteStatus (XSpi *SpiPtr, u8 StatusRegister)
| This function writes to the Status register of the Intel Flash. More...
void | SpiHandler (void *CallBackRef, u32 StatusEvent, unsigned int ByteCount)
| This function is the handler which performs processing for the SPI driver. More...
int | main (void)
| Main function to execute the Flash example. More...

## Function Documentation

int main | ( | void |  | ) |

Main function to execute the Flash example.

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  None

References XSpi_Config::BaseAddress, SpiHandler(), SpiIntelFlashRead(), SpiIntelFlashSectorErase(), SpiIntelFlashWrite(), SpiIntelFlashWriteEnable(), SpiIntelFlashWriteStatus(), XSP_MASTER_OPTION, XSpi_CfgInitialize(), XSpi_InterruptHandler(), XSpi_LookupConfig(), XSpi_SetOptions(), XSpi_SetSlaveSelect(), XSpi_SetStatusHandler(), and XSpi_Start().

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

This function is the handler which performs processing for the SPI 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 SPI data completes or an error occurs.

This handler provides an example of how to handle SPI interrupts and is application specific.

Parameters

  CallBackRef | is the upper layer callback reference passed back when the callback function is invoked.
  StatusEvent | is the event that just occurred.
  ByteCount | is the number of bytes transferred up until the event occurred.

Returns
  None.

Note
  None.

int SpiIntelFlashBulkErase | ( | XSpi * | SpiPtr | ) |

This function erases the entire contents of the Intel Serial Flash.

Parameters

  SpiPtr | is a pointer to the instance of the Spi device.

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  The erased bytes will read as 0xFF.

References XSpi_Transfer().

int SpiIntelFlashGetStatus | ( | XSpi * | SpiPtr | ) |

This function reads the Status register of the Intel Serial Flash.

Parameters

  SpiPtr | is a pointer to the instance of the Spi device.

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  The status register content is stored at the second byte pointed by the ReadBuffer.

References XSpi_Transfer().

int SpiIntelFlashRead | ( | XSpi * | SpiPtr,
|  | u32 | Addr,
|  | u32 | ByteCount
| ) |  |

This function reads the data from the Intel Serial Flash Memory.

Parameters

  SpiPtr | is a pointer to the instance of the Spi device.
  Addr | is the starting address in the Flash Memory from which the data is to be read.
  ByteCount | is the number of bytes to be read.

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  None.

References XSpi_Transfer().

Referenced by main().

int SpiIntelFlashSectorErase | ( | XSpi * | SpiPtr,
|  | u32 | Addr
| ) |  |

This function erases the contents of the specified Sector in the Intel Serial Flash.

Parameters

  SpiPtr | is a pointer to the instance of the Spi device.
  Addr | is the address within a sector of the Buffer, which is to be erased.

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  The erased bytes will read as 0xFF.

References XSpi_Transfer().

Referenced by main().

int SpiIntelFlashWrite | ( | XSpi * | SpiPtr,
|  | u32 | Addr,
|  | u32 | ByteCount
| ) |  |

This function writes the data to the specified locations in the Intel Serial Flash memory.

Parameters

  SpiPtr | is a pointer to the instance of the Spi device.
  Addr | is the address in the Buffer, where to write the data.
  ByteCount | is the number of bytes to be written.

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  A minimum of one byte and a maximum of one Page can be written using this API.

References XSpi_Transfer().

Referenced by main().

int SpiIntelFlashWriteEnable | ( | XSpi * | SpiPtr | ) |

This function enables writes to the Intel Serial Flash memory.

Parameters

  SpiPtr | is a pointer to the instance of the Spi device.

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  None.

References XSpi_Transfer().

Referenced by main().

int SpiIntelFlashWriteStatus | ( | XSpi * | SpiPtr,
|  | u8 | StatusRegister
| ) |  |

This function writes to the Status register of the Intel Flash.

Parameters

  SpiPtr | is a pointer to the instance of the Spi device.
  StatusRegister | is the value to be written to the status register of the flash device.

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  The status register content is stored at the second byte pointed by the ReadPtr.

References XSpi_Transfer().

Referenced by main().