beyond_笑谈 发表于 2024-11-22 23:50

【Follow me第二季第3期】quad-spi flash和octo-spi flash程序配置及读写速度测试

<p>测试quad-spi flash和octo-spi flash读写速度对比,如下图</p>

<p > &nbsp;</p>

<p >&nbsp;</p>

<p >对应代码如下:</p>

<p >进入主函数(main.c)找到菜单任务</p>

<p > &nbsp;</p>

<p >通过菜单任务逐布找到菜单选项部分程序,也就是串口调试页面的菜单选项,如下</p>

<p > &nbsp;</p>

<p >&nbsp;</p>

<p >进入spi测试部分程序</p>

<p > &nbsp;</p>

<p >&nbsp;</p>

<p >SPI读写测试程序及转换程序如下</p>

<p align="left" >ospi_performance_test (block_size_actual, &amp;ospi_performance_write_result, &amp;ospi_performance_read_result);</p>

<p align="left" >&nbsp;</p>

<p align="left" >ospi_write_result = ((100000000 / timer_frequency) * ospi_performance_write_result) / 100;</p>

<p align="left" >qspi_write_result&nbsp; = ((100000000 / timer_frequency) * qspi_write_test(block_size_actual)) / 100;</p>

<p align="left" >&nbsp;</p>

<p align="left" >print_to_console((uint8_t *)&quot;Writing to flash completed\r\n&quot;);</p>

<p align="left" >print_to_console((uint8_t *)&quot;\r\nReading the text block from external Quad-SPI and Octo-SPI flash memories...\r\n&quot;);</p>

<p align="left" >&nbsp;</p>

<p align="left" >ospi_read_result&nbsp; = ((100000000 / timer_frequency) * ospi_performance_read_result) / 100;</p>

<p align="left" >qspi_read_result&nbsp; = ((100000000 / timer_frequency) * qspi_read_test(block_size_actual)) / 100;</p>

<p >&nbsp;</p>

<p >ospi数据写入测试程序如下:</p>

<p >static uint32_t write_dopi_ospi(uint32_t data_size)</p>

<p >{</p>

<p >&nbsp;&nbsp;&nbsp; fsp_err_t err;</p>

<p >&nbsp;&nbsp;&nbsp; uint32_t test_var;</p>

<p >&nbsp;&nbsp;&nbsp; uint8_t * p_dest = (uint8_t *)OSPI_DMA_ADDRESS;</p>

<p >&nbsp; &nbsp;&nbsp;timer_status_t status = {};</p>

<p >&nbsp;&nbsp;&nbsp; uint32_t number_of_pages;</p>

<p >&nbsp;&nbsp;&nbsp; R_GPT_Open(g_memory_performance.p_ctrl, g_memory_performance.p_cfg);</p>

<p >&nbsp;&nbsp;&nbsp; number_of_pages = (uint32_t)(data_size * (1024 / OSPI_TEST_PAGE_SIZE));</p>

<p >&nbsp;</p>

<p >for (test_var = 0; test_var &lt; number_of_pages; test_var++ )</p>

<p >&nbsp;{</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R_GPT_Start(g_memory_performance.p_ctrl);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; err = R_OSPI_Write(g_ospi.p_ctrl, s_page, p_dest, OSPI_TEST_PAGE_SIZE);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (FSP_SUCCESS != err)</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;__asm(&quot;bkpt&quot;);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ospi_test_wait_until_wip();</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p_dest += OSPI_TEST_PAGE_SIZE;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R_GPT_Stop(g_memory_performance.p_ctrl);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vTaskDelay(1U);</p>

<p >&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;</p>

<p >&nbsp;&nbsp;&nbsp; R_GPT_StatusGet(g_memory_performance.p_ctrl, &amp;status);</p>

<p >&nbsp;&nbsp;&nbsp; R_GPT_Reset(g_memory_performance.p_ctrl);</p>

<p >&nbsp;&nbsp;&nbsp; R_GPT_Close(g_memory_performance.p_ctrl);</p>

<p >&nbsp;</p>

<p >&nbsp;&nbsp;&nbsp; return (status.counter);</p>

<p >}</p>

<p >&nbsp;</p>

<p >ospi数据读取测试程序如下:</p>

<p >static uint32_t read_dopi_ospi(uint32_t data_size)</p>

<p >{</p>

<p >&nbsp; &nbsp;&nbsp;uint32_t * p_src = (uint32_t *)OSPI_DMA_ADDRESS;</p>

<p >&nbsp;&nbsp;&nbsp; uint32_t * p_dest = (uint32_t *)s_perf_read;</p>

<p >&nbsp;&nbsp;&nbsp; timer_status_t status = {};</p>

<p >&nbsp;&nbsp;&nbsp; R_GPT_Open(g_memory_performance.p_ctrl, g_memory_performance.p_cfg);</p>

<p >#ifdef READ_PAGE_BY_PAGE</p>

<p >&nbsp;&nbsp;&nbsp; number_of_blocks = data_size * ( 1024 / OSPI_TEST_PAGE_SIZE);</p>

<p >&nbsp;</p>

<p >&nbsp;&nbsp;&nbsp; while(number_of_blocks--)</p>

<p >&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data = (OSPI_TEST_PAGE_SIZE) / 4U;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R_GPT_Start(g_memory_performance.p_ctrl);</p>

<p >&nbsp;</p>

<p >#ifdef MANUAL_READ</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (data)</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *p_dest = *p_src;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p_dest++;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p_src++;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data--;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>

<p >#endif</p>

<p >&nbsp;</p>

<p >#define READ_MEMCPY</p>

<p >#ifdef READ_MEMCPY</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memcpy ( p_dest, p_src, OSPI_TEST_PAGE_SIZE / 4);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p_src += OSPI_TEST_PAGE_SIZE / 4;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p_dest += OSPI_TEST_PAGE_SIZE / 4;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R_GPT_Stop(g_memory_performance.p_ctrl);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vTaskDelay(1U);</p>

<p >#endif</p>

<p >&nbsp;&nbsp;&nbsp; }</p>

<p >#endif</p>

<p >&nbsp;</p>

<p >#ifdef READ_AS_SINGLE_BLOCK</p>

<p >&nbsp;&nbsp;&nbsp; R_GPT_Start(g_memory_performance.p_ctrl);</p>

<p >&nbsp;&nbsp;&nbsp; R_OSPI_XipEnter(g_ospi.p_ctrl);</p>

<p >&nbsp;&nbsp;&nbsp; memcpy (p_dest, p_src, (data_size * 1024) / 4);</p>

<p >&nbsp;&nbsp;&nbsp; R_OSPI_XipExit(g_ospi.p_ctrl);</p>

<p >&nbsp;&nbsp;&nbsp; R_GPT_Stop(g_memory_performance.p_ctrl);</p>

<p >#endif</p>

<p >&nbsp;</p>

<p >&nbsp;&nbsp;&nbsp; R_GPT_StatusGet(g_memory_performance.p_ctrl, &amp;status);</p>

<p >&nbsp;&nbsp;&nbsp; R_GPT_Reset(g_memory_performance.p_ctrl);</p>

<p >&nbsp;&nbsp;&nbsp; R_GPT_Close(g_memory_performance.p_ctrl);</p>

<p >&nbsp;&nbsp;&nbsp; return (status.counter);</p>

<p >}</p>

<p >&nbsp;</p>

<p >qspi数据写入测试程序如下:</p>

<p >static uint32_t qspi_write_test(uint32_t block_size)</p>

<p >{</p>

<p >&nbsp;&nbsp;&nbsp; fsp_err_t fsp_err;</p>

<p >&nbsp;&nbsp;&nbsp; uint32_t qspi_write_result = 0;</p>

<p >&nbsp;&nbsp;&nbsp; timer_status_t status = {};</p>

<p >&nbsp;&nbsp;&nbsp; fsp_err_t err = FSP_SUCCESS;</p>

<p >&nbsp;&nbsp;&nbsp; spi_flash_protocol_t current_spi_mode;</p>

<p >&nbsp;</p>

<p >&nbsp;&nbsp; &nbsp;block_size *= 1024;</p>

<p >&nbsp;&nbsp;&nbsp; current_spi_mode = SPI_FLASH_PROTOCOL_EXTENDED_SPI;</p>

<p >&nbsp;&nbsp;&nbsp; err = qpi_init();</p>

<p >&nbsp;&nbsp;&nbsp; if (FSP_SUCCESS == err)</p>

<p >&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; current_spi_mode = g_qspi_cfg.spi_protocol;</p>

<p >&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp; uint32_t page_write_count = 0;</p>

<p >&nbsp;&nbsp;&nbsp; uint8_t&nbsp; * p_mem_addr;</p>

<p >&nbsp;&nbsp;&nbsp; p_mem_addr = (uint8_t *)QSPI_DEVICE_START_ADDRESS;</p>

<p >&nbsp;&nbsp;&nbsp; while (((page_write_count * SECTOR_SIZE) &lt; block_size)</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;&amp; ( FSP_SUCCESS == err ) )</p>

<p >&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; err = R_QSPI_Erase(&amp;g_qspi_ctrl, p_mem_addr, SECTOR_SIZE);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (FSP_SUCCESS != err)</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sprintf(s_print_buffer, &quot;R_QSPI_Erase Failed\r\n&quot;);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; err = get_flash_status();</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (FSP_SUCCESS != err)</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sprintf(s_print_buffer, &quot;Failed to get status for QSPI operation\r\n&quot;);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uint32_t count;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (count = 0; count &lt; SECTOR_SIZE; count++ )</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (DEFAULT_MEM_VAL != p_mem_addr)</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p>

<p >&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;err = FSP_ERR_NOT_ERASED;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p_mem_addr += SECTOR_SIZE;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; page_write_count++;</p>

<p >&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp; fsp_err = R_GPT_Start(g_memory_performance.p_ctrl);</p>

<p >&nbsp;&nbsp;&nbsp; if (FSP_SUCCESS != fsp_err)</p>

<p >&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SYSTEM_ERROR</p>

<p >&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp; p_mem_addr = (uint8_t *)QSPI_DEVICE_START_ADDRESS;</p>

<p >&nbsp;&nbsp;&nbsp; page_write_count = 0;</p>

<p >&nbsp;&nbsp;&nbsp; while (((page_write_count * PAGE_WRITE_SIZE) &lt; block_size)</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;&amp; (FSP_SUCCESS == err))</p>

<p >&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (FSP_SUCCESS == err)</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; err = R_QSPI_Write(&amp;g_qspi_ctrl, &amp;(sp_source), p_mem_addr, PAGE_WRITE_SIZE);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (FSP_SUCCESS != err)</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sprintf(s_print_buffer, &quot;R_QSPI_Write Failed\r\n&quot;);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; err = get_flash_status();</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (FSP_SUCCESS != err)</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sprintf(s_print_buffer, &quot;Failed to get status for QSPI operation\r\n&quot;);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p_mem_addr += PAGE_WRITE_SIZE;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; page_write_count++;</p>

<p >&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp; deinit_qspi(current_spi_mode);</p>

<p >&nbsp;&nbsp;&nbsp; fsp_err = R_GPT_Stop(g_memory_performance.p_ctrl);</p>

<p >&nbsp;&nbsp;&nbsp; if (FSP_SUCCESS != fsp_err)</p>

<p >&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SYSTEM_ERROR</p>

<p >&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp; fsp_err = R_GPT_StatusGet(g_memory_performance.p_ctrl, &amp;status);</p>

<p >&nbsp;&nbsp;&nbsp; if (FSP_SUCCESS != fsp_err)</p>

<p >&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SYSTEM_ERROR</p>

<p >&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp; fsp_err = R_GPT_Reset(g_memory_performance.p_ctrl);</p>

<p >&nbsp;&nbsp;&nbsp; if (FSP_SUCCESS != fsp_err)</p>

<p >&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SYSTEM_ERROR</p>

<p >&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp; qspi_write_result = status.counter;</p>

<p >&nbsp;&nbsp;&nbsp; return (qspi_write_result);</p>

<p >}</p>

<p >&nbsp;</p>

<p >qspi数据读取测试程序如下:</p>

<p >static uint32_t qspi_read_test(uint32_t block_size)</p>

<p >{</p>

<p >&nbsp;&nbsp;&nbsp; fsp_err_t fsp_err;</p>

<p >&nbsp;&nbsp;&nbsp; fsp_err_t err = FSP_SUCCESS;</p>

<p >&nbsp;&nbsp;&nbsp; uint32_t qspi_read_result = 0;</p>

<p >&nbsp;&nbsp;&nbsp; timer_status_t status = {};</p>

<p >&nbsp;&nbsp;&nbsp; spi_flash_protocol_t current_spi_mode;</p>

<p >&nbsp;&nbsp;&nbsp; uint8_t&nbsp; * p_dma_read_buffer;</p>

<p >&nbsp;&nbsp;&nbsp; uint32_t&nbsp;&nbsp; page_read_count;</p>

<p >&nbsp;&nbsp;&nbsp; uint8_t&nbsp; * p_mem_addr;</p>

<p >&nbsp;&nbsp;&nbsp; block_size *= 1024;</p>

<p >&nbsp;&nbsp;&nbsp; p_dma_read_buffer = pvPortMalloc(block_size);</p>

<p >&nbsp;&nbsp;&nbsp; if (NULL == p_dma_read_buffer)</p>

<p >&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HeapStats_t pxHeapStats;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vPortGetHeapStats(&amp;pxHeapStats);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sprintf(s_print_buffer, &quot;\r\nQSPI malloc operation Failed - Max free mem: %dbytes\r\n&quot;,</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pxHeapStats.xSizeOfLargestFreeBlockInBytes);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; err = FSP_ERR_NOT_ERASED;</p>

<p >&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;</p>

<p >&nbsp;&nbsp;&nbsp; current_spi_mode = SPI_FLASH_PROTOCOL_EXTENDED_SPI;</p>

<p >&nbsp;&nbsp;&nbsp; err = qpi_init();</p>

<p >&nbsp;&nbsp;&nbsp; if (FSP_SUCCESS == err)</p>

<p >&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; current_spi_mode = g_qspi_cfg.spi_protocol;</p>

<p >&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp; fsp_err = R_GPT_Start(g_memory_performance.p_ctrl);</p>

<p >&nbsp;&nbsp;&nbsp; if (FSP_SUCCESS != fsp_err)</p>

<p >&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SYSTEM_ERROR</p>

<p >&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp; page_read_count = 0;</p>

<p >&nbsp;&nbsp;&nbsp; p_mem_addr = (uint8_t *)QSPI_DEVICE_START_ADDRESS;</p>

<p >&nbsp;&nbsp;&nbsp; while (((page_read_count * PAGE_WRITE_SIZE) &lt; block_size)</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;&amp; (FSP_SUCCESS == err))</p>

<p >&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ((fsp_err_t) (memcmp (p_mem_addr, &amp;(sp_source), PAGE_WRITE_SIZE)) != FSP_SUCCESS)</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; err = FSP_ERR_NOT_ERASED;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sprintf(s_print_buffer, &quot;\r\nQSPI operation Failed -&gt; Data read does not match with written data\r\n&quot;);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p_mem_addr += PAGE_WRITE_SIZE;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; page_read_count++;</p>

<p >&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp; fsp_err = R_GPT_Stop(g_memory_performance.p_ctrl);</p>

<p >&nbsp;&nbsp;&nbsp; deinit_qspi(current_spi_mode);</p>

<p >&nbsp;&nbsp;&nbsp; if (FSP_SUCCESS != fsp_err)</p>

<p >&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SYSTEM_ERROR</p>

<p >&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp; fsp_err = R_GPT_StatusGet(g_memory_performance.p_ctrl, &amp;status);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp; if (FSP_SUCCESS != fsp_err)</p>

<p >&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SYSTEM_ERROR</p>

<p >&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp; fsp_err = R_GPT_Reset(g_memory_performance.p_ctrl);</p>

<p >&nbsp;&nbsp;&nbsp; if (FSP_SUCCESS != fsp_err)</p>

<p >&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SYSTEM_ERROR</p>

<p >&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp; qspi_read_result = status.counter;</p>

<p >&nbsp;&nbsp;&nbsp; vPortFree(p_dma_read_buffer);</p>

<p >&nbsp;&nbsp;&nbsp; return (qspi_read_result);</p>

<p >}</p>
页: [1]
查看完整版本: 【Follow me第二季第3期】quad-spi flash和octo-spi flash程序配置及读写速度测试