我想实现 RAM 磁盘作为 USB 大容量存储设备,实现 PC 和 STM 开发板之间的数据交互。我使用这个 mbed 工程:https://os.mbed.com/users/va009039/code/F401RE_USBMSD_RAM/
固件可以正常运行,但是 Windows 无法识别开发板为 USB 磁盘。
#define PACKET_SIZE 32
#define blocks_data (1024 * 512)
FATFileSystem fs("fs");
SERIAL setup Serial pc(USBTX, USBRX, 230400);
THREADs Thread ramfs_thread;
void ram_disk_setup() { int connect1 = 0;
/* Size of RAM file system exposed to PC as USB MassStorage */ HeapBlockDevice heap_bd(blocks_data, 512);
MBRBlockDevice::partition(&heap_bd, 1, 0x0b, 0, 512 * 512);
MBRBlockDevice part1(&heap_bd, 1);
RAMFS ramfs1("ram1", &part1);
format with FS FATFileSystem::format(&part1); create FS object and mount FS FATFileSystem fat1("fat", &part1);
USBRAMFS usbmsd1(&ramfs1);
while(true) { if (usbmsd1.connect() && 1 != connect1) { connect1 = 1; printf("Connected to PC - 1\r\n"); }
only try once per second Thread::wait(9000); } }
int main(void) { osStatus err; wait(5);
printf("\r\nUSB Serial done\r\n");
err = ramfs_thread.start(callback(ram_disk_setup)); if (err) { printf("ERROR > send_hid_thread not created\r\n"); } ramfs_thread.join(); }
|
|