68|0

108

帖子

0

TA的资源

一粒金砂(中级)

楼主
 

【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 测试结果

此帖出自NXP MCU论坛
点赞 关注
 

回复
举报
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/8 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表