AnsweredAssumed Answered

Negative effect of enabling Prefetcher for XIP from NOR flash memory

Question asked by Kamran Farhangi on Apr 1, 2020
Latest reply on Apr 19, 2020 by Kamran Farhangi

Using an IMXRT1062 on an IMXRT1060 Evaluation kit, I'm trying to run the code from a NOR flash memory (XIP). I noticed if I disable the prefetcher (AHBCR->PREFETCHEN = 0), the code runs slightly faster (about 12% to be exact). I am a bit confused as I expect the opposite for disabling the prefetch. So can someone explain in what conditions can this happen or what am I doing wrong?

The flash memory configuration is as follows:

 

static const FlexSPINorConfig __attribute__((section(".boot_hdr.conf"), used)) g_flash_config =
{
    .memConfig = {
        .tag                  = FLEXSPI_CFG_BLK_TAG,
        .version              = FLEXSPI_CFG_BLK_VERSION,
        .readSampleClkSrc     = kFlexSPIReadSampleClk_LoopbackFromDqsPad,
        .csHoldTime           = 3u,
        .csSetupTime          = 3u,
        .columnAddressWidth   = 0u,
        .configCmdEnable      = 0u,
        .controllerMiscOption = (1 << kFlexSpiMiscOffset_SafeConfigFreqEnable),
        .deviceType           = kFlexSpiDeviceType_SerialNOR,
        .sflashPadType        = kSerialFlash_4Pads,
        .serialClkFreq        = kFlexSpiSerialClk_133MHz,
        .lutCustomSeqEnable   = 0u,
        .sflashA1Size         = 0x00800000u, /* 8MB/64Mbit */
        .lookupTable =
            {
                // 0 Fast read sequence
                [0] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xEB, RADDR_SDR, FLEXSPI_4PAD,0x18),
                [1] = FLEXSPI_LUT_SEQ(DUMMY_SDR, FLEXSPI_4PAD, 0x06, READ_SDR, FLEXSPI_4PAD, 0x04),
                [2] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [3] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                // 1 Read Status sequence
                [4] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x05, READ_SDR, FLEXSPI_1PAD, 0x04),
                [5] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [6] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [7] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                // 2 Reserved
                [8]  = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [9]  = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [10] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [11] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                // 3 Write Enable sequence
                [12] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x06, STOP, 00),
                [13] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [14] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [15] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                // 4 Reserved
                [16] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [17] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [18] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [19] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                // 5 erase sector sequence
                [20] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x20, RADDR_SDR, FLEXSPI_1PAD, 0x18),
                [21] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [22] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [23] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                // 6 Reserved
                [24] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [25] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [26] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [27] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                // 7 Reserved
                [28] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [29] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [30] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [31] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                // 8 Reserved
                [32] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xD8, RADDR_SDR, FLEXSPI_1PAD, 0x18),
                [33] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [34] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [35] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                // 9 page program sequence
                [36] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x02, RADDR_SDR, FLEXSPI_1PAD, 0x18),
                [37] = FLEXSPI_LUT_SEQ(WRITE_SDR, FLEXSPI_1PAD, 0x04, STOP, 00),
                [38] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [39] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                // 10 Reserved
                [40] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [41] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [42] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [43] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                // 11 chip erase sequence
                [44] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x60, STOP, 00),
                [45] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [46] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [47] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                // 12 Reserved
                [48] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [49] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [50] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [51] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                // 13 Reserved
                [52] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [53] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [54] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [55] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                // 14 Reserved
                [56] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [57] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [58] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [59] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                // 15 Reserved
                [60] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [61] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [62] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
                [63] = FLEXSPI_LUT_SEQ(STOP, 00, STOP, 00),
            },
    },
    .pageSize = 256,
    .sectorSize = 4096,
    .ipcmdSerialClkFreq = kFlexSpiSerialClk_30MHz,
    .isUniformBlockSize = 0,
    .serialNorType = 0,
    .needExitNoCmdMode = 0,
    .halfClkForNonReadCmd = 0,
    .needRestoreNoCmdMode = 0,
    .blockSize = 0x10000,
};

Outcomes