spi
Vitis Drivers API Documentation
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  )
int SpiAtmelFlashPageErase ( XSpi SpiPtr,
u32  Address 
)

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

Parameters
SpiPtris a pointer to the SPI driver component to use.
Addresscontains 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
SpiPtris a pointer to the SPI driver component to use.
Addressis the address from which the data is to be read from the Flash.
ByteCountis 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
SpiPtris a pointer to the SPI driver component to use.
Addressis the address to which the data is written.
ByteCountcontains 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
CallBackRefis the upper layer callback reference passed back when the callback function is invoked.
StatusEventis the event that just occurred.
ByteCountis 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
CallBackRefis a reference passed to the handler.
StatusEventis the status of the SPI .
ByteCountis 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
CallBackRefis a reference passed to the handler.
StatusEventis the status of the SPI.
ByteCountis the number of bytes transferred.
Returns
None.
Note
None.

Referenced by main().