usb
Dependencies: mbed FatFileSystemCpp
main.cpp
- Committer:
- CANGuru
- Date:
- 2021-02-18
- Revision:
- 4:091ef1bde6d6
- Parent:
- 0:e294af8d0e07
File content as of revision 4:091ef1bde6d6:
#include "mbed.h" #include "MSCFileSystem.h" //#include <stat.h> #define FSNAME "msc" MSCFileSystem msc(FSNAME); uint8_t myblock[1024]; int main() { DIR *d; struct dirent *p; //struct stat st; //char path[PATH_MAX]; printf("\r\n================================\r\n"); printf("USB Mass storage demo program for mbed LPC1768\r\n"); printf("================================\r\n"); d = opendir("/" FSNAME); printf("\r\nList of files on the flash drive:\r\n"); if ( d != NULL ) { while ( (p = readdir(d)) != NULL ) { printf(" - %s\r\n", p->d_name); /* no <stat.h> on mbed, it seems :/ sprintf(path, "/"FSNAME"/%s", p->d_name); if ( stat(path, &st) == 0 ) { if ( S_ISDIR(st.st_mode) ) printf(" <directory>\n"); else printf(" %d\n", st.st_size); } else { printf(" ???\n"); }*/ } } else { error("Could not open directory!"); } printf("\r\nTesting file write:\r\n"); FILE *fp = fopen( "/" FSNAME "/msctest.txt", "w"); if ( fp == NULL ) { error("Could not open file for write\r\n"); } printf("\r\nWriting 1MB:\r\n"); for (int mb=0;mb<10;mb++){ for (int k=0;k<1024;k++){ fwrite(&myblock, sizeof(myblock), 1, fp); } printf("Written %dMB:\r\n",mb); } printf("\r\nFinished:\r\n"); fprintf(fp, "Hello mass storage!"); fclose(fp); printf("\n - OK\r\n"); /* printf("\nTesting file read:\n"); fp = fopen( "/" FSNAME "/msctest.txt", "r"); if ( fp == NULL ) { error("Could not open file for read\n"); } char buf[256]; if ( NULL == fgets(buf, sizeof(buf), fp) ) { error("Error reading from file\n"); } fclose(fp); printf("\n - OK, read string: '%s'\n\n", buf); */ }