色哟哟视频在线观看-色哟哟视频在线-色哟哟欧美15最新在线-色哟哟免费在线观看-国产l精品国产亚洲区在线观看-国产l精品国产亚洲区久久

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

ZYNQ開發案例之ZYNQ的UART加載

454398 ? 來源:FPGA技術聯盟 ? 作者:FPGA技術聯盟 ? 2020-12-05 10:15 ? 次閱讀

加載方法

ZYNQ的啟動鏡像是由FSBL程序(bootloader),PL配置文件(硬件比特流文件),應用層軟件三個部分組成,其通過SDK的軟件生成工具把三個部分按規定的格式拼湊成一個.bin文件,最終將這個文件寫入到QSPIFLASH中,整個ZYNQ在配置好啟動方式為FLASH啟動后,便可做到上電自啟動運行下載到FLASH中的用戶程序。

為了實現遠程加載,拋開仿真器,通過UART的方式將固定的.bin文件發送給ZYNQ,然后將文件寫入到FLASH。其分三個步驟完成整個程序的更新:第一,搭建UART的傳輸,通過規定的握手協議,PC機將.bin文件以串口的形式發送給ZYNQ;第二,ZYNQ將收到的文件存儲在指定的DDR3內存當中;第三,ZYNQ將DDR3中的文件數據寫入到FLASH,寫完以后在讀出來與接收的數據作對比,做一個校驗。

串口交互形式

1. 開啟PC機加載程序,等待任務機發送加載信號

2. ZYNQ上電后第一時間給UART發送加載信號0xee,隨后監測UART上的回應信號;

3. PC機監測UART上的加載信號,若是0xee,則發送回應信號0xab,表示PC機做好了進入加載的準備,若不是0xee則不會發送回應信號;

4. ZYNQ收到回應信息0xab以后,進入加載流程,發送獲取長度指令信號0xcc給PC機;

5. PC機監測UART上的獲取長度指令信號,若是0xcc,則發送數據總包數n給PC機(長度=128*n);

6. ZQNY收到數據長度數據后,發送應答信號0xaa給PC機,表示接收到數據長度了;

7. PC機監測UART上的應答信號,接收到應答信號0xaa后,PC機進入發送數據流程,監測ZYNQ的準備好接收數據信號0xdd;

8. ZYNQ接收完數據長度以后,發送準備好接收數據信號0xdd給PC機;

9. PC機監測UART上的準備好接收數據信號0xdd,收到準備好信號0xdd信號以后,發送一包數據(128byte)給ZYNQ,發送完了以后又監測準備好信號0xdd,然后又發送一包數據(128byte)給ZYNQ,往復循環,直到數據包發送完,發送完數據后監測數據接收完信號0xbb;

10. ZYNQ接收完數據后,發送接收完信號0xbb給PC機;

11. PC機監測數據接收完信號0xbb;收到接收完信號0xbb后,數據交互流程完成,ZYNQ監測FLASH寫入操作完成信號;

12. ZYNQ將接收到的數據寫入到FLASH,寫入完了以后發送FLASH寫入操作完成信號0xaf給PC機;

13. PC機監測到接收完成信號0xaf后,提示用戶寫flash操作完成;進入到監測FLASH數據校驗階段;

14. ZYNQ寫完flash后,將對應數據從flash中讀出來做校驗,校驗成功則發送校驗完成信號0xcf給PC機,若校驗失敗則發送失敗信號0xef給PC機;

15. PC機監測到校驗完成信號或者校驗失敗信號后提示用戶校驗完成,整個加載程序完成。

交互流程如圖1所示。

UART與QSPI讀寫函數的設計

Uart初始化流程

1. 通過uart設備ID找到對應的外設信息;

2. 填充uart外設寄存器基地址和一些相關信息;

3. uart外設自檢;

4. 配置uart的fifo的觸發等級;

5. 使能uart外設;

源碼如下

void Init_Uart(void)
{
   XUartPs_Config *UartConifgPtr;
   s32 temp;
   //find device
UartConifgPtr = XUartPs_LookupConfig (XPAR_PS7_UART_1_DEVICE_ID);
   //config xuartps data struct
XUartPs_CfgInitialize(&Uart_1,UartConifgPtr, UartConifgPtr->BaseAddress);
   //self test
   temp = XUartPs_SelfTest(&Uart_1);
   if(temp != XST_SUCCESS)
   {
       return;
   }
// XUartPs_SetDataFormat(&Uart_1,XUARTPS_FORMAT_EVEN_PARITY);
   //set uart fifo level
   XUartPs_SetFifoThreshold(&Uart_1,8);
   //uart enable
   XUartPs_EnableUart(&Uart_1);
}

Uart接收字節函數

判斷RX的FIFO是否為空,如果處于空的狀態,一直等待;如果不為空,讀取RX的FIFO里面的數據,源碼如下:

u8 Uart_RecvByte(void)
{
u8 byte = 0;
while((((XUartPs_ReadReg(InstancePtr->Config.BaseAddress,XUARTPS_SR_OFFSET)) & 0x02) == 0x02));
byte = XUartPs_ReadReg(InstancePtr->Config.BaseAddress,XUARTPS_FIFO_OFFSET);
return byte;
}

Uart發送字節函數

判斷TX的FIFO是否滿,如果處于滿的狀態,一直等待;如果未滿,則把需要發送的數據寫入到TX的FIFO中,源碼如下:

void Uart_SendByte(u8 byte)
{
while((((XUartPs_ReadReg(InstancePtr->Config.BaseAddress,XUARTPS_SR_OFFSET)) & 0x10) == 0x10));
XUartPs_WriteReg(InstancePtr->Config.BaseAddress,XUARTPS_FIFO_OFFSET,byte);
}

初始化QSPI流程

1. 通過qspi設備ID找到對應的外設信息;

2. 填充qspi外設寄存器基地址和一些相關信息;

3. Qspi外設自檢;

4. 配置qspi的工作模式;

5. 配置qspi的工作頻率;

6. 配置qspi的為從設備選擇;

源碼如下:

void Init_Qspi(void)
{
XQspiPs_Config *QspiConfig;
//find device
QspiConfig = XQspiPs_LookupConfig(XPAR_XQSPIPS_0_DEVICE_ID);
//config XQspiPs data struct QspiInstance
XQspiPs_CfgInitialize(&QspiInstance, QspiConfig,QspiConfig->BaseAddress);
//self test
XQspiPs_SelfTest(&QspiInstance);
//set qspi option
XQspiPs_SetOptions(&QspiInstance,XQSPIPS_MANUAL_START_OPTION |XQSPIPS_FORCE_SSELECT_OPTION |XQSPIPS_HOLD_B_DRIVE_OPTION);
//set qspi clk
XQspiPs_SetClkPrescaler(&QspiInstance, XQSPIPS_CLK_PRESCALE_8);
//set slave select of qspi
XQspiPs_SetSlaveSelect(&QspiInstance);
}

Flash擦除函數流程

1. 根據需要寫入數據的大小判斷需要整片擦除還是扇區擦除;

2. 通過qspi接口將寫使能命令寫入到flash;

3. 通過qspi接口將寫命令和需要擦除的flash地址以及數據發送到flash;

4. 等待數據的傳輸完成;

函數源碼:

*/
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

/*

* 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;
}
}

Flash寫入函數流程

1. 通過qspi接口將寫使能發送給flash;

2. 通過qspi接口將寫命令和需要寫入數據的flash地址以及數據發送到flash;

3. 等待數據傳輸完成;

源碼如下:

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;
}
}
}

Flash讀函數流程

1. 判斷讀指令是普通讀指令還是其他的讀指令;

2. 根據判斷使用對應的讀指令,將對應指令和flash寫入到flash,并根據需要讀多少個數據,寫入對應個無效數據到flash,以獲取flash中對應地址的數據;

函數源碼如下:
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);
}

加載程序源碼

/*

* uart_flash.c

*/

#include "xuartps.h"

#include "xil_types.h"

#include "xparameters.h" /* SDK generated parameters */

#include "xqspips.h" /* QSPI device driver */

/////////////////////////////////////////////////////

#define UART_DEVICE_ID XPAR_PS7_UART_1_DEVICE_ID

#define HEAD_LEN 2
XUartPs Uart_1;

XUartPs *InstancePtr = &Uart_1;

int Data_Len = 0;

int Len_Count = 0;

int Data_Count = 0;

u8 Uart_ReadBuffer[128];

u8 Uart_WriteBuffer[128];

u8 ReadCMD[10];

u8 WriteHeadLen[HEAD_LEN] = {0xcc,0x55};

u8 WriteLenOver[HEAD_LEN] = {0xaa,0x55};

u8 WriteHeadData[HEAD_LEN] = {0xdd,0x55};

u8 WriteDataOver[HEAD_LEN] = {0xbb,0x55};

u8 WritePowerOn[HEAD_LEN] = {0xee,0x55};

u8 Uart_RecvByte(void);

void Uart_SendByte(u8 byte);

int Uart_SendBuffer(u8 *buff,int length);

void Init_Uart(void);

int find_Head(u8 *src,u8 *dst,u8 length);

void delay(u32 count);

#define USER_DDR_BASE_ADDR 0x3e000000

u32 DDR_Base_Addr = USER_DDR_BASE_ADDR;

///////////////////////////////////////////////////////

///////////////////////////////////////////////////////

#define QSPI_DEVICE_ID XPAR_XQSPIPS_0_DEVICE_ID

#define WRITE_STATUS_CMD 0x01

#define WRITE_CMD 0x02

#define READ_CMD 0x03

#define WRITE_DISABLE_CMD 0x04

#define READ_STATUS_CMD 0x05

#define WRITE_ENABLE_CMD 0x06

#define FAST_READ_CMD 0x0B

#define DUAL_READ_CMD 0x3B

#define QUAD_READ_CMD 0x6B

#define BULK_ERASE_CMD 0xC7

#define SEC_ERASE_CMD 0xD8

#define READ_ID 0x9F

#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 quadreads */

#define DUMMY_SIZE 1 /* Number of dummy bytes for fast, dual andquad 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

#define SECTOR_SIZE 0x10000

#define NUM_SECTORS 0x100

#define NUM_PAGES 0x10000

#define PAGE_SIZE 256

#define PAGE_COUNT 16

#define TEST_ADDRESS 0x00000000//0x00055000

#define UNIQUE_VALUE 0x05

#define MAX_DATA PAGE_COUNT * PAGE_SIZE

void Init_Qspi(void);

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(void);

XQspiPs QspiInstance;

unsigned int Flash_Address = 0x000000;

u8 ReadBuffer[MAX_DATA + DATA_OFFSET + DUMMY_SIZE];

u8 WriteBuffer[PAGE_SIZE + DATA_OFFSET];

///////////////////////////////////////////////////////

int main(void)

{

int recv_count = 0,i = 0,j = 0,verify_flag = 0;

u8 tt;

Init_Uart();

Init_Qspi();

// recv start signal

delay(10000);

//1 send power on to pc

Uart_SendBuffer(WritePowerOn,1);

delay(10000);

//recv power on ack

ReadCMD[0] = Uart_RecvByte();

delay(10000);

//2,ack right goto load

if(ReadCMD[0] == 0xab)

{

//3,send get data_len to pc

Uart_SendBuffer(WriteHeadLen,1);

delay(1000);

//4,recv length

while(1)

{

if(Len_Count > 1)

{

//5,send len tran over to pc

Uart_SendBuffer(WriteLenOver,1);

//6,data_len option

Data_Len |= ReadCMD[0] << 8;

Data_Len |= ReadCMD[1];

break;

}

ReadCMD[Len_Count] = Uart_RecvByte();

Len_Count++;

}

//7,sent get data to pc

delay(100000);

while(1)

{

//send over data

if(Data_Count >= Data_Len)

{

// send data over to pc

Uart_SendBuffer(WriteDataOver,1);

break;

}

// send get data to pc

Uart_SendBuffer(WriteHeadData,1);

while(1)

{

//get data to buffer

Uart_ReadBuffer[recv_count] = Uart_RecvByte();

if(recv_count >= 127)

{

break;

}

recv_count++;

}

recv_count = 0;

//write ddr3

for(i = 0,DDR_Base_Addr = USER_DDR_BASE_ADDR + Data_Count * 128;i < 128;i++,DDR_Base_Addr++)

{

*(unsigned int *)DDR_Base_Addr = Uart_ReadBuffer[i];

}

Data_Count++;

}

//flash program

Flash_Address = 0x000000;

DDR_Base_Addr = USER_DDR_BASE_ADDR;

//erase

FlashErase(&QspiInstance,0x000000, Data_Len * 128);

//write flash

for(i = 0;i < (Data_Len * 128 / PAGE_SIZE + 1);i++)

{

for(j = 0;j < PAGE_SIZE;j++)

{

WriteBuffer[j + 4] = *(unsigned int *)(DDR_Base_Addr + PAGE_SIZE * i + j);

}

FlashWrite(&QspiInstance, Flash_Address,PAGE_SIZE,WRITE_CMD);

Flash_Address += PAGE_SIZE;

}

Uart_SendByte(0xaf);

//verify Data

Flash_Address = 0x000000;

DDR_Base_Addr = USER_DDR_BASE_ADDR;

for(i = 0;i < (Data_Len * 128 / PAGE_SIZE + 1);i++)

{

FlashRead(&QspiInstance, Flash_Address,PAGE_SIZE,READ_CMD);

Flash_Address += PAGE_SIZE;

for(j = 0;j < PAGE_SIZE;j++)

{

tt = *(unsigned int *)(DDR_Base_Addr + PAGE_SIZE * i + j);

if(ReadBuffer[j + 4] == tt)

{

verify_flag = 0;

}

else

{

verify_flag = 1;

}

}

}

if(verify_flag == 1)

{

Uart_SendByte(0xcf);

}

else

{

Uart_SendByte(0xef);

}

while(1)

{

}

}

else

{

print("author:660 dz!!/r/n");

print("timer:2019/3/13!!/r/n");

while(1)

{

}

}

return 0;

}

void Init_Uart(void)

{

XUartPs_Config *UartConifgPtr;

s32 temp;

//find device

UartConifgPtr = XUartPs_LookupConfig(XPAR_PS7_UART_1_DEVICE_ID);

//config xuartps data struct

XUartPs_CfgInitialize(&Uart_1,UartConifgPtr, UartConifgPtr->BaseAddress);

//self test

temp = XUartPs_SelfTest(&Uart_1);

if(temp != XST_SUCCESS)

{

return;

}

// XUartPs_SetDataFormat(&Uart_1,XUARTPS_FORMAT_EVEN_PARITY);

//set uart fifo level

XUartPs_SetFifoThreshold(&Uart_1,8);

//uart enable

XUartPs_EnableUart(&Uart_1);

}

u8 Uart_RecvByte(void)

{

u8 byte = 0;

while((((XUartPs_ReadReg(InstancePtr->Config.BaseAddress,XUARTPS_SR_OFFSET)) & 0x02) == 0x02));

byte = XUartPs_ReadReg(InstancePtr->Config.BaseAddress,XUARTPS_FIFO_OFFSET);

return byte;

}

void Uart_SendByte(u8 byte)

{

while((((XUartPs_ReadReg(InstancePtr->Config.BaseAddress,XUARTPS_SR_OFFSET)) & 0x10) == 0x10));

XUartPs_WriteReg(InstancePtr->Config.BaseAddress,XUARTPS_FIFO_OFFSET,byte);

}

int Uart_SendBuffer(u8 *buff,int length)

{

int i = 0;

for(i = 0;i < length;i++)

{

Uart_SendByte(buff[i]);

}

return i;

}

int find_Head(u8 *src,u8 *dst,u8 length)

{

int i = 0,ret = 0;

for(i = 0;i < length - 1;i++)

{

if((src[i] == dst[0]) && (src[i + 1] == dst[1]))

{

ret = 1;

}

}

return ret;

}

void delay(u32 count)

{

unsigned int i = 0;

for(i = 0;i < count;i++)

;

}

void Init_Qspi(void)

{

XQspiPs_Config *QspiConfig;

//find device

QspiConfig = XQspiPs_LookupConfig(XPAR_XQSPIPS_0_DEVICE_ID);

//config XQspiPs data struct QspiInstance

XQspiPs_CfgInitialize(&QspiInstance, QspiConfig,QspiConfig->BaseAddress);

//self test

XQspiPs_SelfTest(&QspiInstance);

//set qspi option

XQspiPs_SetOptions(&QspiInstance,XQSPIPS_MANUAL_START_OPTION |XQSPIPS_FORCE_SSELECT_OPTION |XQSPIPS_HOLD_B_DRIVE_OPTION);

//set qspi clk

XQspiPs_SetClkPrescaler(&QspiInstance, XQSPIPS_CLK_PRESCALE_8);

//set slave select of qspi

XQspiPs_SetSlaveSelect(&QspiInstance);

}

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 / 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;

}

}

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;

}

}

}

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);

}

int FlashReadID(void)

{

int Status;

/*

* Read ID in Auto mode.

*/

WriteBuffer[COMMAND_OFFSET] = READ_ID;

WriteBuffer[ADDRESS_1_OFFSET] = 0x23; /* 3 dummy bytes */

WriteBuffer[ADDRESS_2_OFFSET] = 0x08;

WriteBuffer[ADDRESS_3_OFFSET] = 0x09;

Status = XQspiPs_PolledTransfer(&QspiInstance, WriteBuffer, ReadBuffer,RD_ID_SIZE);

if (Status != XST_SUCCESS) {

return XST_FAILURE;

}

return XST_SUCCESS;

}

編輯:hfy

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • Zynq
    +關注

    關注

    10

    文章

    609

    瀏覽量

    47175
  • SDK
    SDK
    +關注

    關注

    3

    文章

    1035

    瀏覽量

    45905
收藏 人收藏

    評論

    相關推薦

    ZYNQ進階:PL端UART 發送設計案例

    ZYNQ進階之路2 中我們講解了PL端PWM呼吸燈的設計,本節我們講解PL端實現串口UART的發送設計; 首先新建一個串口發送的工程,工程建立在ZYNQ進階之路1中已經講述,這里不再累述; 下面
    的頭像 發表于 11-25 17:26 ?3567次閱讀
    <b class='flag-5'>ZYNQ</b>進階:PL端<b class='flag-5'>UART</b> 發送設計案例

    ZYNQ開發案例:GPIO的結構體系及使用案例

    GPIO的結構體系 zynq的GPIO,分為兩種,MIO(multiuse I/O)和EMIO(extendable multiuse I/O)。 ZYNQ的GPIO由4個BANK組成,其體系結構
    的頭像 發表于 12-09 11:41 ?3700次閱讀
    <b class='flag-5'>ZYNQ</b><b class='flag-5'>開發案</b>例:GPIO的結構體系及使用案例

    PYNQ案例(一):ZYNQ的PL與PS開發

    上一期的學習中,我們系統性地介紹了PYNQ與ZYNQ地區別與聯系。PYNQ = Python + ZYNQ,即將ZYNQ部分功能的Python化,直接調用Python庫和FPGA硬件庫進行功能的
    的頭像 發表于 12-25 14:11 ?8153次閱讀

    PYNQ案例(二):ZYNQ與PYNQ的區別與聯系

    方法,軟件編程模式與全功能的標準ARM處理SoC毫無二致。 與相關和不同的是,PYNQ = Python + ZYNQ,即將ZYNQ部分功能的Python化,直接調用Python庫和FPGA硬件庫進行功能
    的頭像 發表于 12-25 14:15 ?5948次閱讀

    Zynq Book來襲!!!!!!

    ) 的英國學者所著,為您詳細介紹 Xilinx? Zynq?-7000 All Programmable SoC。本書包含了 Zynq-7000 SoC 開發的方方面面,從硬件到軟件,從理論到實現
    發表于 09-04 11:37

    玩轉Zynq連載28——[ex50] 第一個Zynq系統工程“Hello Zynq

    鏈接:https://pan.baidu.com/s/1XTQtP5LZAedkCwQtllAEyw提取碼:ld9c 1概述如圖所示,Zynq系統的PS部分有豐富的外設接口,常見的USB、UART
    發表于 09-30 12:57

    Zynq在非JTAG模式下的啟動配置流程

    的 ARM 開發過程類似,區別就在于它是PS + PL 的架構,所以在啟動過程中,額外需要加載二進制 bit 流文件。Xilinx 將 Zynq 的啟動劃分為3個階段,從結構上看也是科學合理的。  總結
    發表于 01-08 16:33

    ZYNQ嵌入式系統的開發流程

    部分的始發點。通過本次實驗我們將了解 ZYNQ 嵌入式系統的開發流程,熟悉 ZYNQ 嵌入式最小系統的搭建。本章包括以下幾個部分:1.1 簡介1.2 實驗任務1.3 硬件設計1.4 軟件...
    發表于 10-27 07:50

    ZYNQ學習筆記_ZYNQ簡介和Hello World

    ZYNQ學習筆記_ZYNQ簡介和Hello WorldZYNQ介紹PS和PL的連接ZYNQ開發工具鏈在PS端編寫Hello World程序ZYNQ
    發表于 12-22 19:11 ?10次下載
    <b class='flag-5'>ZYNQ</b>學習筆記_<b class='flag-5'>ZYNQ</b>簡介和Hello World

    ZYNQ的啟動流程

    ZYNQ7000 SOC 芯片可以從 FLASH 啟動,也可以從 SD 卡里啟動, 本節介紹程序 FLASH 啟動的方法。Zynq7000 SOC 芯片上電后,最先運行的是ARM端系統(PS
    的頭像 發表于 05-07 09:41 ?6496次閱讀

    解析Zynq加載方式

    因為在S6或者其他7系列的FPGA中,是有一套非常成熟的FPGA加載機制(Xilinx有很詳細的指導手冊),但是來到Zynq時代,這個方式變了。為什么呢?因為現在zynq上有ARM了,所有的
    的頭像 發表于 05-09 10:53 ?3438次閱讀

    ZYNQ 的啟動流程介紹

    普通的 FPGA 一般是可以從 flash 啟動,或者被動加載,但是ZYNQ不行,ZYNQ必須PS端參與
    的頭像 發表于 07-22 10:10 ?7417次閱讀

    ZYNQ7020的PS端的基本開發流程

    這篇文章記錄ZYNQ7020的PS端的基本開發流程,關于PL端的開發流程,參考之前文章,這里放個超鏈接。
    的頭像 發表于 07-24 18:12 ?7837次閱讀

    FPGAs,ZynqZynq MPSoC器件的特點

    Zynq MPSoC是Zynq-7000 SoC(之后簡稱Zynq)的進化版本。Zynq是賽靈思發布的集成PL(FPGA)和PS設計的最早的一代產品。如圖2.1所示,在相對較高層次對比
    的頭像 發表于 08-15 09:16 ?2578次閱讀

    ZYNQ常用外設設計 (上)

    Step3: 按照“Vivado中進行ZYNQ硬件部分設計”中介紹的,直到在SDK中編寫C代碼步驟。需要使用UART進行通行,分為通過UART向外發送數據和通過UART接收數據。
    的頭像 發表于 09-23 09:25 ?1183次閱讀
    <b class='flag-5'>ZYNQ</b>常用外設設計 (上)
    主站蜘蛛池模板: 国产啪视频在线播放观看| 欧美成a人片免费看久久| 99视频精品全部免费免费观| 亚洲精品电影天堂网| 色哟哟网站入口在线观看视频| 老湿司午夜爽爽影院榴莲视频 | 99久久蜜臀AV免费看蛮| 夜色爽爽爽久久精品日韩| 思思久99久女女精品| 欧美最猛12teevideos欧美| 老师你狠狂| 菊地凛子av| 毛片免费在线播放| 榴莲黄版无限刷| 久久综合亚洲色hezyo| 久久无码人妻AV精品一区| 久久视频这只精品99re6| 久久久这里有精品999| 浪小辉军警服务员VIDEOS| 美女被男人撕衣舔胸| 麻豆COMCN| 欧美色妞AV重囗味视频| 秋霞在线看片无码免费| 全部老头和老太XXXXX| 日本漂亮妈妈7观整有限中| 日韩精品免费在线观看| 天堂网久久| 伊人成综合网伊人222| 18video性欧美19sex高清| china男士同性视频tv| 国产国拍亚洲精品av麻豆| 含羞草在线免费观看| 精品欧美18videosex欧美| 麻豆精品无码久久久久久久久| 毛片大全网站| 偷拍 自怕 亚洲 在线| 亚洲欧洲日韩天堂无吗| 91在线青春娱乐精品分类| 攻把受做哭边走边肉楼梯PLAY| 国产午夜在线视频| 欧美成人中文字幕在线视频|