Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
文件系统
mkfs_格式化文件系统
dfs_mkfs() 调用format error
发布于 2021-02-28 21:55:46 浏览:1402
订阅该版
背景: 外挂SPI flash,W25Q256,SFUD/FAL都没啥问题,具体见启动打印: ``` \ | / - RT - Thread Operating System / | \ 3.1.4 build Feb 28 2021 2006 - 2019 Copyright by rt-thread team rt_hw_spi_device_attach succ! [SFUD] Find a Winbond flash chip. Size is 33554432 bytes. [SFUD] W25Q256 flash device is initialize success. [D/FAL] (fal_flash_init:61) Flash device | W25Q256 | addr: 0x00000000 | len: 0x02000000 | blk_size: 0x00001000 |initialized finish. [21:32:45.476] [32;22m[I/FAL] ==================== FAL partition table ====================[0m [32;22m[I/FAL] | name | flash_dev | offset | length |[0m [32;22m[I/FAL] -------------------------------------------------------------[0m [32;22m[I/FAL] | easyflash | W25Q256 | 0x00000000 | 0x00200000 |[0m [32;22m[I/FAL] | download | W25Q256 | 0x00200000 | 0x02000000 |[0m [32;22m[I/FAL] =============================================================[0m [32;22m[I/FAL] RT-Thread Flash Abstraction Layer (V0.5.0) initialize success.[0m ROMFS File System initialized! [32;22m[I/FAL] The FAL MTD NOR device (download) created successfully[0m format error mkfs failed! msh />device type ref count -------- -------------------- ---------- download MTD Device 0 W25Q256 Block Device 0 spi10 SPI Device 0 spi1 SPI Bus 0 uart3 Character Device 2 pin Miscellaneous Device 0 挂载DFS的时候先mkfs,发现在dfs_elm_mkfs()中调用f_mkfs()的时候出错了,返回(0x01 FR_DISK_ERR,A hard error occurred in the low level disk I/O layer) ``` 操作代码如下: ```c int rt_hw_spi_flash_init(void) { int ret; __HAL_RCC_GPIOA_CLK_ENABLE(); ret = rt_hw_spi_device_attach("spi1", "spi10", GPIOA, GPIO_PIN_4); if (ret != RT_EOK) { rt_kprintf("rt_hw_spi_device_attach failed! \n"); return ret; } else { rt_kprintf("rt_hw_spi_device_attach succ! \n"); } if (RT_NULL == rt_sfud_flash_probe("W25Q256", "spi10")) { rt_kprintf("rt_sfud_flash_probe failed! \n"); return -RT_ERROR; } fal_init(); return RT_EOK; } int mount_init(void) { struct rt_device *flash_dev = RT_NULL; /* mount ROMFS as root directory */ if (dfs_mount(RT_NULL, "/", "rom", 0, (const void *)DFS_ROMFS_ROOT) == 0) { rt_kprintf("ROMFS File System initialized!\n"); } else { rt_kprintf("ROMFS File System initialized Failed!\n"); } flash_dev = fal_mtd_nor_device_create("download"); if (flash_dev) { // mkfs firstly if (dfs_mkfs("elm", "download") != 0) { rt_kprintf("mkfs failed! \n"); return 1; } //mount filesystem if (dfs_mount("download", "/flash", "elm", 0, 0) != 0) { rt_kprintf("mount to '/flash' failed! \n"); return 1; } else { rt_kprintf("mount to '/flash' success! \n"); } } else { rt_kprintf("Can't create block device \n"); } return RT_EOK; } INIT_APP_EXPORT(mount_init); ``` 问题: 因为f_mkfs的具体实现没找到,如果如描述的`low level disk I/O layer error`的话,为什么FAL启动的时候不提示错误?设备的r/w等函数都是`SFUD/FAL`自带的,不大可能唯独我的代码出错啊~
查看更多
whj467467222
认证专家
2021-03-01
开源,分享,交流,共同进步
看样子你是想对 FLASH 进行分区,然后挂载文件系统。 这个代码在 **ART-Pi** 的 SDK 拷贝出来的,验证通过的,你可以自己去下载一份看看其他的配置。 参考一下这个的实现吧. ```c /* * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2018-12-13 balanceTWK add sdcard port file * 2019-06-11 WillianChan Add SD card hot plug detection */ #include
#ifdef BSP_USING_FS #if DFS_FILESYSTEMS_MAX < 4 #error "Please define DFS_FILESYSTEMS_MAX more than 4" #endif #if DFS_FILESYSTEM_TYPES_MAX < 4 #error "Please define DFS_FILESYSTEM_TYPES_MAX more than 4" #endif #ifdef BSP_USING_SPI_FLASH_FS #include "fal.h" #endif #include
#include "dfs_romfs.h" #include "drv_sdio.h" #define DBG_TAG "app.filesystem" #define DBG_LVL DBG_INFO #include
static const struct romfs_dirent _romfs_root[] = { {ROMFS_DIRENT_DIR, "flash", RT_NULL, 0}, {ROMFS_DIRENT_DIR, "sdcard", RT_NULL, 0}}; const struct romfs_dirent romfs_root = { ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root) / sizeof(_romfs_root[0])}; #ifdef BSP_USING_SDCARD_FS /* SD Card hot plug detection pin */ #define SD_CHECK_PIN GET_PIN(D, 5) static void _sdcard_mount(void) { rt_device_t device; device = rt_device_find("sd0"); if (device == NULL) { mmcsd_wait_cd_changed(0); sdcard_change(); mmcsd_wait_cd_changed(RT_WAITING_FOREVER); device = rt_device_find("sd0"); } if (device != RT_NULL) { if (dfs_mount("sd0", "/sdcard", "elm", 0, 0) == RT_EOK) { LOG_I("sd card mount to '/sdcard'"); } else { LOG_W("sd card mount to '/sdcard' failed!"); } } } static void _sdcard_unmount(void) { rt_thread_mdelay(200); dfs_unmount("/sdcard"); LOG_I("Unmount \"/sdcard\""); mmcsd_wait_cd_changed(0); sdcard_change(); mmcsd_wait_cd_changed(RT_WAITING_FOREVER); } static void sd_mount(void *parameter) { rt_uint8_t re_sd_check_pin = 1; rt_thread_mdelay(200); if (rt_pin_read(SD_CHECK_PIN)) { _sdcard_mount(); } while (1) { rt_thread_mdelay(200); if (!re_sd_check_pin && (re_sd_check_pin = rt_pin_read(SD_CHECK_PIN)) != 0) { _sdcard_mount(); } if (re_sd_check_pin && (re_sd_check_pin = rt_pin_read(SD_CHECK_PIN)) == 0) { _sdcard_unmount(); } } } #endif /* BSP_USING_SDCARD_FS */ int mount_init(void) { if (dfs_mount(RT_NULL, "/", "rom", 0, &(romfs_root)) != 0) { LOG_E("rom mount to '/' failed!"); } #ifdef BSP_USING_SPI_FLASH_FS struct rt_device *flash_dev = RT_NULL; #ifndef RT_USING_WIFI fal_init(); #endif flash_dev = fal_mtd_nor_device_create("filesystem"); if (flash_dev) { //mount filesystem if (dfs_mount(flash_dev->parent.name, "/flash", "lfs", 0, 0) != 0) { LOG_W("mount to '/flash' failed! try to mkfs %s", flash_dev->parent.name); dfs_mkfs("lfs", flash_dev->parent.name); if (dfs_mount(flash_dev->parent.name, "/flash", "lfs", 0, 0) == 0) { LOG_I("mount to '/flash' success!"); } } else { LOG_I("mount to '/flash' success!"); } } else { LOG_E("Can't create block device filesystem or bt_image partition."); } #endif #ifdef BSP_USING_SDCARD_FS rt_thread_t tid; rt_pin_mode(SD_CHECK_PIN, PIN_MODE_INPUT_PULLUP); tid = rt_thread_create("sd_mount", sd_mount, RT_NULL, 2048, RT_THREAD_PRIORITY_MAX - 2, 20); if (tid != RT_NULL) { rt_thread_startup(tid); } else { LOG_E("create sd_mount thread err!"); } #endif return RT_EOK; } INIT_APP_EXPORT(mount_init); #endif /* BSP_USING_FS */ ```
2
个回答
默认排序
按发布时间排序
Juggernaut
2021-02-28
①②③
跟进`f_mkfs()`,`stat = disk_initialize(pdrv);`这个返回0是正常,第一次调用`disk_ioctl()`返回的时候`sz_blk`的值为1,第2次调用`disk_ioctl()`返回的时候ss的值为0; ```c /* Check physical drive status */ stat = disk_initialize(pdrv); if (stat & STA_NOINIT) return FR_NOT_READY; if (stat & STA_PROTECT) return FR_WRITE_PROTECTED; if (disk_ioctl(pdrv, GET_BLOCK_SIZE, &sz_blk) != RES_OK || !sz_blk || sz_blk > 32768 || (sz_blk & (sz_blk - 1))) sz_blk = 1; /* Erase block to align data area */ #if _MAX_SS != _MIN_SS /* Get sector size of the medium */ if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &ss) != RES_OK) return FR_DISK_ERR; if (ss > _MAX_SS || ss < _MIN_SS || (ss & (ss - 1))) return FR_DISK_ERR; ``` 跟进去看了下,在`disk_ioctl()`函数执行如下代码的时候`geometry`没有拿到数据~ SFUD/FAL的大神能否帮忙看看 ```c else if (ctrl == GET_SECTOR_SIZE) { struct rt_device_blk_geometry geometry; rt_memset(&geometry, 0, sizeof(geometry)); rt_device_control(device, RT_DEVICE_CTRL_BLK_GETGEOME, &geometry); *(WORD *)buff = (WORD)(geometry.bytes_per_sector); } ```
撰写答案
登录
注册新账号
关注者
0
被浏览
1.4k
关于作者
Juggernaut
①②③
提问
15
回答
109
被采纳
6
关注TA
发私信
相关问题
1
【文件系统】目录查询
2
文件系统Posix 接口 的close API疑问
3
dfs_mount挂载文件系统路径的路径必须为‘/’才能成功
4
SD卡连续读写文件报错
5
文件系统挂载断言机制
6
文件系统是否支持挂载NFS网络文件系统
7
文件系统挂载失败!!!
8
dfs_filesystem_lookup() 返回NULL
9
webnet 是否可以做全动态网页,使用内存池来加快速度
10
“文件系统装在表”报错
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
使用百度AI助手辅助编写一个rt-thread下的ONVIF设备发现功能的功能代码
2
RT-Thread 发布 EtherKit开源以太网硬件!
3
rt-thread使用cherryusb实现虚拟串口
4
《C++20 图形界面程序:速度与渲染效率的双重优化秘籍》
5
《原子操作:程序世界里的“最小魔法单位”解析》
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
WIZnet_W5500
ota在线升级
UART
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
keil_MDK
rt_mq_消息队列_msg_queue
at_device
ulog
C++_cpp
本月问答贡献
踩姑娘的小蘑菇
7
个答案
3
次被采纳
张世争
8
个答案
2
次被采纳
rv666
5
个答案
2
次被采纳
用户名由3_15位
11
个答案
1
次被采纳
KunYi
6
个答案
1
次被采纳
本月文章贡献
程序员阿伟
5
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
大龄码农
1
篇文章
2
次点赞
ThinkCode
1
篇文章
1
次点赞
Betrayer
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部