本文主要演示zynq 7000下对Qspi 的读写操作,以及读取8字节唯一ID, 可以用于简单加密。本文分为四部分:硬件设计,软件设计,测试验证,总结
本文的前提条件是读者会helloworld 实验,也就是会zynq 7000的SDK开发过程,如果不会,那先去看我的zynq 7000下的helloworld 实验,或者开发板提供的helloworld 实验教程。我实验平台是黑金的核心板AC7010, 其板上的QSPI芯片是W25Q256FV
1 硬件设计
硬件设计基本和helloworld 一样,不同的是要选择QSPI, 否则怎么做实验呢。还有工程名字取为qspi。在zynq配置的peripheral I/O Pins 里选择Quad SPI Flash, 如图:
在zynq配置的MIO configuration 里选择Quad SPI Flash的每个脚为 fast, 如图:
初次以外,都和hello world 实验的硬件设计一样。
2:软件设计
在SDK里 新建工程,取名为qspi_t , 在Next 里可以选择hello world 或者empty project。下载我提供的xqspips_flash_polled_example.c 文件, 放入.src ,就是hellowrld.c 的地方。删除helloworld.c 。为什么取这样一个名字呢?这是Xilinx提供的样例程序,你可以在你的xilinx 目录下搜索到这个文件。我提供的程序是在其上修改得到的。
FlashWrite, FlashRead, FlashErase, FlashReadID 都是样例程序里包含的。我做的工作只是修改了main函数,还有仿照FlashReadID, 编写了一个FlashReadUID函数。
FlashWrite, 写Flash, 其参数是QSPI驱动指针, FLash写的起始地址, 写入字节数, 写命令
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;
WriteBuff