Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
Filesystem
407挂载SD卡的dfs不成功 边做边学习 已完成有模块应用代码
发布于 2018-03-16 10:33:51 浏览:3234
订阅该版
* 本帖最后由 qiousanxi 于 2018-3-20 16:47 编辑 * **使用的是原子的407例程,按照3.01BSP 429的阿波罗修改了,** static struct rt_device sdcard_device; static struct rt_semaphore sd_lock; /* RT-Thread Device Driver Interface */ static rt_err_t rt_sdcard_init(rt_device_t dev) { if (rt_sem_init(&sd_lock, "sdlock", 1, RT_IPC_FLAG_FIFO) != RT_EOK) { rt_kprintf("init sd lock semaphore failed
"); } else rt_kprintf("SD Card init OK
"); return RT_EOK; } static rt_err_t rt_sdcard_open(rt_device_t dev, rt_uint16_t oflag) { return RT_EOK; } static rt_err_t rt_sdcard_close(rt_device_t dev) { return RT_EOK; } static rt_size_t rt_sdcard_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size) { rt_uint8_t status = SD_OK; rt_sem_take(&sd_lock, RT_WAITING_FOREVER); if(((uint32_t)buffer & 0x03) != 0) { /* non-aligned. */ uint32_t i; uint64_t sector_adr; uint8_t* copy_buffer; sector_adr = (uint64_t)pos*SECTOR_SIZE; copy_buffer = (uint8_t*)buffer; for(i = 0; i < size; i++) { SD_ReadBlock(SDIO_DATA_BUFFER,sector_adr + 512*size,512);//单个sector的读操作 memcpy(copy_buffer,SDIO_DATA_BUFFER,512); copy_buffer+=512; } } else { if(size==1) SD_ReadBlock((u8 *)buffer,(uint64_t)pos*SECTOR_SIZE,512); //单个sector的写操作 else SD_ReadMultiBlocks((u8 *)buffer,(uint64_t)pos*SECTOR_SIZE,512,size); //多个sector } rt_sem_release(&sd_lock); if (status == SD_OK) return size; rt_kprintf("read failed: %d, buffer 0x%08x
", status, buffer); return 0; } static rt_size_t rt_sdcard_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size) { rt_uint8_t status = SD_OK; rt_sem_take(&sd_lock, RT_WAITING_FOREVER); if(((uint32_t)buffer & 0x03) != 0) { /* non-aligned. */ uint32_t i; uint64_t sector_adr; uint8_t* copy_buffer; sector_adr = (uint64_t)pos*SECTOR_SIZE; copy_buffer = (uint8_t*)buffer; for(i=0; i
", status, buffer); return 0; } static rt_err_t rt_sdcard_control(rt_device_t dev, int cmd, void *args) { RT_ASSERT(dev != RT_NULL); if (cmd == RT_DEVICE_CTRL_BLK_GETGEOME) { struct rt_device_blk_geometry *geometry; geometry = (struct rt_device_blk_geometry *)args; if (geometry == RT_NULL) return -RT_ERROR; geometry->bytes_per_sector = 512; geometry->block_size = SDCardInfo.CardBlockSize; geometry->sector_count = SDCardInfo.CardCapacity/SDCardInfo.CardBlockSize; } return RT_EOK; } static int rt_hw_sdcard_init(void) { if (SD_Init() == SD_OK) { /* register sdcard device */ sdcard_device.type = RT_Device_Class_Block; sdcard_device.init = rt_sdcard_init; sdcard_device.open = rt_sdcard_open; sdcard_device.close = rt_sdcard_close; sdcard_device.read = rt_sdcard_read; sdcard_device.write = rt_sdcard_write; sdcard_device.control = rt_sdcard_control; /* no private */ sdcard_device.user_data = &SDCardInfo; rt_device_register(&sdcard_device, "sd0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE); return RT_EOK; } rt_kprintf("sdcard init failed
"); return RT_ERROR; } INIT_BOARD_EXPORT(rt_hw_sdcard_init); 启动程序 void rt_init_thread_entry(void *parameter) { #ifdef RT_USING_COMPONENTS_INIT /* initialization RT-Thread Components */ rt_components_init(); #endif #if defined(RT_USING_DFS) && defined(RT_USING_DFS_ELMFAT) if (dfs_mount("sd0", "/dev", "elm", 0, 0) == 0) { rt_kprintf("sd card mount to /dev!
"); } else { rt_kprintf("sd card mount to /dev failed!
"); } #endif /* DFS */ #ifdef RT_USING_FINSH /* init finsh object */ finsh_system_init(); #endif #ifdef RT_USING_MODULE /* init module object */ rt_system_module_init(); #endif } **设备已经有了** \ | / - RT - Thread Operating System / | \ 3.0.3 build Mar 16 2018 2006 - 2018 Copyright by rt-thread team do components intialization. initialize rti_board_end:0 done initialize dfs_init:0 done initialize rt_mmcsd_blk_init:0 done initialize rt_mmcsd_core_init:0 done initialize rt_system_module_init:0 done initialize elm_init:0 done initialize finsh_system_init:0 done sd card mount to /dev failed! finsh />list_device() device type ref count ------ -------------------- ---------- sd0 Block Device 0 uart1 Character Device 2 0, 0x00000000 格式化就会死机 finsh />mkfs("elm","sd0") device_name : sd0 SD Card init OK psr: 0x21000000 pc: 0x080003e8 lr: 0x0800d8d1 r12: 0x00000ff5 r03: 0x00000030 r02: 0x000000ff r01: 0x00000000 r00: 0x00000011 hard fault on thread: shell 请教一下,还需要什么注意的吗????
查看更多
13
个回答
默认排序
按发布时间排序
Tianqf
2018-03-16
这家伙很懒,什么也没写!
挂载没成功啊
qiousanxi
2018-03-16
这家伙很懒,什么也没写!
**设备测试的时候** \ | / - RT - Thread Operating System / | \ 3.0.3 build Mar 16 2018 2006 - 2018 Copyright by rt-thread team do components intialization. initialize rti_board_end:0 done initialize dfs_init:0 done initialize rt_mmcsd_blk_init:0 done initialize rt_mmcsd_core_init:0 done initialize rt_system_module_init:0 done initialize elm_init:0 done initialize finsh_system_init:0 done SD Card init OK block device! device info: sector size : 512 byte sector count : 15564800 block size : 512 byte device R/W test pass! RT_TICK_PER_SECOND:1000 continuous single sector speed test: write: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< write 200 sector from 293 to 1257, 103.73Kbyte/s read : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> read 200 sector from 1262 to 1566, 328.94Kbyte/s random single sector speed test: write: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< write 200 sector from 1575 to 4561, 33.48Kbyte/s read : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> read 200 sector from 4566 to 4862, 337.83Kbyte/s multiple sector speed test write: <<<<<<<<<< multiple write 2 sector speed : 204.8Kbyte/s read : >>>>>>>>>> multiple read 2 sector speed : 588.23Kbyte/s write: <<<<<<<<<< multiple write 4 sector speed : 400.0Kbyte/s read : >>>>>>>>>> multiple read 4 sector speed : 1.22Mbyte/s write: <<<<<<<<<< multiple write 8 sector speed : 677.96Kbyte/s read : >>>>>>>>>> multiple read 8 sector speed : 2.79Mbyte/s write: <<<<<<<<<< multiple write 16 sector speed : 1.73Mbyte/s read : >>>>>>>>>> multiple read 16 sector speed : 4.33Mbyte/s write: <<<<<<<<<< multiple write 32 sector speed : 3.32Mbyte/s read : >>>>>>>>>> multiple read 32 sector speed : 10.41Mbyte/s write: <<<<<<<<<< multiple write 64 sector speed : 6.64Mbyte/s read : >>>>>>>>>> multiple read 64 sector speed : 22.32Mbyte/s write: <<<<<<<<<< multiple write 128 sector speed : 3.63Mbyte/s read : >>>>>>>>>> multiple read 128 sector speed : 44.64Mbyte/s
qiousanxi
2018-03-16
这家伙很懒,什么也没写!
>挂载没成功啊 --- 就是没挂载成功,挂在的时候需要注意什么吗?
qiousanxi
2018-03-16
这家伙很懒,什么也没写!
挂在到'/' 目录**** SD Card init OK sd card mount to /sd! finsh />ls("/") Directory /: sd0 0 uart1 0 0, 0x00000000 finsh /> 但是文件夹的内容看不到
qiousanxi
2018-03-16
这家伙很懒,什么也没写!
#ifdef RT_USING_DFS_DEVFS { extern int devfs_init(void); /* if enable devfs, initialize and mount it as soon as possible */ devfs_init(); dfs_mount(NULL, "/dev", "devfs", 0, 0); } #endif 目前屏蔽了这个宏定义,挂在成功 \ | / - RT - Thread Operating System / | \ 3.0.3 build Mar 16 2018 2006 - 2018 Copyright by rt-thread team SD Card init OK sd card mount to / finsh />ls("/") [ DFS]open file:/ [ DFS]open in filesystem:elm [ DFS]Actual file path: / [ DFS]open successful Directory /: dev
test
123.txt 0 你好.txt 0 0, 0x00000000 finsh />cd dev Unknown symbol finsh />
qiousanxi
2018-03-16
这家伙很懒,什么也没写!
[i=s] 本帖最后由 qiousanxi 于 2018-3-16 15:10 编辑 [/i] DWORD get_fattime(void) 没有做RTC就把这个函数return 0 不然可能会出现half
qiousanxi
2018-03-20
这家伙很懒,什么也没写!
[i=s] 本帖最后由 qiousanxi 于 2018-3-20 17:46 编辑 [/i] 已完成 奉上代码 ,记得吧get_fattime 修改一下
armink
2018-03-20
这家伙很懒,什么也没写!
>#ifdef RT_USING_DFS_DEVFS > { > extern int devfs_init(void); --- ``` #ifdef RT_USING_DFS_DEVFS { extern int devfs_init(void); /* if enable devfs, initialize and mount it as soon as possible */ devfs_init(); dfs_mount(NULL, "/dev", "devfs", 0, 0); } #endif ``` 屏蔽了这个代码就好使了吗? 我看到 ls 是也会有一个 dev 目录,这个不是你自己创建的吧?
qiousanxi
2018-03-22
这家伙很懒,什么也没写!
[i=s] 本帖最后由 qiousanxi 于 2018-3-22 13:59 编辑 [/i] >屏蔽了这个代码就好使了吗? >我看到 ls 是也会有一个 dev 目录,这个不是你自己创建的吧? ... --- 没有创建,我把这屏蔽了,之前是 带这个东西,目录一直在devfs目录里面
aureoleday
2018-04-03
这家伙很懒,什么也没写!
>没有创建,我把这屏蔽了,之前是 带这个东西,目录一直在devfs目录里面 --- 你好,你的工程帮我大忙了,刚好在调SD的驱动 目前用你的工程能实现SD卡的读写和测速,但是也出现了你的情况 \ | / - RT - Thread Operating System / | \ 3.0.3 build Apr 2 2018 2006 - 2018 Copyright by rt-thread team SD Card init OK sd card mount to / failed! finsh />devi --function: device_test -- e.g: device_test("sd0") finsh />device_test("sd0") block device! device info: sector size : 512 byte sector count : 15273984 block size : 512 byte device R/W test pass! RT_TICK_PER_SECOND:1000 continuous single sector speed test: write: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< write 200 sector from 11002 to 12253, 79.93Kbyte/s read : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> read 200 sector from 12259 to 12386, 787.40Kbyte/s random single sector speed test: write: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< write 200 sector from 12394 to 13763, 73.4Kbyte/s read : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> read 200 sector from 13768 to 13897, 775.19Kbyte/s multiple sector speed test write: <<<<<<<<<< multiple write 2 sector speed : 64.93Kbyte/s read : >>>>>>>>>> multiple read 2 sector speed : 1.39Mbyte/s write: <<<<<<<<<< multiple write 4 sector speed : 487.80Kbyte/s read : >>>>>>>>>> multiple read 4 sector speed : 2.79Mbyte/s write: <<<<<<<<<< multiple write 8 sector speed : 930.23Kbyte/s read : >>>>>>>>>> multiple read 8 sector speed : 4.88Mbyte/s write: <<<<<<<<<< multiple write 16 sector speed : 484.84Kbyte/s read : >>>>>>>>>> multiple read 16 sector speed : 6.50Mbyte/s write: <<<<<<<<<< multiple write 32 sector speed : 935.67Kbyte/s read : >>>>>>>>>> multiple read 32 sector speed : 8.22Mbyte/s write: <<<<<<<<<< multiple write 64 sector speed : 5.78Mbyte/s read : >>>>>>>>>> multiple read 64 sector speed : 9.76Mbyte/s write: <<<<<<<<<< multiple write 128 sector speed : 7.35Mbyte/s read : >>>>>>>>>> multiple read 128 sector speed : 10.41Mbyte/s 即使把#ifdef RT_USING_DFS_DEVFS那段屏蔽了也没用,还有什么招么?
撰写答案
登录
注册新账号
关注者
0
被浏览
3.2k
关于作者
qiousanxi
这家伙很懒,什么也没写!
提问
4
回答
27
被采纳
0
关注TA
发私信
相关问题
1
字库除了SD卡和http还有别的方式导入吗
2
如何同时使用RTT文件系统于NAND Flash 和 SD卡,针对Realboard4088?
3
EasyFlash好棒
4
SD卡挂在的SPI总线又要加个DA设备
5
sd卡与flash 同时挂载 挂载路径shell怎么区分 访问
6
请教ramfs使用方法
7
rtt stable2.0.x版本 sd卡及文件系统
8
nandflash文件系统UFFS请教
9
关于SD卡挂载文件系统的问题(已解决)
10
Yaffs采用GPL2许可
推荐文章
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
rt-thread使用cherryusb实现虚拟串口
2
《C++20 图形界面程序:速度与渲染效率的双重优化秘籍》
3
《原子操作:程序世界里的“最小魔法单位”解析》
4
《C++设计模式:重塑游戏角色系统类结构的秘籍》
5
rt-thread官方usb驱动之虚拟串口
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
ART-Pi
FinSH
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
rt_mq_消息队列_msg_queue
keil_MDK
at_device
ulog
C++_cpp
本月问答贡献
踩姑娘的小蘑菇
6
个答案
3
次被采纳
张世争
8
个答案
2
次被采纳
rv666
5
个答案
2
次被采纳
用户名由3_15位
11
个答案
1
次被采纳
KunYi
6
个答案
1
次被采纳
本月文章贡献
出出啊
1
篇文章
2
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
1
篇文章
1
次点赞
crystal266
2
篇文章
2
次点赞
whj467467222
2
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部