完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
void rt_hw_spiflash_init(void)
{ rt_uint32_t n; rt_uint8_t* sector; spi_flash.type = RT_Device_Class_Block; spi_flash.init = rt_spiflash_init; spi_flash.open = rt_spiflash_open; spi_flash.close = rt_spiflash_close; spi_flash.read = rt_spiflash_read; spi_flash.write = rt_spiflash_write; spi_flash.control = rt_spiflash_control; spi_flash.private = RT_NULL; at45db_SetPageSize(); // 设置为512字节模式 /* get the first sector to read partition table */ sector = (rt_uint8_t*) rt_malloc (512); if (sector == RT_NULL) { rt_kprintf("allocate partition sector buffer failedn"); return; } n = rt_spiflash_read((rt_device_t)&spi_flash, 0, sector, 512); if (n == 512) { rt_err_t status; /* get the first partition */ status = dfs_filesystem_get_partition(&spi_flash_part, sector, 0); if (status != RT_EOK) { /* there is no partition table */ spi_flash_part.offset = 0; spi_flash_part.size = 0; } } else { /* there is no partition table */ spi_flash_part.offset = 0; spi_flash_part.size = 0; } /* release sector buffer */ rt_free(sector); /* register sd device */ rt_device_register(&spi_flash, "spi0", RT_DEVICE_FLAG_RDWR); } 这个成功了,运行结果: finsh>>list_device() device type -------- ---------- spi0 Block Device sd0 Block Device uart1 Character Device 0, 0x00000000 然后dfs_mount("spi0", "/", "elm", 0, 0) 就不成功,是因为flash没有格式化? 如果要在系统内对flash进行格式化,要怎样操作咧? |
|
相关推荐
3个回答
|
|
elm_fat 在 mount时,并没检查目标的有效性。请检查你的DFS和ELM_FS是否已经初始化。
需要格式化,可以使用mkfs("spi0") 可以参考RADIO中的代码。 |
|
|
|
已经在stm32radio中找到了mkfs的方法。
在dfs_elm.c中实现DRESULT disk_ioctl (BYTE drv, BYTE ctrl, void *buff)函数, 然后完成下面的代码,就可以在finsh中使用mkfs命令了 [s:175] /* ELM format function */ int mkfs(const char* device) { BYTE drv; rt_device_t dev; FRESULT result; /* find device name */ for (drv = 0; drv < _DRIVES; drv ++) { dev = disk[drv]; if (rt_strncmp(dev->parent.name, device, RT_NAME_MAX) == 0) { /* Partitioning rule 0:FDISK */ /* Auto selection of cluster size */ result = f_mkfs(drv, 0, 0); if ( result != FR_OK) { rt_kprintf("format errorn"); return elm_result_to_dfs(result); } return DFS_STATUS_OK; } } /* can't find device driver */ rt_kprintf("can not find device driver: %sn", device); return -DFS_STATUS_EIO; } #ifdef RT_USING_FINSH #include FINSH_FUNCTION_EXPORT(mkfs, make filesystem on disk); #endif 但是有个很奇怪的问题,在dfs_mount文件系统时,这样写就会不停发生异常: dfs_init(); elm_init(); if (dfs_mount("sd0", "/", "elm", 0, 0) == 0) { rt_kprintf("SD File System initialized!n"); if (dfs_mount("spi0", "/SPI", "elm", 0, 0) ==0 ) rt_kprintf("SPI File System initialized!n"); else rt_kprintf("SPI File System init failed!n"); } else rt_kprintf("SD File System init failed!n"); 这样写就不会发生: dfs_init(); elm_init(); if (dfs_mount("sd0", "/", "elm", 0, 0) == 0) rt_kprintf("SD File System initialized!n"); else rt_kprintf("SD File System init failed!n"); if (dfs_mount("spi0", "/SPI", "elm", 0, 0) ==0 ) rt_kprintf("SPI File System initialized!n"); else rt_kprintf("SPI File System init failed!n"); |
|
|
|
怀疑你堆栈溢出。因为上面那样写多一级调用。
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
830 浏览 0 评论
AI模型部署边缘设备的奇妙之旅:如何在边缘端部署OpenCV
2916 浏览 0 评论
tms320280021 adc采样波形,为什么adc采样频率上来波形就不好了?
1391 浏览 0 评论
2006 浏览 0 评论
1553 浏览 0 评论
75096 浏览 21 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-26 05:50 , Processed in 0.591628 second(s), Total 74, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号