潘多拉,打开板载 spi flash
简单的进行测试:
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <spi_flash_sfud.h>
int main(void)
{
sfud_err result;
uint8_t *read_data;//读取到的数据
uint8_t *write_data;//将要写入的数据
sfud_flash *sfud_dev = NULL;
#if 0 // 法1:获取 sfud_dev
sfud_dev = rt_sfud_flash_find_by_dev_name("W25Q128");
if (sfud_dev != RT_NULL)
{
rt_kprintf("Find sfud_dev success, sfud_dev name = %s\n", sfud_dev->name);
}
#else // 法2:获取 sfud_dev
sfud_dev = rt_sfud_flash_find("qspi10");
if (sfud_dev != RT_NULL)
{
rt_kprintf("Find sfud_dev success, sfud_dev name = %s\n", sfud_dev->name);
}
#endif
/* 擦除从 0 开始的 4096 字节 */
result = sfud_erase(sfud_dev, 0, 4096);
if (result == SFUD_SUCCESS)
{
rt_kprintf("Erase success\n");
}
/* 写入从 0 开始的 32 字节, 0x01 */
write_data = rt_malloc(32);
rt_memset(write_data, 1, 32);
result = sfud_write(sfud_dev, 0, 32, write_data);
if (result == SFUD_SUCCESS)
{
rt_kprintf("Write success.\n");
}
/* 读取从0开始的32字节 */
read_data = rt_malloc(32);
result = sfud_read(sfud_dev, 0, 32, read_data);
if (result == SFUD_SUCCESS)
{
rt_kprintf("Read success.\n ");
}
return RT_EOK;
}
\ | /
- RT - Thread Operating System
/ | \ 4.0.3 build Apr 27 2020
2006 - 2020 Copyright by rt-thread team
[D/drv.qspi] qspi init success!
[SFUD] Find a Winbond flash chip. Size is 16777216 bytes.
[SFUD] W25Q128 flash device is initialize success.
[D/drv.qspi] qspi init success!
Find sfud_dev success, sfud_dev name = W25Q128
msh >Erase success
Write success.
Read success.