RT-Thread ART-Pi 外部SPI Flash分区挂载为U盘
本帖最后由 fsmd 于 2022-4-4 00:14 编辑验证环境
[*]Win10 64位
[*]Keil MDK 5.30
[*]ART-Pi 开发板:STM32H750XBH6开发板
[*]工程:最小RT-Thread 系统,版本:RT-Thread v4.1.0 released
环境搭建
[*]首先需要配置好ART-Pi 外部 16MB SPI Flash 挂载为FatFS 文件系统,文件系统有个12MB的filesystem,用户可以用于存储文件
[*]这里开启USB Device功能,实现USB Mass Storage,winUSB功能
[*]开启USB框架
http://www.pluto-os.com/wp-content/uploads/2022/04/post-64-6249213ad8c3a.png
[*]这里同时使能:Mass Storage Device 与 winusb device
http://www.pluto-os.com/wp-content/uploads/2022/04/post-64-6249213b53d27.png
[*]开启 USB的BSP驱动
http://www.pluto-os.com/wp-content/uploads/2022/04/post-64-6249213bbc11c.png挂载U盘
[*]上面的操作只是开启了USB 设备,编译烧写后,无法挂载到电脑,枚举成U盘
[*]所以需要先取消文件系统的挂载,这样,就可以在电脑端挂载成U盘了
[*]这里增加了挂载为USB U盘的命令 mount_to_usb,开机后,输入命令,电脑过一会,就会出现U盘
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <dfs.h>
#include <dfs_fs.h>
/* defined the LED0 pin: PI8 */
#define LED0_PIN GET_PIN(I, 8)
#ifdef RT_USING_WIFI
extern void wlan_autoconnect_init(void);
#endif
#define FS_PARTITION_NAME"filesystem"
extern int ulog_file_backend_init(void);
void mount_to_usb(void)
{
char *fullpath = NULL;
fullpath = dfs_normalize_path(NULL, "/");
if (dfs_unmount(fullpath) == 0)
{
rt_kprintf("mount_to_usb ok!\n");
}
else
{
rt_kprintf("mount_to_usb fail!\n");
}
}
MSH_CMD_EXPORT(mount_to_usb, mount_to_usb);
void mount_to_flash(void)
{
rt_device_t dev;
dev = rt_device_find(FS_PARTITION_NAME);
if (dev != RT_NULL && dev->open_flag != 0)
{
rt_device_close(dev);
rt_kprintf("close usb device ok!\n");
}
if (dfs_mount(FS_PARTITION_NAME, "/", "elm", 0, 0) == 0)
{
rt_kprintf("mount_to_flash ok!\n");
}
else
{
rt_kprintf("mount_to_flash error!!\n");
}
}
MSH_CMD_EXPORT(mount_to_flash, mount_to_flash);
http://www.pluto-os.com/wp-content/uploads/2022/04/post-64-6249213c36fff.pnghttp://www.pluto-os.com/wp-content/uploads/2022/04/post-64-6249213c90001.png
[*]可以把需要的文件拷贝进去,可以删除里面的文件
http://www.pluto-os.com/wp-content/uploads/2022/04/post-64-6249213cc48ee.png
[*]想把分区挂载回文件系统,让开发板识别文件系统,可以使用命令:mount_to_flash,也可以直接重启,拔掉USB OTG的线即可
小结
[*]实现了电脑与开发板互传文件,如LOG文件、资源文件等
[*]使用RT-Thread USB的框架与USBD 设备驱动,让开发板模拟成U盘,操作很简单
[*]后续可继续深入研究USB的整个框架
页:
[1]