XilinxProcessorIPLib/drivers/spi/examples/xspi_stm_flash_example.c
int SpiStmFlashWrite(XSpi *SpiPtr, u32 Addr, u32 ByteCount)
{
	u32 Index;
	int Status;

	/*
	 * Prepare the WriteBuffer.
	 */
	WriteBuffer[BYTE1] = STM_COMMAND_PAGEPROGRAM_WRITE;
	WriteBuffer[BYTE2] = (u8) (Addr >> 16);
	WriteBuffer[BYTE3] = (u8) (Addr >> 8);
	WriteBuffer[BYTE4] = (u8) Addr;


	/*
	 * Fill in the TEST data that is to be written into the STM Serial Flash
	 * device.
	 */
	for(Index = 4; Index < ByteCount + STM_READ_WRITE_EXTRA_BYTES;
								Index++) {
		WriteBuffer[Index] = (u8)((Index - 4) + STM_FLASH_TEST_BYTE);
	}

	/*
	 * Initiate the Transfer.
	 */
	TransferInProgress = TRUE;
	Status = XSpi_Transfer(SpiPtr, WriteBuffer, NULL,
				(ByteCount + STM_READ_WRITE_EXTRA_BYTES));
	if(Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Wait till the Transfer is complete and check if there are any errors
	 * in the transaction..
	 */
	while(TransferInProgress);
	if(ErrorCount != 0) {
		ErrorCount = 0;
		return XST_FAILURE;
	}

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* This function writes the data to the specified locations in the STM Serial
* Flash memory.
*
* @param	SpiPtr is a pointer to the instance of the Spi device.
* @param	Addr is the address in the Buffer, where to write the data.
* @param	ByteCount is the number of bytes to be written.
*
* @return	XST_SUCCESS if successful else XST_FAILURE.
*
* @note		None
*
******************************************************************************/
This function writes the data to the specified locations in the STM Serial
Flash memory.
This function writes the data to the specified locations in the STM Serial Flash memory .
int SpiStmFlashWrite(XSpi *SpiPtr, u32 Addr, u32 ByteCount)
{
	u32 Index;
	int Status;
	WriteBuffer[BYTE1] = STM_COMMAND_PAGEPROGRAM_WRITE;
	WriteBuffer[BYTE2] = (u8) (Addr >> 16);
	WriteBuffer[BYTE3] = (u8) (Addr >> 8);
	WriteBuffer[BYTE4] = (u8) Addr;
	for(Index = 4; Index < ByteCount + STM_READ_WRITE_EXTRA_BYTES;
								Index++) {
		WriteBuffer[Index] = (u8)((Index - 4) + STM_FLASH_TEST_BYTE);
	}
	TransferInProgress = TRUE;
	Status = XSpi_Transfer(SpiPtr, WriteBuffer, NULL,
				(ByteCount + STM_READ_WRITE_EXTRA_BYTES));
	if(Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	while(TransferInProgress);
	if(ErrorCount != 0) {
		ErrorCount = 0;
		return XST_FAILURE;
	}
	return XST_SUCCESS;
}
int SpiStmFlashWrite ( XSpi * SpiPtr , u32 Addr , u32 ByteCount ) { u32 Index ; int Status ; WriteBuffer [ BYTE1 ] = STM_COMMAND_PAGEPROGRAM_WRITE ; WriteBuffer [ BYTE2 ] = ( u8 ) ( Addr >> 16 ) ; WriteBuffer [ BYTE3 ] = ( u8 ) ( Addr >> 8 ) ; WriteBuffer [ BYTE4 ] = ( u8 ) Addr ; for ( Index = 4 ; Index < ByteCount + STM_READ_WRITE_EXTRA_BYTES ; Index ++ ) { WriteBuffer [ Index ] = ( u8 ) ( ( Index - 4 ) + STM_FLASH_TEST_BYTE ) ; } TransferInProgress = TRUE ; Status = XSpi_Transfer ( SpiPtr , WriteBuffer , NULL , ( ByteCount + STM_READ_WRITE_EXTRA_BYTES ) ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } while ( TransferInProgress ) ; if ( ErrorCount != 0 ) { ErrorCount = 0 ; return XST_FAILURE ; } return XST_SUCCESS ; }
This function writes the data to the specified locations in the STM Serial
Flash memory.
This function writes the data to the specified locations in the STM Serial Flash memory .
/*
	 * Prepare the WriteBuffer.
	 */ /*
	 * Fill in the TEST data that is to be written into the STM Serial Flash
	 * device.
	 */ /*
	 * Initiate the Transfer.
	 */ /*
	 * Wait till the Transfer is complete and check if there are any errors
	 * in the transaction..
	 */