Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed FatFileSystemCpp
main.cpp
00001 #include "mbed.h" 00002 #include "MSCFileSystem.h" 00003 //#include <stat.h> 00004 00005 #define FSNAME "msc" 00006 MSCFileSystem msc(FSNAME); 00007 00008 uint8_t myblock[1024]; 00009 00010 00011 int main() 00012 { 00013 DIR *d; 00014 struct dirent *p; 00015 //struct stat st; 00016 //char path[PATH_MAX]; 00017 00018 printf("\r\n================================\r\n"); 00019 printf("USB Mass storage demo program for mbed LPC1768\r\n"); 00020 printf("================================\r\n"); 00021 00022 d = opendir("/" FSNAME); 00023 00024 printf("\r\nList of files on the flash drive:\r\n"); 00025 if ( d != NULL ) 00026 { 00027 while ( (p = readdir(d)) != NULL ) 00028 { 00029 printf(" - %s\r\n", p->d_name); 00030 /* no <stat.h> on mbed, it seems :/ 00031 sprintf(path, "/"FSNAME"/%s", p->d_name); 00032 if ( stat(path, &st) == 0 ) 00033 { 00034 if ( S_ISDIR(st.st_mode) ) 00035 printf(" <directory>\n"); 00036 else 00037 printf(" %d\n", st.st_size); 00038 } 00039 else 00040 { 00041 printf(" ???\n"); 00042 }*/ 00043 } 00044 } 00045 else 00046 { 00047 error("Could not open directory!"); 00048 } 00049 printf("\r\nTesting file write:\r\n"); 00050 FILE *fp = fopen( "/" FSNAME "/msctest.txt", "w"); 00051 if ( fp == NULL ) 00052 { 00053 error("Could not open file for write\r\n"); 00054 } 00055 00056 printf("\r\nWriting 1MB:\r\n"); 00057 for (int mb=0;mb<10;mb++){ 00058 for (int k=0;k<1024;k++){ 00059 fwrite(&myblock, sizeof(myblock), 1, fp); 00060 00061 } 00062 printf("Written %dMB:\r\n",mb); 00063 } 00064 printf("\r\nFinished:\r\n"); 00065 00066 fprintf(fp, "Hello mass storage!"); 00067 fclose(fp); 00068 printf("\n - OK\r\n"); 00069 /* 00070 printf("\nTesting file read:\n"); 00071 fp = fopen( "/" FSNAME "/msctest.txt", "r"); 00072 if ( fp == NULL ) 00073 { 00074 error("Could not open file for read\n"); 00075 } 00076 char buf[256]; 00077 if ( NULL == fgets(buf, sizeof(buf), fp) ) 00078 { 00079 error("Error reading from file\n"); 00080 } 00081 fclose(fp); 00082 printf("\n - OK, read string: '%s'\n\n", buf); 00083 00084 */ 00085 }
Generated on Tue Jul 26 2022 08:01:38 by
