aple0807 发表于 2024-5-12 10:43

【AT-START-F405测评】QPI-FLASH 操作测试

        AT32F405支持QPI外设,挂载FLASH可以方便存储设备日志和历史数据。
        今天测试一下QPI操作FLASH的速度,板载16MB SPI-FLASH。
        测试代码如下:
if (1 == nortst.check_req)
        {
                uint32_t amount = nortst.amount;
                uint32_t ticks;

                // 写入数据
                uint32_t dats = nortst.dat = nortst.dat_first;

                flash_dbg_print("nor flash check : start : R/W : %dMB\n", amount / (1024 * 1024));
                ticks = app_tick_get();
                for (nortst.addr = nortst.addr_start; nortst.addr < amount + nortst.addr_start; nortst.addr += SPI_NOR_PAGE_SIZE)
                {
                        if (nortst.addr % SPI_NOR_SECTOR_SIZE == 0)
                        {
                                bsp_snor_sector_erase(nortst.addr);
                        }

                        for (int index = 0; index < SPI_NOR_PAGE_SIZE / 4; index++)
                        {
                                nortst.buff.uVal = nortst.dat++;
                        }

                        // 写入一页数据
                        bsp_snor_write(nortst.addr, SPI_NOR_PAGE_SIZE, nortst.buff.v);

                        if (0 == (nortst.addr & 0x03FFFF))
                        {
                                flash_dbg_print("nor flash check write data: %d %% \n", (nortst.addr - nortst.addr_start) * 100 / amount);
                        }
                       
                        if (!nortst.check_req)
                                break;
                }
                flash_dbg_print("nor flash write end: time : %d ms \n", app_tick_get() - ticks);

                // 读回校验
                ticks = app_tick_get();
                nortst.dat = dats;
                for (nortst.addr = nortst.addr_start; nortst.addr < amount + nortst.addr_start; nortst.addr += SPI_NOR_PAGE_SIZE)
                {
                        if (nortst.addr % SPI_NOR_SECTOR_SIZE == 0)
                        {
                                // 读取一扇区数据
                                bsp_snor_read(nortst.addr, SPI_NOR_SECTOR_SIZE, nortst.buff.v);

                                for (int index = 0; index < SPI_NOR_SECTOR_SIZE / 4; index++)
                                {
                                        if (nortst.buff.uVal != nortst.dat)
                                        {
                                                nortst.err++;
                                        }
                                        nortst.dat++;
                                }

                                if (nortst.err)
                                {
                                        flash_dbg_print("nor flash check err: %d @ %x \n", nortst.err, nortst.addr);
                                        nortst.err = 0;
                                }
                        }
                       
                        if (!nortst.check_req)
                                break;
                }

                nortst.check_req = 0;
                flash_dbg_print("nor flash read and check end : time : %d ms\n", app_tick_get() - ticks);

                set_u32(nortst.buff, 0, 4096 / 4);

                nortst.chk_cnt++;
                if (nortst.err)
                        nortst.chk_err_cnt++;
        }        其主要功能是根据指定地址和数量写入数据,然后读取并验证数据是否损坏。
       
        测试结果如下:
        QPI时钟频率配置为54MHz。
        控制台输入 nor check 4

        测试4MB数据读写,写入耗时35s,大约100+KB/s。
        读取并验证耗时:239ms,换算速度约16.7MB/s,这个速度相当可观。
        下面附上测试代码:


gouguoccc 发表于 2024-5-12 11:14

些数据这个时间不对吧?这么长?

aple0807 发表于 2024-5-12 11:28

gouguoccc 发表于 2024-5-12 11:14
些数据这个时间不对吧?这么长?

时间很长吗?外部FLASH,读取并验证4MB数据,239ms

gyh974 发表于 2024-5-13 09:48

QPI是什么意思?有原理图?怎么和MCU连接才是快速接口?

呐咯密密 发表于 2024-5-13 13:19

挺不错的测试,后面也要做QSPI,有个借鉴

aple0807 发表于 2024-5-13 17:13

gyh974 发表于 2024-5-13 09:48
QPI是什么意思?有原理图?怎么和MCU连接才是快速接口?

QPI 和 SPI信号时序一样,区别是QPI有4条数据线,工作在半双工模式。
页: [1]
查看完整版本: 【AT-START-F405测评】QPI-FLASH 操作测试