spi
Vitis Drivers API Documentation
xspi_stm_flash_example.c File Reference

Overview

This file contains a design example using the SPI driver (XSpi) and hardware device with an STM serial Flash device (M25P series) 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 M25P16 device. The bytes per page (STM_PAGE_SIZE) in M25P16 is 256.

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/28/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.

Macros

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

Functions

int SpiStmFlashWriteEnable (XSpi *SpiPtr)
 This function enables writes to the STM Serial Flash memory. More...
 
int SpiStmFlashWrite (XSpi *SpiPtr, u32 Addr, u32 ByteCount)
 This function writes the data to the specified locations in the STM Serial Flash memory. More...
 
int SpiStmFlashRead (XSpi *SpiPtr, u32 Addr, u32 ByteCount)
 This function reads the data from the STM Serial Flash Memory. More...
 
int SpiStmFlashBulkErase (XSpi *SpiPtr)
 This function erases the entire contents of the STM Serial Flash device. More...
 
int SpiStmFlashSectorErase (XSpi *SpiPtr, u32 Addr)
 This function erases the contents of the specified Sector in the STM Serial Flash device. More...
 
int SpiStmFlashGetStatus (XSpi *SpiPtr)
 This function reads the Status register of the STM 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...
 

Macro Definition Documentation

#define STM_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(), SpiStmFlashRead(), and SpiStmFlashWrite().

Function Documentation

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.
int SpiStmFlashBulkErase ( XSpi SpiPtr)

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

Parameters
SpiPtris 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 SpiStmFlashGetStatus ( XSpi SpiPtr)

This function reads the Status register of the STM Flash.

Parameters
SpiPtris 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 SpiStmFlashRead ( XSpi SpiPtr,
u32  Addr,
u32  ByteCount 
)

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

Parameters
SpiPtris a pointer to the instance of the Spi device.
Addris the starting address in the Flash Memory from which the data is to be read.
ByteCountis the number of bytes to be read.
Returns
XST_SUCCESS if successful else XST_FAILURE.
Note
None

References STM_READ_WRITE_EXTRA_BYTES, and XSpi_Transfer().

Referenced by main().

int SpiStmFlashSectorErase ( XSpi SpiPtr,
u32  Addr 
)

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

Parameters
SpiPtris a pointer to the instance of the Spi device.
Addris 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 SpiStmFlashWrite ( XSpi SpiPtr,
u32  Addr,
u32  ByteCount 
)

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

Parameters
SpiPtris a pointer to the instance of the Spi device.
Addris the address in the Buffer, where to write the data.
ByteCountis the number of bytes to be written.
Returns
XST_SUCCESS if successful else XST_FAILURE.
Note
None

References STM_READ_WRITE_EXTRA_BYTES, and XSpi_Transfer().

Referenced by main().

int SpiStmFlashWriteEnable ( XSpi SpiPtr)

This function enables writes to the STM Serial Flash memory.

Parameters
SpiPtris 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().