lib/sw_services/xilisf/examples/xilisf_qspips_stm_polled_example.c
int FlashErase(XIsf *InstancePtr, u32 Address, u32 ByteCount)
{
	int Status = XST_FAILURE;
	int Sector;
	u32 LqspiCr;
	u32 NumSect;
	u32 SectorSize;
	u32 NumSectors;
	u32 Sector_Mask;
	/*
	 * Get the value of Sector Size and Number of Sectors for the flash
	 */
		SectorSize = Isf.SectorSize;
		NumSectors = Isf.NumSectors;

	/* Get the sector mask value */
		Sector_Mask = SectorMask(SectorSize);

	/*
	 * If erase size is same as the total size of the flash, use bulk erase
	 * command
	 */
	if (ByteCount == (NumSectors * SectorSize)) {

#ifdef XPAR_XQSPIPS_0_DEVICE_ID
		if(ConfigPtr->ConnectionMode ==
					XQSPIPS_CONNECTION_MODE_STACKED){

			/*
			 * Get the current LQSPI configuration register value
			 */
			LqspiCr =
			XQspiPs_GetLqspiConfigReg(InstancePtr->SpiInstPtr);
			/*
			 * Set selection to L_PAGE
			 */
			XQspiPs_SetLqspiConfigReg(InstancePtr->SpiInstPtr,
				LqspiCr & (~XQSPIPS_LQSPI_CR_U_PAGE_MASK));

			/*
			 * Assert the Flash chip select.
			 */
			XQspiPs_SetSlaveSelect(InstancePtr->SpiInstPtr);
		}
#endif	/*XPAR_XQSPIPS_0_DEVICE_ID*/

			/*
			 * Call Bulk erase
			 */
			Status = XIsf_Erase(InstancePtr,
						XISF_BULK_ERASE, Address);
			if(Status != XST_SUCCESS) {
				return XST_FAILURE;
			}

#ifdef XPAR_XQSPIPS_0_DEVICE_ID
			/*
			 * If stacked mode, bulk erase second flash
			 */
			if(ConfigPtr->ConnectionMode ==
					XQSPIPS_CONNECTION_MODE_STACKED){

			/*
			 * Get the current LQSPI configuration register value
			 */
			LqspiCr =
			XQspiPs_GetLqspiConfigReg(InstancePtr->SpiInstPtr);
			/*
			 * Set selection to U_PAGE
			 */
			XQspiPs_SetLqspiConfigReg(InstancePtr->SpiInstPtr,
				LqspiCr | XQSPIPS_LQSPI_CR_U_PAGE_MASK);

			/*
			 * Assert the Flash chip select.
			 */
			XQspiPs_SetSlaveSelect(InstancePtr->SpiInstPtr);


			/*
			 * Call Bulk erase
			 */
			Status = XIsf_Erase(InstancePtr,
						XISF_BULK_ERASE, Address);
			if(Status != XST_SUCCESS) {
				return XST_FAILURE;
			}
		}
#endif	/*XPAR_XQSPIPS_0_DEVICE_ID*/

		return Status;
	}

	/*
	 * Calculate no. of sectors to erase based on byte count
	 */
	NumSect = ByteCount/SectorSize + 1;

	/*
	 * If ByteCount to k sectors,
	 * but the address range spans from N to N+k+1 sectors, then
	 * increment no. of sectors to be erased
	 */

	if( ((Address + ByteCount) & Sector_Mask) ==
			((Address + (NumSect * SectorSize)) &
					Sector_Mask) ) {
		NumSect++;
	}

	/*
	 * If the erase size is less than the total size of the flash, use
	 * sector erase command
	 */
	for (Sector = 0; Sector < NumSect; Sector++) {

		/*
		 * Perform the Sector Erase operation.
		 */
		Status = XIsf_Erase(InstancePtr, XISF_SECTOR_ERASE, Address);
		if(Status != XST_SUCCESS) {
			return XST_FAILURE;
		}

		Address += SectorSize;
	}
	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* This function erases the sectors in the  serial FLASH connected to the
* QSPI interface.
*
* @param	InstancePtr is a pointer to the XIsf 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 .
int FlashErase(XIsf *InstancePtr, u32 Address, u32 ByteCount)
{
	int Status = XST_FAILURE;
	int Sector;
	u32 LqspiCr;
	u32 NumSect;
	u32 SectorSize;
	u32 NumSectors;
	u32 Sector_Mask;
		SectorSize = Isf.SectorSize;
		NumSectors = Isf.NumSectors;
		Sector_Mask = SectorMask(SectorSize);
	if (ByteCount == (NumSectors * SectorSize)) {
#ifdef XPAR_XQSPIPS_0_DEVICE_ID
		if(ConfigPtr->ConnectionMode ==
					XQSPIPS_CONNECTION_MODE_STACKED){
			LqspiCr =
			XQspiPs_GetLqspiConfigReg(InstancePtr->SpiInstPtr);
			XQspiPs_SetLqspiConfigReg(InstancePtr->SpiInstPtr,
				LqspiCr & (~XQSPIPS_LQSPI_CR_U_PAGE_MASK));
			XQspiPs_SetSlaveSelect(InstancePtr->SpiInstPtr);
		}
#endif	
			Status = XIsf_Erase(InstancePtr,
						XISF_BULK_ERASE, Address);
			if(Status != XST_SUCCESS) {
				return XST_FAILURE;
			}
#ifdef XPAR_XQSPIPS_0_DEVICE_ID
			if(ConfigPtr->ConnectionMode ==
					XQSPIPS_CONNECTION_MODE_STACKED){
			LqspiCr =
			XQspiPs_GetLqspiConfigReg(InstancePtr->SpiInstPtr);
			XQspiPs_SetLqspiConfigReg(InstancePtr->SpiInstPtr,
				LqspiCr | XQSPIPS_LQSPI_CR_U_PAGE_MASK);
			XQspiPs_SetSlaveSelect(InstancePtr->SpiInstPtr);
			Status = XIsf_Erase(InstancePtr,
						XISF_BULK_ERASE, Address);
			if(Status != XST_SUCCESS) {
				return XST_FAILURE;
			}
		}
#endif	
		return Status;
	}
	NumSect = ByteCount/SectorSize + 1;
	if( ((Address + ByteCount) & Sector_Mask) ==
			((Address + (NumSect * SectorSize)) &
					Sector_Mask) ) {
		NumSect++;
	}
	for (Sector = 0; Sector < NumSect; Sector++) {
		Status = XIsf_Erase(InstancePtr, XISF_SECTOR_ERASE, Address);
		if(Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
		Address += SectorSize;
	}
	return XST_SUCCESS;
}
int FlashErase ( XIsf * InstancePtr , u32 Address , u32 ByteCount ) { int Status = XST_FAILURE ; int Sector ; u32 LqspiCr ; u32 NumSect ; u32 SectorSize ; u32 NumSectors ; u32 Sector_Mask ; SectorSize = Isf . SectorSize ; NumSectors = Isf . NumSectors ; Sector_Mask = SectorMask ( SectorSize ) ; if ( ByteCount == ( NumSectors * SectorSize ) ) { #ifdef XPAR_XQSPIPS_0_DEVICE_ID if ( ConfigPtr -> ConnectionMode == XQSPIPS_CONNECTION_MODE_STACKED ) { LqspiCr = XQspiPs_GetLqspiConfigReg ( InstancePtr -> SpiInstPtr ) ; XQspiPs_SetLqspiConfigReg ( InstancePtr -> SpiInstPtr , LqspiCr & ( ~ XQSPIPS_LQSPI_CR_U_PAGE_MASK ) ) ; XQspiPs_SetSlaveSelect ( InstancePtr -> SpiInstPtr ) ; } #endif Status = XIsf_Erase ( InstancePtr , XISF_BULK_ERASE , Address ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } #ifdef XPAR_XQSPIPS_0_DEVICE_ID if ( ConfigPtr -> ConnectionMode == XQSPIPS_CONNECTION_MODE_STACKED ) { LqspiCr = XQspiPs_GetLqspiConfigReg ( InstancePtr -> SpiInstPtr ) ; XQspiPs_SetLqspiConfigReg ( InstancePtr -> SpiInstPtr , LqspiCr | XQSPIPS_LQSPI_CR_U_PAGE_MASK ) ; XQspiPs_SetSlaveSelect ( InstancePtr -> SpiInstPtr ) ; Status = XIsf_Erase ( InstancePtr , XISF_BULK_ERASE , Address ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } } #endif return Status ; } NumSect = ByteCount / SectorSize + 1 ; if ( ( ( Address + ByteCount ) & Sector_Mask ) == ( ( Address + ( NumSect * SectorSize ) ) & Sector_Mask ) ) { NumSect ++ ; } for ( Sector = 0 ; Sector < NumSect ; Sector ++ ) { Status = XIsf_Erase ( InstancePtr , XISF_SECTOR_ERASE , Address ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Address += SectorSize ; } return XST_SUCCESS ; }
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 .
/*
	 * Get the value of Sector Size and Number of Sectors for the flash
	 */ /* Get the sector mask value */ /*
	 * If erase size is same as the total size of the flash, use bulk erase
	 * command
	 */ /*
			 * Get the current LQSPI configuration register value
			 */ /*
			 * Set selection to L_PAGE
			 */ /*
			 * Assert the Flash chip select.
			 */ /*XPAR_XQSPIPS_0_DEVICE_ID*/ /*
			 * Call Bulk erase
			 */ /*
			 * If stacked mode, bulk erase second flash
			 */ /*
			 * Get the current LQSPI configuration register value
			 */ /*
			 * Set selection to U_PAGE
			 */ /*
			 * Assert the Flash chip select.
			 */ /*
			 * Call Bulk erase
			 */ /*XPAR_XQSPIPS_0_DEVICE_ID*/ /*
	 * Calculate no. of sectors to erase based on byte count
	 */ /*
	 * If ByteCount to k sectors,
	 * but the address range spans from N to N+k+1 sectors, then
	 * increment no. of sectors to be erased
	 */ /*
	 * If the erase size is less than the total size of the flash, use
	 * sector erase command
	 */ /*
		 * Perform the Sector Erase operation.
		 */