| spi Vitis Drivers API Documentation

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

Functions
xspi_atmel_flash_example.c File Reference

## Overview

This file contains a design example using the SPI driver (XSpi) and hardware device with an Atmel Serial Flash Device (AT45XX series).

This example erases the Page, writes to the Page, reads back from the Page and compares the data.

This example works for an Atmel AT45DB161D. The bytes per page (ATMEL_PAGE_SIZE) in this device is 528 bytes for default addressing mode and 512 bytes in Power-of-2 addressing mode. For further details of device refer to the Atmel Datasheet of AT45DB161D device.

The ATMEL_PAGE_SIZE constant need to be updated by the user according to the Device used.

The ATMEL_FLASH_TEST_ADDRESS constant need to be updated by the user according to the serial flash device used, there is no error checking done in the example for the address specified by the user.

This example also works with the In-System Flash(ISF) in the S3AN devices. The ATMEL_PAGE_SIZE and ATMEL_FLASH_TEST_ADDRESS need to be defined properly based on the device used. For further details of the ISF refer to the Spartan-3AN FPGA In-System Flash User Guide (UG333).

This example assumes that the underlying processor is MicroBlaze and default addressing mode is used in the Flash Device.

Note

None.

    MODIFICATION HISTORY:

    Ver   Who  Date     Changes

    1.00a sdn  02/26/08 First release
    1.00a sdn  07/02/08 Changed the initialization so that the SPI
                  Master works in Spi Mode 3 as the In-System Flash
                  works only in Spi Mode 3
    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
void | SpiHandler (void *CallBackRef, u32 StatusEvent, unsigned int ByteCount)
| This function is the handler which performs processing for the SPI driver. More...
int | SpiAtmelFlashRead (XSpi *SpiPtr, u32 Address, u16 ByteCount)
| This function reads data from the Atmel Flash device connected to the SPI interface. More...
int | SpiAtmelFlashWrite (XSpi *SpiPtr, u32 Address, u16 ByteCount)
| This function writes to the Atmel Flash device connected to the SPI interface. More...
int | SpiAtmelFlashPageErase (XSpi *SpiPtr, u32 Address)
| This function erases the contents of the specified Page in the Flash. More...
int | main (void)
| Main function to execute the Atmel Flash example. More...

## Function Documentation

int main | ( | void |  | ) |

Main function to execute the Atmel Flash example.

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  None

References XSpi_Config::BaseAddress, SpiAtmelFlashPageErase(), SpiAtmelFlashRead(), SpiAtmelFlashWrite(), SpiHandler(), XSP_MASTER_OPTION, XSpi_CfgInitialize(), XSpi_InterruptHandler(), XSpi_LookupConfig(), XSpi_SetOptions(), XSpi_SetSlaveSelect(), XSpi_SetStatusHandler(), and XSpi_Start().

int SpiAtmelFlashPageErase | ( | XSpi * | SpiPtr,
|  | u32 | Address
| ) |  |

This function erases the contents of the specified Page in the Flash.

Parameters

  SpiPtr | is a pointer to the SPI driver component to use.
  Address | contains the address of the page to be erased.

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  None.

References XSpi_Transfer().

Referenced by main().

int SpiAtmelFlashRead | ( | XSpi * | SpiPtr,
|  | u32 | Address,
|  | u16 | ByteCount
| ) |  |

This function reads data from the Atmel Flash device connected to the SPI interface.

Parameters

  SpiPtr | is a pointer to the SPI driver component to use.
  Address | is the address from which the data is to be read from the Flash.
  ByteCount | is the number of bytes to read.

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  None.

References XSpi_Transfer().

Referenced by main().

int SpiAtmelFlashWrite | ( | XSpi * | SpiPtr,
|  | u32 | Address,
|  | u16 | ByteCount
| ) |  |

This function writes to the Atmel Flash device connected to the SPI interface.

Parameters

  SpiPtr | is a pointer to the SPI driver component to use.
  Address | is the address to which the data is written.
  ByteCount | contains the number of bytes to write.

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  None.

References XSpi_Transfer().

Referenced by main().

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.

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 but is application specific.

Parameters

  CallBackRef | is a reference passed to the handler.
  StatusEvent | is the status of the SPI .
  ByteCount | is the number of bytes transferred.

Returns
  None

Note
  None.

It is called from an interrupt context such that the amount of processing to be performed should be minimized. This handler provides an example of how to handle SPI interrupts but is application specific.

Parameters

  CallBackRef | is a reference passed to the handler.
  StatusEvent | is the status of the SPI.
  ByteCount | is the number of bytes transferred.

Returns
  None.

Note
  None.

Referenced by main().