2022-10-16 20:42:31 +08:00
|
|
|
/*
|
2022-10-16 20:42:31 +08:00
|
|
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
2022-10-16 20:42:31 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2020-08-07 NU-LL first version
|
|
|
|
*/
|
2022-10-16 20:42:31 +08:00
|
|
|
#include <rtthread.h>
|
|
|
|
#include <rtdevice.h>
|
|
|
|
#include <drv_spi.h>
|
|
|
|
#include <spi_flash.h>
|
|
|
|
#include <spi_flash_sfud.h>
|
2022-10-16 20:42:31 +08:00
|
|
|
#include <fal.h>
|
|
|
|
#include <dfs_fs.h>
|
|
|
|
|
2022-10-16 20:42:31 +08:00
|
|
|
#define DRV_DEBUG
|
|
|
|
#define LOG_TAG "drv.spiflash"
|
2022-10-16 20:42:31 +08:00
|
|
|
#include <drv_log.h>
|
|
|
|
|
2022-10-16 20:42:31 +08:00
|
|
|
#define FS_PARTITION_NAME "filesystem"
|
2022-10-16 20:42:31 +08:00
|
|
|
|
2022-10-16 20:42:31 +08:00
|
|
|
#define SPI_CS_GPIO GPIOD
|
|
|
|
#define SPI_CS_PIN GPIO_PIN_6
|
2022-10-16 20:42:31 +08:00
|
|
|
|
|
|
|
static int rt_hw_spi_flash_with_sfud_init(void)
|
|
|
|
{
|
2022-10-16 20:42:31 +08:00
|
|
|
rt_err_t err = RT_EOK;
|
2023-01-18 13:27:08 +08:00
|
|
|
rt_hw_spi_device_attach("spi1", "spi10", GET_PIN(D, 6));
|
2022-10-16 20:42:31 +08:00
|
|
|
|
|
|
|
/* init W25Q16 , And register as a block device */
|
2022-10-16 20:42:31 +08:00
|
|
|
if (RT_NULL == rt_sfud_flash_probe(FAL_USING_NOR_FLASH_DEV_NAME, "spi10"))
|
2022-10-16 20:42:31 +08:00
|
|
|
{
|
2022-10-16 20:42:31 +08:00
|
|
|
LOG_E("Failed to probe flash device "FAL_USING_NOR_FLASH_DEV_NAME);
|
2022-10-16 20:42:31 +08:00
|
|
|
return -RT_ERROR;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
INIT_DEVICE_EXPORT(rt_hw_spi_flash_with_sfud_init);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int mnt(void)
|
|
|
|
{
|
|
|
|
struct rt_device *mtd_dev = RT_NULL;
|
|
|
|
|
|
|
|
fal_init();
|
|
|
|
mtd_dev = fal_mtd_nor_device_create(FS_PARTITION_NAME);
|
|
|
|
if (!mtd_dev)
|
|
|
|
{
|
|
|
|
LOG_E("Can't create a mtd device on '%s' partition.", FS_PARTITION_NAME);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* mount littlefs */
|
|
|
|
if (dfs_mount(FS_PARTITION_NAME, "/", "lfs", 0, 0) == 0)
|
|
|
|
{
|
|
|
|
LOG_I("Filesystem initialized!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dfs_mkfs("lfs", FS_PARTITION_NAME);
|
|
|
|
/* mount littlefs */
|
|
|
|
if (dfs_mount(FS_PARTITION_NAME, "/", "lfs", 0, 0) == 0)
|
|
|
|
{
|
|
|
|
mkdir("/qspi",0x777);
|
2022-10-16 20:42:31 +08:00
|
|
|
LOG_I("mkdir /qspi. Filesystem initialized!");
|
2022-10-16 20:42:31 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_E("Failed to initialize filesystem!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
INIT_ENV_EXPORT(mnt);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|