9 - QSPI Flash读写测试实验

1 实验任务

本实验任务是使用PS侧的QSPI Flash控制器,先后对QSPI Flash 进行写、 读操作。通过对比读出的数据是否等于写入的数据, 从而验证读写操作是否正确。

2 系统框图

在这里插入图片描述

3 硬件设计

3.1 Block Design

  1. 添加ZYNQ7 Processing System IP核
    • (1)在Peripheral I/O页面
      • 1)勾选Quad SPI Flash.Single SS 4bit IO
      • 2)勾选UART
      • 3)正确选择Bank 0和Bank 1的电压
    • (2)在DDR Configuration页面
      • 1)DDR Controller Configuration下,合理配置Memory Type、Memory Part和Bus Width等参数

在这里插入图片描述

3.2 注意事项

无。

4 软件设计

4.1 注意事项

  1. 基础知识
    • 1)开发板使用的是Winbond公司W25Q256JVEQ型Flash芯片
    • 2)软件工程参考的是Xilinx提供的Example Design(xqspips_flash_polled_example),需要特别注意的是:
      • 例程定义的芯片参数和开发板使用的芯片参数不一致,例如指令编码、Page和Sector大小、Page和Sector数量等,需要一一对照并修改
  2. 最初在进行程序固化实验时
    • 1)从SD卡可以启动
    • 2)从QSPI Flash无法启动,显示回读数据错误,校验失败;此时,我一脸懵逼,因为刚拿到开发板的时候,也进行过程序固化实验,清晰地记得当时从SD卡和QSPI Flash启动都是可以的,怎么现在从QSPI Flash启动就不行了呢?在没有手段和头绪的情况下,只能怀疑Flash芯片是不是坏了
  3. 修改例程使程序能够遍历Flash芯片的16MB空间(W25Q256JV芯片大小为32MB,但是QSPI Flash控制器使用3字节地址,只能访问16MB的空间)
    • 1)测试发现0MB ➡ 8MB数据读写比较有错误,8MB ➡ 16MB数据读写比较正常
    • 2)研究芯片手册发现,芯片有写保护设置,通过状态寄存器的TB位、BP3~BP0位、CMP位和WPS位等可以控制芯片的哪些块只能读取不能擦除和写入,即写保护
    • 3)编写FlashReadStatus函数,读取Flash的状态寄存器,发现TB=1,BP3~BP0=1000b,CMP=0,WPS=0,对应芯片的低四分之一区域被写保护了
    • 4)编写FlashWriteStatus函数,将状态寄存器的值恢复到出厂设置状态
  4. 在恢复状态寄存器的出场设置状态时发现,Status Register-1的QE位写0写不进去,一直为1,最后在芯片手册的9.8 Ordering Information小节找到了答案;如下图所示,对于W25Q256JV系列芯片,型号最后一位是Q和N的,QE位出厂设置为1且固定(即不可修改)
    在这里插入图片描述

4.2 速率测试

  1. 芯片手册提供的时序特性,如下图所示:
    2.
  2. 实测擦除、写入和读取一个sector所需时间,如下所示:
********************************************
[Time Consumed] - Erase Flash :
		Time (ms):    41.009
[Time Consumed] - Write Flash :
		Time (ms):    6.704
[Time Consumed] - Read Flash :
		Time (ms):    0.179
[Time Consumed] - Compare Data :
		Time (ms):    0.092
********************************************
  1. 实测结果分析
    • 1)实际擦除时间41.009ms<典型值50ms,关于擦除时间在此特别说明:
      • FlashErase函数使用for循环来执行sector擦除操作,即 for (Sector = 0; Sector < ((ByteCount / SECTOR_SIZE) + 1); Sector++) ;该语句有个问题,当ByteCount = SECTOR_SIZE时,实际需要擦除一个sector,结果擦除两个sector,导致统计的擦除时间远大于50ms
      • 修改for循环语句:for (Sector = 0; Sector < (((ByteCount - 1) / SECTOR_SIZE) + 1); Sector++)
    • 2)实际写入时间6.704ms/16=0.419ms,非常接近典型值0.4ms
    • 3)实际读取时间0.179ms,读取速度≈22.3MB/s,接近理论极限速度25MB/s
      • Vivado中,对PS配置时,Clock Configuration➡IO Peripheral CLocks➡QSPI = 200MHz
      • Vitis中,应用工程对FLash进行配置时,使用XQspiPs_SetClkPrescaler函数对QSPI时钟进行四分频,即50MHz
      • Vitis中,应用工程使用FlashQuadEnable函数使能QE(Quad Enable)位,即使能Flash的Quad SPI工作模式
      • Vitis中,应用工程使用FlashRead函数读取Flash时,使用QUAD_READ_CMD命令
      • 综上,理论极限速度为25MB/s
    • 4)为什么读速度远远大于写速度?
      • 写操作需先发送写使能(WREN)、页编程指令(PP),然后等待编程完成(检查WIP位)
      • 写操作每次只能写入一个Page
      • 写操作需要改变存储单元状态,如向浮栅注入电子,将1变为0
      • 读操作只需发送FAST_READ读指令
      • 读操作每次读取的Page数不限
      • 读操作只需感应存储单元状态
      • 综上,Flash读速度远远大于写速度
    • 5)最后,需要注意的是,在统计读写Flash所耗费的时间时,不要添加打印信息,否则统计误差会很大;因为串口速率很慢(只有115200),随便打印一条信息都会耗时几毫秒,远远大于读取一个sector的时间。

4.3 工程源码

/***************************** Include Files *********************************/

#include "stdio.h"
#include "sleep.h"
#include "xparameters.h"
#include "xqspips.h"
#include "xtime_l.h"

/************************** Constant Definitions *****************************/

#define QSPI_DEVICE_ID		XPAR_XQSPIPS_0_DEVICE_ID

/* The following constants define the commands which may be sent to the FLASH device. */
#define WRITE_STATUS_CMD	0x01 // Write Status Register-1
#define WRITE_CMD			0x02 // Page Program
#define READ_CMD			0x03 // Read Data
#define WRITE_DISABLE_CMD	0x04 // Write Disable
#define READ_STATUS_CMD		0x05 // Read Status Register-1
#define WRITE_ENABLE_CMD	0x06 // Write Enable
#define FAST_READ_CMD		0x0B // Fast Read
#define DUAL_READ_CMD		0x3B // Fast Read Dual Output
#define QUAD_READ_CMD		0x6B // Fast Read Quad Output
#define BULK_ERASE_CMD		0xC7 // Chip Erase
#define	SEC_ERASE_CMD		0x20 // Sector Erase
#define READ_ID				0x9F // JEDEC ID

#define WRITE_STATUS2_CMD	0x31 // Write Status Register-2
#define WRITE_STATUS3_CMD	0x11 // Write Status Register-3

#define READ_STATUS2_CMD	0x35 // Read Status Register-2
#define READ_STATUS3_CMD	0x15 // Read Status Register-3

/* The following constants define the offsets within a FlashBuffer data type for each kind of data. */
#define COMMAND_OFFSET		0 // FLASH instruction
#define ADDRESS_1_OFFSET	1 // MSB byte of address to read or write
#define ADDRESS_2_OFFSET	2 // Middle byte of address to read or write
#define ADDRESS_3_OFFSET	3 // LSB byte of address to read or write
#define DATA_OFFSET			4 // Start of Data for Read/Write
#define DUMMY_OFFSET		4 // Dummy byte offset for fast, dual and quad reads
#define DUMMY_SIZE			1 // Number of dummy bytes for fast, dual and quad reads
#define RD_ID_SIZE			4 // Read ID command + 3 bytes ID response
#define BULK_ERASE_SIZE		1 // Bulk Erase command size
#define SEC_ERASE_SIZE		4 // Sector Erase command + Sector address

#define OVERHEAD_SIZE		4

/* The following constants specify the page size, sector size, and number of pages and sectors for the FLASH. */
#define SECTOR_SIZE			0x1000  // 4096B
#define NUM_SECTORS			0x80  //
#define NUM_PAGES			0x10000 // Not Used
#define PAGE_SIZE			256     // 256B

/* Number of flash pages to be written.*/
#define PAGE_COUNT			16 //

/* Flash address to which data is ot be written.*/
#define TEST_ADDRESS		0x00000000
#define UNIQUE_VALUE		0x00

#define DEBUG				1
/**************************** Type Definitions *******************************/

/***************** Macros (Inline Functions) Definitions *********************/

/************************** Function Prototypes ******************************/

void FlashErase(XQspiPs *QspiPtr, u32 Address, u32 ByteCount);
void FlashWrite(XQspiPs *QspiPtr, u32 Address, u32 ByteCount, u8 Command);
void FlashRead(XQspiPs *QspiPtr, u32 Address, u32 ByteCount, u8 Command);
int  FlashReadID(XQspiPs *QspiPtr);
void FlashReadStatus(XQspiPs *QspiPtr);
void FlashWriteStatus(XQspiPs *QspiPtr);
void FlashQuadEnable(XQspiPs *QspiPtr);
int  QspiFlashPolledExample(XQspiPs *QspiInstancePtr, u16 QspiDeviceId);
void PrintTimeStats(XTime StartTime, XTime EndTime, const char* Label);

/************************** Variable Definitions *****************************/

XQspiPs QspiInstance;

u8 ReadBuffer[SECTOR_SIZE + DATA_OFFSET + DUMMY_SIZE];
u8 WriteBuffer[PAGE_SIZE + DATA_OFFSET];

u32 BadSectorCount = 0;

XTime StartTime;
XTime EndTime;

/*****************************************************************************/

int main(void)
{
	//
	int Status;

	//
	printf("QSPI FLASH Write and Read Test.\n");

	// Run the Qspi Interrupt example
	Status = QspiFlashPolledExample(&QspiInstance, QSPI_DEVICE_ID);
	if (Status != XST_SUCCESS) {
		printf("Error : qspi flash polled example test failed.\n");
		return XST_FAILURE;
	}

	//
	printf("BadSectorCount = %lu\n", BadSectorCount);

	//
	return XST_SUCCESS;
}

/*****************************************************************************/

int QspiFlashPolledExample(XQspiPs *QspiInstancePtr, u16 QspiDeviceId)
{
	//
	int Status;
	u8 *BufferPtr;
	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 (QspiConfig == NULL) {
		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 Manual Start and Manual Chip select options and drive HOLD_B pin high
	XQspiPs_SetOptions(QspiInstancePtr, XQSPIPS_MANUAL_START_OPTION | XQSPIPS_FORCE_SSELECT_OPTION | XQSPIPS_HOLD_B_DRIVE_OPTION);

	// Set the prescaler for QSPI clock
	XQspiPs_SetClkPrescaler(QspiInstancePtr, XQSPIPS_CLK_PRESCALE_4);

	// Assert the FLASH chip select
	XQspiPs_SetSlaveSelect(QspiInstancePtr);

	// Write the flash status
	FlashWriteStatus(QspiInstancePtr);

	// Read the flash status
	FlashReadStatus(QspiInstancePtr);

	// Read the flash id
	FlashReadID(QspiInstancePtr);

	// Enabe Quad SPI Operation
	FlashQuadEnable(QspiInstancePtr);

	// Initialize the write buffer
	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < PAGE_SIZE; Count++, UniqueValue++) {
		WriteBuffer[DATA_OFFSET + Count] = (u8)UniqueValue;
	}

	//
	printf("********************************************\n");

	// Traverse the entire flash
	for (u32 SectorCount = 0; SectorCount < NUM_SECTORS; SectorCount++) {
		// Erase the flash
		XTime_GetTime(&StartTime);
		FlashErase(QspiInstancePtr, TEST_ADDRESS + (SectorCount * SECTOR_SIZE), SECTOR_SIZE);
//		printf("Erase flash sector %lu done.\n", SectorCount);
		XTime_GetTime(&EndTime);
		PrintTimeStats(StartTime, EndTime, "Erase Flash");

		// Write the flash
		XTime_GetTime(&StartTime);
		for (Page = 0; Page < PAGE_COUNT; Page++) {
			FlashWrite(QspiInstancePtr, (Page * PAGE_SIZE) + TEST_ADDRESS + (SectorCount * SECTOR_SIZE), PAGE_SIZE, WRITE_CMD);
		}
//		printf("Write flash sector %lu done.\n", SectorCount);
		XTime_GetTime(&EndTime);
		PrintTimeStats(StartTime, EndTime, "Write Flash");

		// Read the flash
		XTime_GetTime(&StartTime);
		memset(ReadBuffer, 0x00, sizeof(ReadBuffer));
		FlashRead(QspiInstancePtr, TEST_ADDRESS + (SectorCount * SECTOR_SIZE), SECTOR_SIZE, QUAD_READ_CMD);
//		printf("Read flash sector %lu done.\n", SectorCount);
		XTime_GetTime(&EndTime);
		PrintTimeStats(StartTime, EndTime, "Read Flash");

		// Compare the data
		XTime_GetTime(&StartTime);
		BufferPtr = &ReadBuffer[DATA_OFFSET + DUMMY_SIZE];
		for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < SECTOR_SIZE; Count++, UniqueValue++) {
			if (BufferPtr[Count] != (u8)UniqueValue) {
				BadSectorCount++;
				printf("Sector %lu is bad, BufferPtr[%d] = %hhu\n", SectorCount, Count, BufferPtr[Count]);
				break;
			}
		}
//		printf("Compare flash sector %lu done.\n", SectorCount);
		XTime_GetTime(&EndTime);
		PrintTimeStats(StartTime, EndTime, "Compare Data");

		//
		printf("********************************************\n");
	}

	//
	return XST_SUCCESS;
}

/*****************************************************************************/

void FlashWrite(XQspiPs *QspiPtr, u32 Address, u32 ByteCount, u8 Command)
{
	//
	u8 WriteEnableCmd = { WRITE_ENABLE_CMD };
	u8 ReadStatusCmd[] = { READ_STATUS_CMD, 0 };  /* must send 2 bytes */
	u8 FlashStatus[2];

	/*
	 * Send the write enable command to the FLASH so that it can be written to,
	 * this needs to be sent as a seperate transfer before the write.
	 */
	XQspiPs_PolledTransfer(QspiPtr, &WriteEnableCmd, NULL, sizeof(WriteEnableCmd));

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

	/*
	 * Send the write command, address, and data to the FLASH to be written,
	 * no receive buffer is specified since there is nothing to receive.
	 */
	XQspiPs_PolledTransfer(QspiPtr, WriteBuffer, NULL, ByteCount + OVERHEAD_SIZE);

	/*
	 * Wait for the write command to the FLASH to be completed,
	 * it takes some time for the data to be written.
	 */
	while (1) {
		/*
		 * Poll the status register of the FLASH 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.
		 */
		if ((FlashStatus[1] & 0x01) == 0) {
			break;
		}
	}

	//
	return;
}
/*****************************************************************************/

void FlashRead(XQspiPs *QspiPtr, u32 Address, u32 ByteCount, u8 Command)
{
	/*
	 * Setup the write command with the specified address and data for the FLASH.
	 */
	WriteBuffer[COMMAND_OFFSET]   = Command;
	WriteBuffer[ADDRESS_1_OFFSET] = (u8)((Address & 0xFF0000) >> 16);
	WriteBuffer[ADDRESS_2_OFFSET] = (u8)((Address & 0xFF00) >> 8);
	WriteBuffer[ADDRESS_3_OFFSET] = (u8)(Address & 0xFF);

	if ((Command == FAST_READ_CMD) || (Command == DUAL_READ_CMD) || (Command == QUAD_READ_CMD)) {
		ByteCount += DUMMY_SIZE;
	}
	/*
	 * Send the read command to the FLASH to read the specified number of bytes from the FLASH,
	 * send the read command and address and receive the specified number of bytes of data in the data buffer.
	 */
	XQspiPs_PolledTransfer(QspiPtr, WriteBuffer, ReadBuffer, ByteCount + OVERHEAD_SIZE);

	//
	return;
}

/*****************************************************************************/

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];
	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 seperate 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.
			 */
			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 - 1) / 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 seperate transfer before the write.
		 */
		XQspiPs_PolledTransfer(QspiPtr, &WriteEnableCmd, NULL, sizeof(WriteEnableCmd));

		/*
		 * Setup the write command with the specified address and data for the FLASH.
		 */
		WriteBuffer[COMMAND_OFFSET]   = SEC_ERASE_CMD;
		WriteBuffer[ADDRESS_1_OFFSET] = (u8)(Address >> 16);
		WriteBuffer[ADDRESS_2_OFFSET] = (u8)(Address >> 8);
		WriteBuffer[ADDRESS_3_OFFSET] = (u8)(Address & 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 erse 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.
			 */
			if ((FlashStatus[1] & 0x01) == 0) {
				break;
			}
		}

		Address += SECTOR_SIZE;
	}

	//
	return;
}

/*****************************************************************************/

void FlashWriteStatus(XQspiPs *QspiPtr)
{
	//
	u8 WriteEnableCmd    = {WRITE_ENABLE_CMD};
	u8 WriteStatus1Cmd[] = {WRITE_STATUS_CMD, 0x0};
	u8 WriteStatus2Cmd[] = {WRITE_STATUS2_CMD, 0x00};
	u8 WriteStatus3Cmd[] = {WRITE_STATUS3_CMD, 0x60};

	// Write Status Register - 1
	XQspiPs_PolledTransfer(QspiPtr, &WriteEnableCmd, NULL, sizeof(WriteEnableCmd));
	XQspiPs_PolledTransfer(QspiPtr, WriteStatus1Cmd, NULL, sizeof(WriteStatus1Cmd));
	usleep(10000);

	// Write Status Register - 2
	XQspiPs_PolledTransfer(QspiPtr, &WriteEnableCmd, NULL, sizeof(WriteEnableCmd));
	XQspiPs_PolledTransfer(QspiPtr, WriteStatus2Cmd, NULL, sizeof(WriteStatus2Cmd));
	usleep(10000);

	// Write Status Register - 3
	XQspiPs_PolledTransfer(QspiPtr, &WriteEnableCmd, NULL, sizeof(WriteEnableCmd));
	XQspiPs_PolledTransfer(QspiPtr, WriteStatus3Cmd, NULL, sizeof(WriteStatus3Cmd));
	usleep(10000);

	//
	return;
}

/*****************************************************************************/

void FlashReadStatus(XQspiPs *QspiPtr)
{
	//
	u8 ReadStatus1Cmd[] = {READ_STATUS_CMD, 0};
	u8 ReadStatus2Cmd[] = {READ_STATUS2_CMD, 0};
	u8 ReadStatus3Cmd[] = {READ_STATUS3_CMD, 0};
	u8 FlashStatus[2];

	// Read Status Register - 1
	XQspiPs_PolledTransfer(QspiPtr, ReadStatus1Cmd, FlashStatus, sizeof(ReadStatus1Cmd));
	printf("Flash Status Register 1 = 0x%02x\n", FlashStatus[1]);
	usleep(10000);

	// Read Status Register - 2
	XQspiPs_PolledTransfer(QspiPtr, ReadStatus2Cmd, FlashStatus, sizeof(ReadStatus2Cmd));
	printf("Flash Status Register 2 = 0x%02x\n", FlashStatus[1]);
	usleep(10000);

	// Read Status Register - 3
	XQspiPs_PolledTransfer(QspiPtr, ReadStatus3Cmd, FlashStatus, sizeof(ReadStatus3Cmd));
	printf("Flash Status Register 3 = 0x%02x\n", FlashStatus[1]);
	usleep(10000);

	//
	return;
}

/*****************************************************************************/

int FlashReadID(XQspiPs *QspiPtr)
{
	//
	int Status;
	u8 ReadIdCmd[] = {READ_ID, 0x23, 0x08, 0x09}; /* 3 dummy bytes */
	u8 FlashId[4];

	//
	Status = XQspiPs_PolledTransfer(QspiPtr, ReadIdCmd, FlashId, RD_ID_SIZE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	//
	printf("FlashID=0x%x 0x%x 0x%x\n", FlashId[1], FlashId[2], FlashId[3]);

	//
	return XST_SUCCESS;
}

/*****************************************************************************/

void FlashQuadEnable(XQspiPs *QspiPtr)
{
	//
	u8 WriteEnableCmd  = {WRITE_ENABLE_CMD};
	u8 ReadStatusCmd[] = {READ_STATUS2_CMD, 0};
	u8 QuadEnableCmd[] = {WRITE_STATUS2_CMD, 0};
	u8 FlashStatus[2];

	//
	if (ReadBuffer[1] == 0xEF) { // Winbond Serial Flash
		//
		XQspiPs_PolledTransfer(QspiPtr, ReadStatusCmd, FlashStatus, sizeof(ReadStatusCmd));
		QuadEnableCmd[1] = FlashStatus[1] | (1 << 1);
		//
		XQspiPs_PolledTransfer(QspiPtr, &WriteEnableCmd, NULL, sizeof(WriteEnableCmd));
		XQspiPs_PolledTransfer(QspiPtr, QuadEnableCmd, NULL, sizeof(QuadEnableCmd));
	}

	//
	return;
}

/*****************************************************************************/

void PrintTimeStats(XTime StartTime, XTime EndTime, const char* Label)
{
    // 计算耗时(单位:时钟周期)
    XTime ElapsedCycles = EndTime - StartTime;

    // 转换为秒(64位全局定时器时钟频率是CPU时钟频率的1/2)
    float ElapsedSeconds = (float)ElapsedCycles * 2 / (float)XPAR_CPU_CORTEXA9_0_CPU_CLK_FREQ_HZ;

    // 打印结果
    printf("[Time Consumed] - %s :\n", Label);
//    printf("\t\tClock Cycles: %llu\n", ElapsedCycles);
//    printf("\t\tTime (s):     %.6f\n", ElapsedSeconds);
    printf("\t\tTime (ms):    %.3f\n", ElapsedSeconds * 1000);
}

/*****************************************************************************/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值