XilinxProcessorIPLib/drivers/qspips/examples/xqspips_g128_flash_example.c
int QspiG128FlashExample(XQspiPs *QspiInstancePtr, u16 QspiDeviceId)
{
	int Status;
	u8 UniqueValue;
	int Count;
	int Page;
	XQspiPs_Config *QspiConfig;

	/*
	 * Initialize the QSPI driver so that it's ready to use
	 */
	QspiConfig = XQspiPs_LookupConfig(QspiDeviceId);
	if (NULL == QspiConfig) {
		return XST_FAILURE;
	}

	Status = XQspiPs_CfgInitialize(QspiInstancePtr, QspiConfig,
					QspiConfig->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Perform a self-test to check hardware build
	 */
	Status = XQspiPs_SelfTest(QspiInstancePtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}



	/*
	 * Set the pre-scaler for QSPI clock
	 */
	XQspiPs_SetClkPrescaler(QspiInstancePtr, XQSPIPS_CLK_PRESCALE_8);

	/*
	 * Set Manual Start and Manual Chip select options and drive the
	 * HOLD_B high.
	 */
	XQspiPs_SetOptions(QspiInstancePtr, XQSPIPS_FORCE_SSELECT_OPTION |
					     XQSPIPS_MANUAL_START_OPTION |
					     XQSPIPS_HOLD_B_DRIVE_OPTION);
	if(QspiConfig->ConnectionMode == XQSPIPS_CONNECTION_MODE_STACKED) {
		/*
		 * Enable two flash memories, Shared bus (NOT separate bus),
		 * L_PAGE selected by default
		 */
		XQspiPs_SetLqspiConfigReg(QspiInstancePtr, DUAL_STACK_CONFIG_WRITE);
	}

	if(QspiConfig->ConnectionMode == XQSPIPS_CONNECTION_MODE_PARALLEL) {
		/*
		 * Enable two flash memories on separate buses
		 */
		XQspiPs_SetLqspiConfigReg(QspiInstancePtr, DUAL_QSPI_CONFIG_WRITE);
	}

	/*
	 * Assert the Flash chip select.
	 */
	XQspiPs_SetSlaveSelect(QspiInstancePtr);

	/*
	 * Read flash ID and obtain all flash related information
	 * It is important to call the read id function before
	 * performing proceeding to any operation, including
	 * preparing the WriteBuffer
	 */
	FlashReadID(QspiInstancePtr, WriteBuffer, ReadBuffer);

	/*
	 * Initialize MaxData according to page size.
	 */
	MaxData = PAGE_COUNT * (Flash_Config_Table[FCTIndex].PageSize);


	/*
	 * Initialize the write buffer for a pattern to write to the Flash
	 * and the read buffer to zero so it can be verified after the read, the
	 * test value that is added to the unique value allows the value to be
	 * changed in a debug environment to guarantee
	 */
	for (UniqueValue = UNIQUE_VALUE, Count = 0;
			Count < Flash_Config_Table[FCTIndex].PageSize;
			Count++, UniqueValue++) {
		WriteBuffer[DATA_OFFSET + Count] = (u8)(UniqueValue + Test);
	}
	memset(ReadBuffer, 0x00, sizeof(ReadBuffer));


	/*
	 * Erase the flash.
	 */
	FlashErase(QspiInstancePtr, TEST_ADDRESS, MaxData, WriteBuffer);

	/*
	 * Write the data in the write buffer to the serial Flash a page at a
	 * time, starting from TEST_ADDRESS
	 */
	for (Page = 0; Page < PAGE_COUNT; Page++) {
		FlashWrite(QspiInstancePtr,
			(Page * Flash_Config_Table[FCTIndex].PageSize) + TEST_ADDRESS,
			Flash_Config_Table[FCTIndex].PageSize, WRITE_CMD, WriteBuffer);
	}

	/*
	 * I/O Read - for any flash size
	 */
	FlashRead(QspiInstancePtr, TEST_ADDRESS, MaxData, QUAD_READ_CMD,
				WriteBuffer, ReadBuffer);

	/*
	 * Setup a pointer to the start of the data that was read into the read
	 * buffer and verify the data read is the data that was written
	 */
	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < MaxData;
	     Count++, UniqueValue++) {
		if (ReadBuffer[Count] != (u8)(UniqueValue + Test)) {
			return XST_FAILURE;
		}
	}

	/*
	 * Initialize the write buffer for a pattern to write to the Flash
	 * and the read buffer to zero so it can be verified after the read, the
	 * test value that is added to the unique value allows the value to be
	 * changed in a debug environment to guarantee
	 */
	for (UniqueValue = UNIQUE_VALUE, Count = 0;
			Count < Flash_Config_Table[FCTIndex].PageSize;
			Count++, UniqueValue++) {
		WriteBuffer[DATA_OFFSET + Count] = (u8)(UniqueValue + Test);
	}
	memset(ReadBuffer, 0x00, sizeof(ReadBuffer));

	/*
	 * Set Auto Start and Manual Chip select options and drive the
	 * HOLD_B high.
	 */
	XQspiPs_SetOptions(QspiInstancePtr, XQSPIPS_FORCE_SSELECT_OPTION |
					     XQSPIPS_HOLD_B_DRIVE_OPTION);

	/*
	 * Erase the flash.
	 */
	FlashErase(QspiInstancePtr, TEST_ADDRESS, MaxData, WriteBuffer);

	/*
	 * Write the data in the write buffer to the serial Flash a page at a
	 * time, starting from TEST_ADDRESS
	 */
	for (Page = 0; Page < PAGE_COUNT; Page++) {
		FlashWrite(QspiInstancePtr,
			(Page * Flash_Config_Table[FCTIndex].PageSize) + TEST_ADDRESS,
			Flash_Config_Table[FCTIndex].PageSize, WRITE_CMD, WriteBuffer);
	}

	/*
	 * I/O Read - for any flash size
	 */
	FlashRead(QspiInstancePtr, TEST_ADDRESS, MaxData, QUAD_READ_CMD,
				WriteBuffer, ReadBuffer);

	/*
	 * Setup a pointer to the start of the data that was read into the read
	 * buffer and verify the data read is the data that was written
	 */
	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < MaxData;
	     Count++, UniqueValue++) {
		if (ReadBuffer[Count] != (u8)(UniqueValue + Test)) {
			return XST_FAILURE;
		}
	}

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* The purpose of this function is to illustrate how to use the XQspiPs
* device driver in single, parallel and stacked modes using
* flash devices greater than 128Mb.
* This function reads and writes data in I/O mode.
*
* @param	QspiInstancePtr is a pointer to the QSPIPS driver to use.
* @param        QspiDeviceId is the XPAR_<QSPIPS_instance>_DEVICE_ID value
*               from xparameters.h
*
* @return	XST_SUCCESS if successful, else XST_FAILURE.
*
* @note		None.
*
*****************************************************************************/
The purpose of this function is to illustrate how to use the XQspiPs
device driver in single, parallel and stacked modes using
flash devices greater than 128Mb.
This function reads and writes data in I/O mode.
The purpose of this function is to illustrate how to use the XQspiPs device driver in single parallel and stacked modes using flash devices greater than 128Mb . This function reads and writes data in I / O mode .
int QspiG128FlashExample(XQspiPs *QspiInstancePtr, u16 QspiDeviceId)
{
	int Status;
	u8 UniqueValue;
	int Count;
	int Page;
	XQspiPs_Config *QspiConfig;
	QspiConfig = XQspiPs_LookupConfig(QspiDeviceId);
	if (NULL == QspiConfig) {
		return XST_FAILURE;
	}
	Status = XQspiPs_CfgInitialize(QspiInstancePtr, QspiConfig,
					QspiConfig->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = XQspiPs_SelfTest(QspiInstancePtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XQspiPs_SetClkPrescaler(QspiInstancePtr, XQSPIPS_CLK_PRESCALE_8);
	XQspiPs_SetOptions(QspiInstancePtr, XQSPIPS_FORCE_SSELECT_OPTION |
					     XQSPIPS_MANUAL_START_OPTION |
					     XQSPIPS_HOLD_B_DRIVE_OPTION);
	if(QspiConfig->ConnectionMode == XQSPIPS_CONNECTION_MODE_STACKED) {
		XQspiPs_SetLqspiConfigReg(QspiInstancePtr, DUAL_STACK_CONFIG_WRITE);
	}
	if(QspiConfig->ConnectionMode == XQSPIPS_CONNECTION_MODE_PARALLEL) {
		XQspiPs_SetLqspiConfigReg(QspiInstancePtr, DUAL_QSPI_CONFIG_WRITE);
	}
	XQspiPs_SetSlaveSelect(QspiInstancePtr);
	FlashReadID(QspiInstancePtr, WriteBuffer, ReadBuffer);
	MaxData = PAGE_COUNT * (Flash_Config_Table[FCTIndex].PageSize);
	for (UniqueValue = UNIQUE_VALUE, Count = 0;
			Count < Flash_Config_Table[FCTIndex].PageSize;
			Count++, UniqueValue++) {
		WriteBuffer[DATA_OFFSET + Count] = (u8)(UniqueValue + Test);
	}
	memset(ReadBuffer, 0x00, sizeof(ReadBuffer));
	FlashErase(QspiInstancePtr, TEST_ADDRESS, MaxData, WriteBuffer);
	for (Page = 0; Page < PAGE_COUNT; Page++) {
		FlashWrite(QspiInstancePtr,
			(Page * Flash_Config_Table[FCTIndex].PageSize) + TEST_ADDRESS,
			Flash_Config_Table[FCTIndex].PageSize, WRITE_CMD, WriteBuffer);
	}
	FlashRead(QspiInstancePtr, TEST_ADDRESS, MaxData, QUAD_READ_CMD,
				WriteBuffer, ReadBuffer);
	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < MaxData;
	     Count++, UniqueValue++) {
		if (ReadBuffer[Count] != (u8)(UniqueValue + Test)) {
			return XST_FAILURE;
		}
	}
	for (UniqueValue = UNIQUE_VALUE, Count = 0;
			Count < Flash_Config_Table[FCTIndex].PageSize;
			Count++, UniqueValue++) {
		WriteBuffer[DATA_OFFSET + Count] = (u8)(UniqueValue + Test);
	}
	memset(ReadBuffer, 0x00, sizeof(ReadBuffer));
	XQspiPs_SetOptions(QspiInstancePtr, XQSPIPS_FORCE_SSELECT_OPTION |
					     XQSPIPS_HOLD_B_DRIVE_OPTION);
	FlashErase(QspiInstancePtr, TEST_ADDRESS, MaxData, WriteBuffer);
	for (Page = 0; Page < PAGE_COUNT; Page++) {
		FlashWrite(QspiInstancePtr,
			(Page * Flash_Config_Table[FCTIndex].PageSize) + TEST_ADDRESS,
			Flash_Config_Table[FCTIndex].PageSize, WRITE_CMD, WriteBuffer);
	}
	FlashRead(QspiInstancePtr, TEST_ADDRESS, MaxData, QUAD_READ_CMD,
				WriteBuffer, ReadBuffer);
	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < MaxData;
	     Count++, UniqueValue++) {
		if (ReadBuffer[Count] != (u8)(UniqueValue + Test)) {
			return XST_FAILURE;
		}
	}
	return XST_SUCCESS;
}
int QspiG128FlashExample ( XQspiPs * QspiInstancePtr , u16 QspiDeviceId ) { int Status ; u8 UniqueValue ; int Count ; int Page ; XQspiPs_Config * QspiConfig ; QspiConfig = XQspiPs_LookupConfig ( QspiDeviceId ) ; if ( NULL == QspiConfig ) { return XST_FAILURE ; } Status = XQspiPs_CfgInitialize ( QspiInstancePtr , QspiConfig , QspiConfig -> BaseAddress ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XQspiPs_SelfTest ( QspiInstancePtr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XQspiPs_SetClkPrescaler ( QspiInstancePtr , XQSPIPS_CLK_PRESCALE_8 ) ; XQspiPs_SetOptions ( QspiInstancePtr , XQSPIPS_FORCE_SSELECT_OPTION | XQSPIPS_MANUAL_START_OPTION | XQSPIPS_HOLD_B_DRIVE_OPTION ) ; if ( QspiConfig -> ConnectionMode == XQSPIPS_CONNECTION_MODE_STACKED ) { XQspiPs_SetLqspiConfigReg ( QspiInstancePtr , DUAL_STACK_CONFIG_WRITE ) ; } if ( QspiConfig -> ConnectionMode == XQSPIPS_CONNECTION_MODE_PARALLEL ) { XQspiPs_SetLqspiConfigReg ( QspiInstancePtr , DUAL_QSPI_CONFIG_WRITE ) ; } XQspiPs_SetSlaveSelect ( QspiInstancePtr ) ; FlashReadID ( QspiInstancePtr , WriteBuffer , ReadBuffer ) ; MaxData = PAGE_COUNT * ( Flash_Config_Table [ FCTIndex ] . PageSize ) ; for ( UniqueValue = UNIQUE_VALUE , Count = 0 ; Count < Flash_Config_Table [ FCTIndex ] . PageSize ; Count ++ , UniqueValue ++ ) { WriteBuffer [ DATA_OFFSET + Count ] = ( u8 ) ( UniqueValue + Test ) ; } memset ( ReadBuffer , 0x00 , sizeof ( ReadBuffer ) ) ; FlashErase ( QspiInstancePtr , TEST_ADDRESS , MaxData , WriteBuffer ) ; for ( Page = 0 ; Page < PAGE_COUNT ; Page ++ ) { FlashWrite ( QspiInstancePtr , ( Page * Flash_Config_Table [ FCTIndex ] . PageSize ) + TEST_ADDRESS , Flash_Config_Table [ FCTIndex ] . PageSize , WRITE_CMD , WriteBuffer ) ; } FlashRead ( QspiInstancePtr , TEST_ADDRESS , MaxData , QUAD_READ_CMD , WriteBuffer , ReadBuffer ) ; for ( UniqueValue = UNIQUE_VALUE , Count = 0 ; Count < MaxData ; Count ++ , UniqueValue ++ ) { if ( ReadBuffer [ Count ] != ( u8 ) ( UniqueValue + Test ) ) { return XST_FAILURE ; } } for ( UniqueValue = UNIQUE_VALUE , Count = 0 ; Count < Flash_Config_Table [ FCTIndex ] . PageSize ; Count ++ , UniqueValue ++ ) { WriteBuffer [ DATA_OFFSET + Count ] = ( u8 ) ( UniqueValue + Test ) ; } memset ( ReadBuffer , 0x00 , sizeof ( ReadBuffer ) ) ; XQspiPs_SetOptions ( QspiInstancePtr , XQSPIPS_FORCE_SSELECT_OPTION | XQSPIPS_HOLD_B_DRIVE_OPTION ) ; FlashErase ( QspiInstancePtr , TEST_ADDRESS , MaxData , WriteBuffer ) ; for ( Page = 0 ; Page < PAGE_COUNT ; Page ++ ) { FlashWrite ( QspiInstancePtr , ( Page * Flash_Config_Table [ FCTIndex ] . PageSize ) + TEST_ADDRESS , Flash_Config_Table [ FCTIndex ] . PageSize , WRITE_CMD , WriteBuffer ) ; } FlashRead ( QspiInstancePtr , TEST_ADDRESS , MaxData , QUAD_READ_CMD , WriteBuffer , ReadBuffer ) ; for ( UniqueValue = UNIQUE_VALUE , Count = 0 ; Count < MaxData ; Count ++ , UniqueValue ++ ) { if ( ReadBuffer [ Count ] != ( u8 ) ( UniqueValue + Test ) ) { return XST_FAILURE ; } } return XST_SUCCESS ; }
The purpose of this function is to illustrate how to use the XQspiPs
device driver in single, parallel and stacked modes using
flash devices greater than 128Mb.
The purpose of this function is to illustrate how to use the XQspiPs device driver in single parallel and stacked modes using flash devices greater than 128Mb .
/*
	 * Initialize the QSPI driver so that it's ready to use
	 */ /*
	 * Perform a self-test to check hardware build
	 */ /*
	 * Set the pre-scaler for QSPI clock
	 */ /*
	 * Set Manual Start and Manual Chip select options and drive the
	 * HOLD_B high.
	 */ /*
		 * Enable two flash memories, Shared bus (NOT separate bus),
		 * L_PAGE selected by default
		 */ /*
		 * Enable two flash memories on separate buses
		 */ /*
	 * Assert the Flash chip select.
	 */ /*
	 * Read flash ID and obtain all flash related information
	 * It is important to call the read id function before
	 * performing proceeding to any operation, including
	 * preparing the WriteBuffer
	 */ /*
	 * Initialize MaxData according to page size.
	 */ /*
	 * Initialize the write buffer for a pattern to write to the Flash
	 * and the read buffer to zero so it can be verified after the read, the
	 * test value that is added to the unique value allows the value to be
	 * changed in a debug environment to guarantee
	 */ /*
	 * Erase the flash.
	 */ /*
	 * Write the data in the write buffer to the serial Flash a page at a
	 * time, starting from TEST_ADDRESS
	 */ /*
	 * I/O Read - for any flash size
	 */ /*
	 * Setup a pointer to the start of the data that was read into the read
	 * buffer and verify the data read is the data that was written
	 */ /*
	 * Initialize the write buffer for a pattern to write to the Flash
	 * and the read buffer to zero so it can be verified after the read, the
	 * test value that is added to the unique value allows the value to be
	 * changed in a debug environment to guarantee
	 */ /*
	 * Set Auto Start and Manual Chip select options and drive the
	 * HOLD_B high.
	 */ /*
	 * Erase the flash.
	 */ /*
	 * Write the data in the write buffer to the serial Flash a page at a
	 * time, starting from TEST_ADDRESS
	 */ /*
	 * I/O Read - for any flash size
	 */ /*
	 * Setup a pointer to the start of the data that was read into the read
	 * buffer and verify the data read is the data that was written
	 */