AN889の日記

組込みエンジニアのブログ

【ZynqMP】xqspipsu_generic_flash_interrupt_example.c の修正

XILINX社のSDKであるVitisにはいろいろなサンプルプログラムが同梱されています。 japan.xilinx.com

このうちのQSPIフラッシュテストプログラムにいけてないところが少しあるので修正しました。 github.com

  • FlashEnableQuadMode()
    case SPANSION_ID_BYTE0で、WRITE_ENABLE_CMD 発行前にチップセレクトも兼ねる GetRealAddr() が実行されないので、フラッシュがデュアルパラレルだと上位デバイスへ WRITE_ENABLE_CMD コマンドが発行されません。
    なので、WRITE_ENABLE_CMD 発行前に GetRealAddr() を実行するようにしました。

  • QspiPsuInterruptFlashExample()
    コマンドのデバッグ文が元の位置だと、その後に選択された4バイトモードコマンドが表示されないので、4バイトモードコマンド選択後に移動しました。

--- xqspipsu_generic_flash_interrupt_example.c.orig  2023-10-10 10:28:10.692908400 +0900
+++ xqspipsu_generic_flash_interrupt_example.c    2023-10-17 15:25:32.296358072 +0900
@@ -371,10 +371,6 @@
        FSRFlag = 0;
    }
 
-  xil_printf("ReadCmd: 0x%x, WriteCmd: 0x%x,"
-         "StatusCmd: 0x%x, FSRFlag: %d\n\r",
-         ReadCmd, WriteCmd, StatusCmd, FSRFlag);
-
    if (Flash_Config_Table[FCTIndex].FlashDeviceSize > SIXTEENMB) {
        Status = FlashEnterExit4BAddMode(QspiPsuInstancePtr, ENTER_4B);
        if (Status != XST_SUCCESS) {
@@ -393,6 +389,10 @@
        }
    }
 
+   xil_printf("ReadCmd: 0x%x, WriteCmd: 0x%x,"
+          "StatusCmd: 0x%x, FSRFlag: %d\n\r",
+          ReadCmd, WriteCmd, StatusCmd, FSRFlag);
+
    for (UniqueValue = UNIQUE_VALUE, Count = 0;
            Count < PageSize;
            Count++, UniqueValue++) {
@@ -1986,6 +1986,7 @@
        while (TransferInProgress);
 
        WriteEnableCmd = WRITE_ENABLE_CMD;
+       GetRealAddr(QspiPsuPtr, TEST_ADDRESS);
        /*
         * Send the write enable command to the Flash
         * so that it can be written to, this needs
@@ -2006,8 +2007,6 @@
        }
        while (TransferInProgress);
 
-      GetRealAddr(QspiPsuPtr, TEST_ADDRESS);
-
        WriteBuffer[0] = WRITE_CONFIG_CMD;
        WriteBuffer[1] |= 0x02;
        WriteBuffer[2] |= 0x01 << 1;
@@ -2071,6 +2070,7 @@
        FlashMsg[0].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
        FlashMsg[0].Flags = XQSPIPSU_MSG_FLAG_TX;
 
+       memset(ReadBfrPtr, 0xff, sizeof(ReadBfrPtr));
        FlashMsg[1].TxBfrPtr = NULL;
        FlashMsg[1].RxBfrPtr = ReadBfrPtr;
        FlashMsg[1].ByteCount = 1;