添加qspi存储w25q128
添加littlefs文件系统 存储挂载路径/sys
This commit is contained in:
1 parent
c7cf944e61
commit
1f345bd81f
47 files changed
+22121
-346
No files matched your search
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2025-11-22 Administrator the first version
|
||||
*//*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2025-11-22 Administrator the first version
|
||||
*/
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include "fal_cfg.h"
|
||||
#include "spi_flash.h"
|
||||
#include "spi_flash_sfud.h"
|
||||
#include "drv_qspi.h"
|
||||
#include "dfs_fs.h"
|
||||
#include "fal.h"
|
||||
|
||||
/* 添加 DEBUG 头文件 */
|
||||
#include <rtdbg.h>
|
||||
|
||||
char w25qxx_read_status_register2(struct rt_qspi_device *device)
|
||||
{
|
||||
/* 0x35 read status register2 */
|
||||
char instruction = 0x35, status;
|
||||
rt_qspi_send_then_recv(device, &instruction, 1, &status, 1);
|
||||
return status;
|
||||
}
|
||||
|
||||
void w25qxx_write_enable(struct rt_qspi_device *device)
|
||||
{
|
||||
/* 0x06 write enable */
|
||||
char instruction = 0x06;
|
||||
rt_qspi_send(device, &instruction, 1);
|
||||
}
|
||||
|
||||
void w25qxx_enter_qspi_mode(struct rt_qspi_device *device)
|
||||
{
|
||||
char status = 0;
|
||||
/* 0x38 enter qspi mode */
|
||||
char instruction = 0x38;
|
||||
char write_status2_buf[2] = {0};
|
||||
/* 0x31 write status register2 */
|
||||
write_status2_buf[0] = 0x31;
|
||||
status = w25qxx_read_status_register2(device);
|
||||
if (!(status & 0x02))
|
||||
{
|
||||
status |= 1 << 1;
|
||||
w25qxx_write_enable(device);
|
||||
write_status2_buf[1] = status;
|
||||
rt_qspi_send(device, &write_status2_buf, 2);
|
||||
rt_qspi_send(device, &instruction, 1);
|
||||
LOG_D("flash already enter qspi mode");
|
||||
rt_thread_mdelay(10);
|
||||
}
|
||||
}
|
||||
|
||||
int spi_flash_init(void)
|
||||
{
|
||||
rt_err_t ret = stm32_qspi_bus_attach_device("qspi1", "qspi10", RT_NULL, 4, w25qxx_enter_qspi_mode, RT_NULL);
|
||||
if (ret != RT_EOK)
|
||||
{
|
||||
LOG_E("qspi attach device failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
/* init W25Q256 */
|
||||
// spi_flash_dev_name 需要用配置文件内的,spi_dev_name实际是SPI挂在参数
|
||||
if(rt_sfud_flash_probe(FAL_USING_NOR_FLASH_DEV_NAME, "qspi10") == RT_NULL)
|
||||
{
|
||||
LOG_E("rt sfud flash error");
|
||||
return -1;
|
||||
}
|
||||
LOG_I("SFUD flash '%s' probed successfully.", FAL_USING_NOR_FLASH_DEV_NAME);
|
||||
/* 初始化 fal */
|
||||
int fal_ = fal_init();
|
||||
if (fal_ > 0)
|
||||
{
|
||||
LOG_I("FAL Number of partitions = %d",fal_);
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
/* 创建 MTD 块设备 */
|
||||
if (fal_mtd_nor_device_create("sysdata") == RT_NULL)
|
||||
{
|
||||
LOG_E("Failed to create MTD device for sysdata!");
|
||||
return -1;
|
||||
}
|
||||
LOG_I("MTD device 'sysdata' created.");
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_DEVICE_EXPORT(spi_flash_init);
|
||||
|
||||
int qspi_fal(void)
|
||||
{
|
||||
LOG_I("Create file path /sys");
|
||||
mkdir("/sys", 0777);
|
||||
|
||||
/* 挂载 littlefs */
|
||||
if (dfs_mount("sysdata", "/sys", "lfs", 0, NULL) == RT_EOK)
|
||||
{
|
||||
LOG_I("Filesystem initialized!");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E("Format memory sysdata");
|
||||
/* 格式化文件系统 */
|
||||
dfs_mkfs("lfs", "sysdata");
|
||||
/* 挂载 littlefs */
|
||||
if (dfs_mount("sysdata", "/sys", "lfs", 0, NULL) == RT_EOK)
|
||||
{
|
||||
LOG_I("Filesystem initialized!");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E("Failed to initialize filesystem!");
|
||||
}
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_APP_EXPORT(qspi_fal);
|
||||
@@ -4,7 +4,7 @@
|
||||
#include"drv_common.h"
|
||||
#include "RUN_LED.h"
|
||||
|
||||
#define LED_PIN GET_PIN(B,0)
|
||||
#define LED_PIN GET_PIN(B,1)
|
||||
|
||||
/* 线程 1 的入口函数 */
|
||||
void RUN_LED(void *parameter)
|
||||
|
||||
@@ -24,6 +24,7 @@ void sd_mount(void *parameter)
|
||||
{
|
||||
if (rt_device_find("sd") != RT_NULL)
|
||||
{
|
||||
LOG_I("Create file path /sddisk");
|
||||
mkdir("/sddisk", 0777);
|
||||
if (dfs_mount("sd", "/sddisk", "elm", 0, NULL) == RT_EOK)
|
||||
{
|
||||
@@ -54,7 +55,6 @@ void sd_mount(void *parameter)
|
||||
int stm32_sdcard_mount(void)
|
||||
{
|
||||
rt_thread_t tid;
|
||||
rt_thread_mdelay(1000);
|
||||
// 删除旧的信号量(如果存在)
|
||||
if (mount_sem != RT_NULL)
|
||||
{
|
||||
@@ -72,7 +72,7 @@ int stm32_sdcard_mount(void)
|
||||
tid = rt_thread_create("sd_mount",
|
||||
sd_mount,
|
||||
RT_NULL,
|
||||
1024*6, // 避免溢出
|
||||
1024*2, // 避免溢出
|
||||
RT_THREAD_PRIORITY_MAX - 2,
|
||||
20);
|
||||
if (tid != RT_NULL)
|
||||
|
||||
@@ -28,11 +28,11 @@ int init_tmpfs_root(void)
|
||||
if (mkdir("/run", 0777) == 0) {
|
||||
LOG_I("Created /run directory");
|
||||
} else {
|
||||
LOG_E("mkdir failed, errno=%d", errno);
|
||||
LOG_E("mkdir failed, errno = %d", errno);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 在应用初始化阶段运行(确保系统已就绪) */
|
||||
INIT_APP_EXPORT(init_tmpfs_root);
|
||||
INIT_DEVICE_EXPORT(init_tmpfs_root);
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2025-11-22 Administrator the first version
|
||||
*/
|
||||
#ifndef _FAL_CFG_H_
|
||||
#define _FAL_CFG_H_
|
||||
|
||||
#include <rtconfig.h>
|
||||
#include <fal.h>
|
||||
|
||||
extern struct fal_flash_dev nor_flash0;
|
||||
|
||||
/* flash device table */
|
||||
#define FAL_FLASH_DEV_TABLE \
|
||||
{ \
|
||||
&nor_flash0, \
|
||||
}
|
||||
|
||||
/* 分区表:根据你的需求划分 */
|
||||
#define FAL_PART_TABLE \
|
||||
{ \
|
||||
{FAL_PART_MAGIC_WORD, "sysdata","W25Q128", 0, 16 * 1024 * 1024, 0 }, \
|
||||
}
|
||||
|
||||
#endif /* _FAL_CFG_H_ */
|
||||
Reference in new issue
Block a user