Hi,
I am currently trying to read a page of test data from the external flash with the RT1176. I have written the following content to flash using the FlexSPI interface:
I have validated that this data is written correctly and persists as expected. However, when I try to read this data using AHB I am getting invalid data where the first two bytes are always CC CC. This causes the data to be offset and results in the last two bytes of the stored flash data to be ignored (see below).
It appears that are the start of every page there is two bytes that contain CC CC despite there being no such data in the flash. I have made sure to clean and invalidate the D-Cache at the range I am reading from prior to performing a memcpy. I am using the following code to perform the read operation:
int main(void) {
/* Init board hardware. */
BOARD_ConfigMPU();
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
#ifndef BOARD_INIT_DEBUG_CONSOLE_PERIPHERAL
/* Init FSL debug console. */
BOARD_InitDebugConsole();
#endif
// SCB_EnableDCache();
FLASH_Initialise(FLEXSPI1);
FLASH_EnableQuadMode(FLEXSPI1);
DCACHE_CleanInvalidateByRange(0x30140000, 256);
// DCACHE_InvalidateByRange(0x30140000, 256);
uint8_t data[256] = { 0xFF };
memcpy(data, (void *)0x30140000, 256);
PRINTF("Data: \r\n");
for(uint16_t i = 0; i < 256; i++) {
if(i % 20 == 0) PRINTF("\r\n");
PRINTF("%02X ", data[i]);
}
for( ;; ) __asm__("nop"); // Infinite loop
PRINTF("Well **bleep** \r\n");
return 0; // This should never be reached
}
void FLASH_Initialise(FLEXSPI_Type *base) {
flexspi_config_t config;
STK_DisableDCache(); // Disable D-Cache if exists
flexspi1_clock_init();
FLEXSPI_GetDefaultConfig(&config);
config.ahbConfig.enableAHBPrefetch = true;
config.ahbConfig.enableAHBBufferable = true;
config.ahbConfig.enableAHBCachable = true;
config.ahbConfig.enableReadAddressOpt = true;
config.rxSampleClock = kFLEXSPI_ReadSampleClkLoopbackFromDqsPad;
FLEXSPI_Init(base, &config);
FLEXSPI_SetFlashConfig(base, &deviceConfig, kFLEXSPI_PortA1);
FLEXSPI_UpdateLUT(base, 0, flashLookupTable, FLASH_LUT_SIZE);
FLEXSPI_SoftwareReset(base);
STK_EnableDCache(); // Enable D-Cache if exists
}
status_t FLASH_EnableQuadMode(FLEXSPI_Type *base) {
flexspi_transfer_t transfer;
status_t status;
uint32_t writeVal = FLASH_QUAD_ENABLE;
status = FLASH_EnableWrite(base, 0);
if(status != kStatus_Success) return status;
transfer.deviceAddress = 0;
transfer.port = kFLEXSPI_PortA1;
transfer.cmdType = kFLEXSPI_Write;
transfer.SeqNumber = 1;
transfer.seqIndex = NOR_CMD_LUT_SEQ_IDX_WRITESTATUSREG;
transfer.data = &writeVal;
transfer.dataSize = 1;
status = FLEXSPI_TransferBlocking(base, &transfer);
if(status != kStatus_Success) return status;
status = FLASH_WaitForBusFinish(base);
FLASH_ClearBuffer(base);
return status;
}
static inline void flexspi1_clock_init(void) {
CLOCK_SetRootClockDiv(kCLOCK_Root_Flexspi1, 2);
CLOCK_SetRootClockMux(kCLOCK_Root_Flexspi1, 0);
}
Any ideas as to what could be causing this?
Thanks,
Jon
Flash chip being used: MT25QU512ABB
SoM being used: TQMa117xL