【MCXN947开发板测评】 W25Q64读写功能测试
[复制链接]
在MCXN947开发板上配有不同类型的存储器件,其中一种是QSPI类型的W25Q64,其电路如图1所示。
图1 接口电路
W25Q64测试的主程序为:
int main(void)
{
status_t status;
uint32_t i = 0U;
uint32_t serialNorAddress;
uint32_t AHBNorAddress;
uint32_t serialNorTotalSize;
uint32_t serialNorSectorSize;
uint32_t serialNorPageSize;
CLOCK_SetClkDiv(kCLOCK_DivFlexcom4Clk, 1u);
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
BOARD_InitPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
CLOCK_SetClkDiv(kCLOCK_DivFlexspiClk, 1U);
CLOCK_AttachClk(kFRO_HF_to_FLEXSPI);
PRINTF("\r\n FLEXSPI NOR example started!\r\n");
memset(&norConfig, 0U, sizeof(flexspi_nor_config_t));
#ifdef FLASH_USE_CUSTOM_FCB
memcpy(&norConfig, CUSTOM_FCB, sizeof(flexspi_nor_config_t));
#else
status = FLEXSPI_NorFlash_GetConfig(FlexSpiInstance, &norConfig, &option);
if (status == kStatus_Success)
{
PRINTF("\r\n Successfully get FLEXSPI NOR configuration block\r\n ");
}
else
{
PRINTF("\r\n Get FLEXSPI NOR configuration block failure!\r\n");
error_trap();
}
#endif
status = FLEXSPI_NorFlash_Init(FlexSpiInstance, &norConfig);
if (status == kStatus_Success)
{
PRINTF("\r\n Successfully init FLEXSPI serial NOR flash\r\n ");
}
else
{
PRINTF("\r\n Erase sector failure !\r\n");
error_trap();
}
serialNorTotalSize = norConfig.memConfig.sflashA1Size;
serialNorSectorSize = norConfig.sectorSize;
serialNorPageSize = norConfig.pageSize;
PRINTF("\r\n Serial NOR flash Information: ");
PRINTF("\r\n Serial NOR flash size:\t%d KB, Hex: (0x%x)", (serialNorTotalSize / 1024U), serialNorTotalSize);
PRINTF("\r\n Serial NOR flash sector size:\t%d KB, Hex: (0x%x) ", (serialNorSectorSize / 1024U),
serialNorSectorSize);
PRINTF("\r\n Serial NOR flash page size:\t%d B, Hex: (0x%x)\r\n", serialNorPageSize, serialNorPageSize);
#ifndef SECTOR_INDEX_FROM_END
#define SECTOR_INDEX_FROM_END 1U
#endif
serialNorAddress = serialNorTotalSize - (SECTOR_INDEX_FROM_END * serialNorSectorSize);
AHBNorAddress = EXAMPLE_FLEXSPI_AMBA_BASE + serialNorAddress;
PRINTF("\r\n Erasing serial NOR flash over FLEXSPI");
status = FLEXSPI_NorFlash_Erase(FlexSpiInstance, &norConfig, serialNorAddress, serialNorSectorSize);
if (status == kStatus_Success)
{
PRINTF("\r\n Successfully erased one sector of NOR flash device 0x%x -> 0x%x\r\n", serialNorAddress,
(serialNorAddress + serialNorSectorSize));
}
else
{
PRINTF("\r\n Erase sector failure!\r\n");
error_trap();
}
PRINTF("\r\n Program a buffer to a page of NOR flash\r\n");
for (i = 0; i < BUFFER_LEN; i++)
{
s_buffer[i] = i;
}
status = FLEXSPI_NorFlash_ProgramPage(FlexSpiInstance, &norConfig, serialNorAddress, (const uint32_t *)s_buffer);
if (status != kStatus_Success)
{
PRINTF("\r\n Page program failure!\r\n");
error_trap();
}
PRINTF("\r\n Access serial NOR flash through AHB\r\n ");
memcpy(s_buffer_rbc, (void *)(AHBNorAddress), sizeof(s_buffer_rbc));
if (memcmp(s_buffer_rbc, s_buffer, sizeof(s_buffer)) == 0)
{
PRINTF("\r\n Successfully programmed and verified location FLEXSPI AMBA memory 0x%x -> 0x%x \r\n",
(AHBNorAddress), (AHBNorAddress + sizeof(s_buffer)));
}
else
{
PRINTF("\r\n Program data - read out data value incorrect!\r\n ");
error_trap();
}
status = FLEXSPI_NorFlash_Erase(FlexSpiInstance, &norConfig, serialNorAddress, serialNorSectorSize);
app_finalize();
return 0;
}
经程序的编译和下载,其显示效果如图2所示,说明测试正常。在该程序的基础上,当需要进行存储空间扩展时就提供了极大的方便。
图2 测试结果
|