spi: xspi_numonyx_flash_quad_example.c File Reference

| spi Xilinx SDK Drivers API Documentation

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

Macros | Functions
xspi_numonyx_flash_quad_example.c File Reference

## Overview

This file contains a design example using the SPI driver (XSpi) and axi_qspi device with a Numonyx quad serial flash device 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.

This example has been tested with an N25Q128 device on KC705 and ZC770 board. The bytes per page (PAGE_SIZE) in N25Q128 is 256.

Note

None.

    MODIFICATION HISTORY:

    Ver   Who  Date     Changes

    1.00a bss  08/08/12 First release
    3.04a bss  02/11/13 Modified to use ScuGic in case of Zynq (CR#683510)
    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.

## Macros
#define | READ_WRITE_EXTRA_BYTES 4 /* Read/Write extra bytes */
| This definitions specify the EXTRA bytes in each of the command transactions. More...

## Functions
int | SpiFlashWriteEnable (XSpi *SpiPtr)
| This function enables writes to the Numonyx Serial Flash memory. More...
int | SpiFlashWrite (XSpi *SpiPtr, u32 Addr, u32 ByteCount, u8 WriteCmd)
| This function writes the data to the specified locations in the Numonyx Serial Flash memory. More...
int | SpiFlashRead (XSpi *SpiPtr, u32 Addr, u32 ByteCount, u8 ReadCmd)
| This function reads the data from the Numonyx Serial Flash Memory. More...
int | SpiFlashBulkErase (XSpi *SpiPtr)
| This function erases the entire contents of the Numonyx Serial Flash device. More...
int | SpiFlashSectorErase (XSpi *SpiPtr, u32 Addr)
| This function erases the contents of the specified Sector in the Numonyx Serial Flash device. More...
int | SpiFlashGetStatus (XSpi *SpiPtr)
| This function reads the Status register of the Numonyx Flash. More...
int | SpiFlashQuadEnable (XSpi *SpiPtr)
| This function sets the QuadEnable bit in Winbond flash. More...
int | SpiFlashEnableHPM (XSpi *SpiPtr)
| This function enabled High Performance Mode in Winbond flash, so that data can be read from the flash using DIO and QIO commands. 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 run the quad flash example. More...

## Macro Definition Documentation

#define READ_WRITE_EXTRA_BYTES 4 /* Read/Write extra bytes */

This definitions specify the EXTRA bytes in each of the command transactions.

This count includes Command byte, address bytes and any don't care bytes needed.

Referenced by main(), SpiFlashRead(), and SpiFlashWrite().

## Function Documentation

int main | ( | void |  | ) |

Main function to run the quad flash example.

Parameters

  None |

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  None

References XSpi_Config::BaseAddress, READ_WRITE_EXTRA_BYTES, SpiFlashRead(), SpiFlashSectorErase(), SpiFlashWrite(), SpiFlashWriteEnable(), SpiHandler(), XSP_MASTER_OPTION, XSpi_CfgInitialize(), XSpi_LookupConfig(), XSpi_SetOptions(), XSpi_SetSlaveSelect(), XSpi_SetStatusHandler(), and XSpi_Start().

int SpiFlashBulkErase | ( | XSpi * | SpiPtr | ) |

This function erases the entire contents of the Numonyx Serial Flash device.

This function erases the entire contents of the Winbond Serial Flash device.

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 SpiFlashEnableHPM | ( | XSpi * | SpiPtr | ) |

This function enabled High Performance Mode in Winbond flash, so that data can be read from the flash using DIO and QIO commands.

Parameters

  None |

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  None.

References SpiFlashWriteEnable(), and XSpi_Transfer().

Referenced by main().

int SpiFlashGetStatus | ( | XSpi * | SpiPtr | ) |

This function reads the Status register of the Numonyx Flash.

This function reads the Status register of the Winbond 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 SpiFlashQuadEnable | ( | XSpi * | SpiPtr | ) |

This function sets the QuadEnable bit in Winbond flash.

Parameters

  None |

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  None.

References SpiFlashWriteEnable(), and XSpi_Transfer().

Referenced by main().

int SpiFlashRead | ( | XSpi * | SpiPtr,
|  | u32 | Addr,
|  | u32 | ByteCount,
|  | u8 | ReadCmd
| ) |  |

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

This function reads the data from the Winbond 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 READ_WRITE_EXTRA_BYTES, and XSpi_Transfer().

Referenced by main().

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

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

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

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 be read back as 0xFF.

References XSpi_Transfer().

Referenced by main().

int SpiFlashWrite | ( | XSpi * | SpiPtr,
|  | u32 | Addr,
|  | u32 | ByteCount,
|  | u8 | WriteCmd
| ) |  |

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

This function writes the data to the specified locations in the Winbond 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
  None

References READ_WRITE_EXTRA_BYTES, and XSpi_Transfer().

Referenced by main().

int SpiFlashWriteEnable | ( | XSpi * | SpiPtr | ) |

This function enables writes to the Numonyx Serial Flash memory.

This function enables writes to the Winbond 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(), SpiFlashEnableHPM(), and SpiFlashQuadEnable().

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.