XilinxProcessorIPLib/drivers/qspipsu/examples/xqspipsu_generic_nand_flash_polled_example.c
int FlashWrite(XQspiPsu *QspiPsuPtr, u32 Address, u32 ByteCount, u8 Command,
				u8 *WriteBfrPtr)
{
	u8 WriteEnableCmd;
	u8 ProgExeCmd;
	u8 WriteBuf[5];
	u16 PageAddr;
	int Status;

	PageAddr = Address / PageSize;

	/* Enable write enable */
	WriteEnableCmd = WRITE_ENABLE_CMD;

	FlashMsg[0].TxBfrPtr = &WriteEnableCmd;
	FlashMsg[0].RxBfrPtr = NULL;
	FlashMsg[0].ByteCount = 1;
	FlashMsg[0].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[0].Flags = XQSPIPSU_MSG_FLAG_TX;

	Status = XQspiPsu_PolledTransfer(QspiPsuPtr, FlashMsg, 1);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/* Load program data */
	WriteBuf[COMMAND_OFFSET]   = PAGE_DATA_LOAD;
	WriteBuf[ADDRESS_1_OFFSET] = 0x0;
	WriteBuf[ADDRESS_2_OFFSET] = 0x0;

	FlashMsg[0].TxBfrPtr = WriteBuf;
	FlashMsg[0].RxBfrPtr = NULL;
	FlashMsg[0].ByteCount = 3;
	FlashMsg[0].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[0].Flags = XQSPIPSU_MSG_FLAG_TX;

	FlashMsg[1].TxBfrPtr = WriteBfrPtr;
	FlashMsg[1].RxBfrPtr = NULL;
	FlashMsg[1].ByteCount = ByteCount;
	FlashMsg[1].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[1].Flags = XQSPIPSU_MSG_FLAG_TX;

	Status = XQspiPsu_PolledTransfer(QspiPsuPtr, FlashMsg, 2);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/* Program execute */
	ProgExeCmd = PROG_EXEC_CMD;

	WriteBuf[0] = (u8)((PageAddr & 0xFF00) >> 8);
	WriteBuf[1] = (u8)(PageAddr & 0xFF);

	FlashMsg[0].TxBfrPtr = &ProgExeCmd;
	FlashMsg[0].RxBfrPtr = NULL;
	FlashMsg[0].ByteCount = 1;
	FlashMsg[0].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[0].Flags = XQSPIPSU_MSG_FLAG_TX;

	FlashMsg[1].TxBfrPtr = NULL;
	FlashMsg[1].RxBfrPtr = NULL;
	FlashMsg[1].ByteCount = DUMMY_CLOCKS;
	FlashMsg[1].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[1].Flags = 0;

	FlashMsg[2].TxBfrPtr = WriteBuf;
	FlashMsg[2].RxBfrPtr = NULL;
	FlashMsg[2].ByteCount = 2;
	FlashMsg[2].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[2].Flags = XQSPIPSU_MSG_FLAG_TX;

	Status = XQspiPsu_PolledTransfer(QspiPsuPtr, FlashMsg, 3);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/* Check flash is busy */
	Status = FlashIsNotBusy(QspiPsuPtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
 *
 * This function writes to the  serial Flash connected to the QSPIPSU interface.
 *
 * @param	QspiPsuPtr is a pointer to the QSPIPSU driver component to use.
 * @param	Address contains the address to write data to in the Flash.
 * @param	ByteCount contains the number of bytes to write.
 * @param	Command is the command used to write data to the flash.
 * @param	Pointer to the write buffer (which is to be transmitted)
 *
 * @return	XST_SUCCESS if successful, else XST_FAILURE.
 *
 * @note	None.
 *
 ******************************************************************************/
This function writes to the  serial Flash connected to the QSPIPSU interface.
@param       QspiPsuPtr is a pointer to the QSPIPSU driver component to use.
@param       Address contains the address to write data to in the Flash.
@param       ByteCount contains the number of bytes to write.
@param       Command is the command used to write data to the flash.
@param       Pointer to the write buffer (which is to be transmitted)



@note        None.
This function writes to the serial Flash connected to the QSPIPSU interface . @param QspiPsuPtr is a pointer to the QSPIPSU driver component to use . @param Address contains the address to write data to in the Flash . @param ByteCount contains the number of bytes to write . @param Command is the command used to write data to the flash . @param Pointer to the write buffer ( which is to be transmitted ) @note None .
int FlashWrite(XQspiPsu *QspiPsuPtr, u32 Address, u32 ByteCount, u8 Command,
				u8 *WriteBfrPtr)
{
	u8 WriteEnableCmd;
	u8 ProgExeCmd;
	u8 WriteBuf[5];
	u16 PageAddr;
	int Status;
	PageAddr = Address / PageSize;
	WriteEnableCmd = WRITE_ENABLE_CMD;
	FlashMsg[0].TxBfrPtr = &WriteEnableCmd;
	FlashMsg[0].RxBfrPtr = NULL;
	FlashMsg[0].ByteCount = 1;
	FlashMsg[0].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[0].Flags = XQSPIPSU_MSG_FLAG_TX;
	Status = XQspiPsu_PolledTransfer(QspiPsuPtr, FlashMsg, 1);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	WriteBuf[COMMAND_OFFSET]   = PAGE_DATA_LOAD;
	WriteBuf[ADDRESS_1_OFFSET] = 0x0;
	WriteBuf[ADDRESS_2_OFFSET] = 0x0;
	FlashMsg[0].TxBfrPtr = WriteBuf;
	FlashMsg[0].RxBfrPtr = NULL;
	FlashMsg[0].ByteCount = 3;
	FlashMsg[0].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[0].Flags = XQSPIPSU_MSG_FLAG_TX;
	FlashMsg[1].TxBfrPtr = WriteBfrPtr;
	FlashMsg[1].RxBfrPtr = NULL;
	FlashMsg[1].ByteCount = ByteCount;
	FlashMsg[1].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[1].Flags = XQSPIPSU_MSG_FLAG_TX;
	Status = XQspiPsu_PolledTransfer(QspiPsuPtr, FlashMsg, 2);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	ProgExeCmd = PROG_EXEC_CMD;
	WriteBuf[0] = (u8)((PageAddr & 0xFF00) >> 8);
	WriteBuf[1] = (u8)(PageAddr & 0xFF);
	FlashMsg[0].TxBfrPtr = &ProgExeCmd;
	FlashMsg[0].RxBfrPtr = NULL;
	FlashMsg[0].ByteCount = 1;
	FlashMsg[0].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[0].Flags = XQSPIPSU_MSG_FLAG_TX;
	FlashMsg[1].TxBfrPtr = NULL;
	FlashMsg[1].RxBfrPtr = NULL;
	FlashMsg[1].ByteCount = DUMMY_CLOCKS;
	FlashMsg[1].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[1].Flags = 0;
	FlashMsg[2].TxBfrPtr = WriteBuf;
	FlashMsg[2].RxBfrPtr = NULL;
	FlashMsg[2].ByteCount = 2;
	FlashMsg[2].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[2].Flags = XQSPIPSU_MSG_FLAG_TX;
	Status = XQspiPsu_PolledTransfer(QspiPsuPtr, FlashMsg, 3);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = FlashIsNotBusy(QspiPsuPtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	return XST_SUCCESS;
}
int FlashWrite ( XQspiPsu * QspiPsuPtr , u32 Address , u32 ByteCount , u8 Command , u8 * WriteBfrPtr ) { u8 WriteEnableCmd ; u8 ProgExeCmd ; u8 WriteBuf [ 5 ] ; u16 PageAddr ; int Status ; PageAddr = Address / PageSize ; WriteEnableCmd = WRITE_ENABLE_CMD ; FlashMsg [ 0 ] . TxBfrPtr = & WriteEnableCmd ; FlashMsg [ 0 ] . RxBfrPtr = NULL ; FlashMsg [ 0 ] . ByteCount = 1 ; FlashMsg [ 0 ] . BusWidth = XQSPIPSU_SELECT_MODE_SPI ; FlashMsg [ 0 ] . Flags = XQSPIPSU_MSG_FLAG_TX ; Status = XQspiPsu_PolledTransfer ( QspiPsuPtr , FlashMsg , 1 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } WriteBuf [ COMMAND_OFFSET ] = PAGE_DATA_LOAD ; WriteBuf [ ADDRESS_1_OFFSET ] = 0x0 ; WriteBuf [ ADDRESS_2_OFFSET ] = 0x0 ; FlashMsg [ 0 ] . TxBfrPtr = WriteBuf ; FlashMsg [ 0 ] . RxBfrPtr = NULL ; FlashMsg [ 0 ] . ByteCount = 3 ; FlashMsg [ 0 ] . BusWidth = XQSPIPSU_SELECT_MODE_SPI ; FlashMsg [ 0 ] . Flags = XQSPIPSU_MSG_FLAG_TX ; FlashMsg [ 1 ] . TxBfrPtr = WriteBfrPtr ; FlashMsg [ 1 ] . RxBfrPtr = NULL ; FlashMsg [ 1 ] . ByteCount = ByteCount ; FlashMsg [ 1 ] . BusWidth = XQSPIPSU_SELECT_MODE_SPI ; FlashMsg [ 1 ] . Flags = XQSPIPSU_MSG_FLAG_TX ; Status = XQspiPsu_PolledTransfer ( QspiPsuPtr , FlashMsg , 2 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } ProgExeCmd = PROG_EXEC_CMD ; WriteBuf [ 0 ] = ( u8 ) ( ( PageAddr & 0xFF00 ) >> 8 ) ; WriteBuf [ 1 ] = ( u8 ) ( PageAddr & 0xFF ) ; FlashMsg [ 0 ] . TxBfrPtr = & ProgExeCmd ; FlashMsg [ 0 ] . RxBfrPtr = NULL ; FlashMsg [ 0 ] . ByteCount = 1 ; FlashMsg [ 0 ] . BusWidth = XQSPIPSU_SELECT_MODE_SPI ; FlashMsg [ 0 ] . Flags = XQSPIPSU_MSG_FLAG_TX ; FlashMsg [ 1 ] . TxBfrPtr = NULL ; FlashMsg [ 1 ] . RxBfrPtr = NULL ; FlashMsg [ 1 ] . ByteCount = DUMMY_CLOCKS ; FlashMsg [ 1 ] . BusWidth = XQSPIPSU_SELECT_MODE_SPI ; FlashMsg [ 1 ] . Flags = 0 ; FlashMsg [ 2 ] . TxBfrPtr = WriteBuf ; FlashMsg [ 2 ] . RxBfrPtr = NULL ; FlashMsg [ 2 ] . ByteCount = 2 ; FlashMsg [ 2 ] . BusWidth = XQSPIPSU_SELECT_MODE_SPI ; FlashMsg [ 2 ] . Flags = XQSPIPSU_MSG_FLAG_TX ; Status = XQspiPsu_PolledTransfer ( QspiPsuPtr , FlashMsg , 3 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = FlashIsNotBusy ( QspiPsuPtr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } return XST_SUCCESS ; }
This function writes to the  serial Flash connected to the QSPIPSU interface.
This function writes to the serial Flash connected to the QSPIPSU interface .
/* Enable write enable */ /* Load program data */ /* Program execute */ /* Check flash is busy */