XilinxProcessorIPLib/drivers/qspips/examples/xqspips_dual_flash_lqspi_example.c
void FlashErase(XQspiPs *QspiPtr, u32 Address, u32 ByteCount)
{
	u8 WriteEnableCmd = { WRITE_ENABLE_CMD };
	u8 ReadStatusCmd[] = { READ_STATUS_CMD, 0 };  /* must send 2 bytes */
	u8 FlashStatus[2];
	u32 RealAddr;
	int Sector;

	/*
	 * If erase size is same as the total size of the flash, use bulk erase
	 * command
	 */
	if (ByteCount == (NUM_SECTORS * SECTOR_SIZE)) {
		/*
		 * Send the write enable command to the FLASH so that it can be
		 * written to, this needs to be sent as a separate transfer
		 * before the erase
		 */
		XQspiPs_PolledTransfer(QspiPtr, &WriteEnableCmd, NULL,
				  sizeof(WriteEnableCmd));

		/* Setup the bulk erase command*/
		WriteBuffer[COMMAND_OFFSET]   = BULK_ERASE_CMD;

		/*
		 * Send the bulk erase command; no receive buffer is specified
		 * since there is nothing to receive
		 */
		XQspiPs_PolledTransfer(QspiPtr, WriteBuffer, NULL,
					BULK_ERASE_SIZE);

		/* Wait for the erase command to the FLASH to be completed*/
		while (1) {
			/*
			 * Poll the status register of the device to determine
			 * when it completes, by sending a read status command
			 * and receiving the status byte
			 */
			XQspiPs_PolledTransfer(QspiPtr, ReadStatusCmd,
						FlashStatus,
						sizeof(ReadStatusCmd));

			/*
			 * If the status indicates the write is done, then stop
			 * waiting; if a value of 0xFF in the status byte is
			 * read from the device and this loop never exits, the
			 * device slave select is possibly incorrect such that
			 * the device status is not being read
			 */
			FlashStatus[1] |= FlashStatus[0];
			if ((FlashStatus[1] & 0x01) == 0) {
				break;
			}
		}

		return;
	}

	/*
	 * If the erase size is less than the total size of the flash, use
	 * sector erase command
	 */
	for (Sector = 0; Sector < ((ByteCount / SECTOR_SIZE) + 1); Sector++) {
		/*
		 * Send the write enable command to the SEEPOM so that it can be
		 * written to, this needs to be sent as a separate transfer
		 * before the write
		 */
		XQspiPs_PolledTransfer(QspiPtr, &WriteEnableCmd, NULL,
				  sizeof(WriteEnableCmd));

		/*
		 * The effective sector address in each flash is the actual
		 * address / 2
		 */
		RealAddr = Address / 2;

		/*
		 * Setup the write command with the specified address and data
		 * for the FLASH
		 */
		WriteBuffer[COMMAND_OFFSET]   = SEC_ERASE_CMD;
		WriteBuffer[ADDRESS_1_OFFSET] = (u8)(RealAddr >> 16);
		WriteBuffer[ADDRESS_2_OFFSET] = (u8)(RealAddr >> 8);
		WriteBuffer[ADDRESS_3_OFFSET] = (u8)(RealAddr & 0xFF);

		/*
		 * Send the sector erase command and address; no receive buffer
		 * is specified since there is nothing to receive
		 */
		XQspiPs_PolledTransfer(QspiPtr, WriteBuffer, NULL,
					SEC_ERASE_SIZE);

		/*
		 * Wait for the sector erase command to the
		 * FLASH to be completed
		 */
		while (1) {
			/*
			 * Poll the status register of the device to determine
			 * when it completes, by sending a read status command
			 * and receiving the status byte
			 */
			XQspiPs_PolledTransfer(QspiPtr, ReadStatusCmd,
						FlashStatus,
						sizeof(ReadStatusCmd));

			/*
			 * If the status indicates the write is done, then stop
			 * waiting, if a value of 0xFF in the status byte is
			 * read from the device and this loop never exits, the
			 * device slave select is possibly incorrect such that
			 * the device status is not being read
			 */
			FlashStatus[1] |= FlashStatus[0];
			if ((FlashStatus[1] & 0x01) == 0) {
				break;
			}
		}

		Address += SECTOR_SIZE;
	}
}
/*****************************************************************************/
/**
*
* This function erases the sectors in the  serial FLASH connected to the
* QSPI interface.
*
* @param	QspiPtr is a pointer to the QSPI driver component to use.
* @param	Address contains the address of the first sector which needs to
*		be erased.
* @param	ByteCount contains the total size to be erased.
*
* @return	None.
*
* @note		None.
*
******************************************************************************/
This function erases the sectors in the  serial FLASH connected to the
QSPI interface.
This function erases the sectors in the serial FLASH connected to the QSPI interface .
void FlashErase(XQspiPs *QspiPtr, u32 Address, u32 ByteCount)
{
	u8 WriteEnableCmd = { WRITE_ENABLE_CMD };
	u8 ReadStatusCmd[] = { READ_STATUS_CMD, 0 };  
	u8 FlashStatus[2];
	u32 RealAddr;
	int Sector;
	if (ByteCount == (NUM_SECTORS * SECTOR_SIZE)) {
		XQspiPs_PolledTransfer(QspiPtr, &WriteEnableCmd, NULL,
				  sizeof(WriteEnableCmd));
		WriteBuffer[COMMAND_OFFSET]   = BULK_ERASE_CMD;
		XQspiPs_PolledTransfer(QspiPtr, WriteBuffer, NULL,
					BULK_ERASE_SIZE);
		while (1) {
			XQspiPs_PolledTransfer(QspiPtr, ReadStatusCmd,
						FlashStatus,
						sizeof(ReadStatusCmd));
			FlashStatus[1] |= FlashStatus[0];
			if ((FlashStatus[1] & 0x01) == 0) {
				break;
			}
		}
		return;
	}
	for (Sector = 0; Sector < ((ByteCount / SECTOR_SIZE) + 1); Sector++) {
		XQspiPs_PolledTransfer(QspiPtr, &WriteEnableCmd, NULL,
				  sizeof(WriteEnableCmd));
		RealAddr = Address / 2;
		WriteBuffer[COMMAND_OFFSET]   = SEC_ERASE_CMD;
		WriteBuffer[ADDRESS_1_OFFSET] = (u8)(RealAddr >> 16);
		WriteBuffer[ADDRESS_2_OFFSET] = (u8)(RealAddr >> 8);
		WriteBuffer[ADDRESS_3_OFFSET] = (u8)(RealAddr & 0xFF);
		XQspiPs_PolledTransfer(QspiPtr, WriteBuffer, NULL,
					SEC_ERASE_SIZE);
		while (1) {
			XQspiPs_PolledTransfer(QspiPtr, ReadStatusCmd,
						FlashStatus,
						sizeof(ReadStatusCmd));
			FlashStatus[1] |= FlashStatus[0];
			if ((FlashStatus[1] & 0x01) == 0) {
				break;
			}
		}
		Address += SECTOR_SIZE;
	}
}
void FlashErase ( XQspiPs * QspiPtr , u32 Address , u32 ByteCount ) { u8 WriteEnableCmd = { WRITE_ENABLE_CMD } ; u8 ReadStatusCmd [ ] = { READ_STATUS_CMD , 0 } ; u8 FlashStatus [ 2 ] ; u32 RealAddr ; int Sector ; if ( ByteCount == ( NUM_SECTORS * SECTOR_SIZE ) ) { XQspiPs_PolledTransfer ( QspiPtr , & WriteEnableCmd , NULL , sizeof ( WriteEnableCmd ) ) ; WriteBuffer [ COMMAND_OFFSET ] = BULK_ERASE_CMD ; XQspiPs_PolledTransfer ( QspiPtr , WriteBuffer , NULL , BULK_ERASE_SIZE ) ; while ( 1 ) { XQspiPs_PolledTransfer ( QspiPtr , ReadStatusCmd , FlashStatus , sizeof ( ReadStatusCmd ) ) ; FlashStatus [ 1 ] |= FlashStatus [ 0 ] ; if ( ( FlashStatus [ 1 ] & 0x01 ) == 0 ) { break ; } } return ; } for ( Sector = 0 ; Sector < ( ( ByteCount / SECTOR_SIZE ) + 1 ) ; Sector ++ ) { XQspiPs_PolledTransfer ( QspiPtr , & WriteEnableCmd , NULL , sizeof ( WriteEnableCmd ) ) ; RealAddr = Address / 2 ; WriteBuffer [ COMMAND_OFFSET ] = SEC_ERASE_CMD ; WriteBuffer [ ADDRESS_1_OFFSET ] = ( u8 ) ( RealAddr >> 16 ) ; WriteBuffer [ ADDRESS_2_OFFSET ] = ( u8 ) ( RealAddr >> 8 ) ; WriteBuffer [ ADDRESS_3_OFFSET ] = ( u8 ) ( RealAddr & 0xFF ) ; XQspiPs_PolledTransfer ( QspiPtr , WriteBuffer , NULL , SEC_ERASE_SIZE ) ; while ( 1 ) { XQspiPs_PolledTransfer ( QspiPtr , ReadStatusCmd , FlashStatus , sizeof ( ReadStatusCmd ) ) ; FlashStatus [ 1 ] |= FlashStatus [ 0 ] ; if ( ( FlashStatus [ 1 ] & 0x01 ) == 0 ) { break ; } } Address += SECTOR_SIZE ; } }
This function erases the sectors in the  serial FLASH connected to the
QSPI interface.
This function erases the sectors in the serial FLASH connected to the QSPI interface .
/* must send 2 bytes */ /*
	 * If erase size is same as the total size of the flash, use bulk erase
	 * command
	 */ /*
		 * Send the write enable command to the FLASH so that it can be
		 * written to, this needs to be sent as a separate transfer
		 * before the erase
		 */ /* Setup the bulk erase command*/ /*
		 * Send the bulk erase command; no receive buffer is specified
		 * since there is nothing to receive
		 */ /* Wait for the erase command to the FLASH to be completed*/ /*
			 * Poll the status register of the device to determine
			 * when it completes, by sending a read status command
			 * and receiving the status byte
			 */ /*
			 * If the status indicates the write is done, then stop
			 * waiting; if a value of 0xFF in the status byte is
			 * read from the device and this loop never exits, the
			 * device slave select is possibly incorrect such that
			 * the device status is not being read
			 */ /*
	 * If the erase size is less than the total size of the flash, use
	 * sector erase command
	 */ /*
		 * Send the write enable command to the SEEPOM so that it can be
		 * written to, this needs to be sent as a separate transfer
		 * before the write
		 */ /*
		 * The effective sector address in each flash is the actual
		 * address / 2
		 */ /*
		 * Setup the write command with the specified address and data
		 * for the FLASH
		 */ /*
		 * Send the sector erase command and address; no receive buffer
		 * is specified since there is nothing to receive
		 */ /*
		 * Wait for the sector erase command to the
		 * FLASH to be completed
		 */ /*
			 * Poll the status register of the device to determine
			 * when it completes, by sending a read status command
			 * and receiving the status byte
			 */ /*
			 * If the status indicates the write is done, then stop
			 * waiting, if a value of 0xFF in the status byte is
			 * read from the device and this loop never exits, the
			 * device slave select is possibly incorrect such that
			 * the device status is not being read
			 */