A filesystem for accessing the local mbed Microcontroller USB disk drive.
This allows programs to read and write files on the same disk drive that is used to program the mbed Microcontroller. Once created, the standard C file access functions are used to open, read and write files.
#include "mbed.h"
LocalFileSystem local("local"); // Create the local filesystem under the name "local"
int main() {
FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
fprintf(fp, "Hello World!");
fclose(fp);
}
If the microcontroller program opens a file on the local drive, it will be marked as “removed” on the Host computer. This means it is no longer accessible from the Host Computer.
The drive will only re-appear when file handles are closed, or the microcontroller program exits. Note that if the program does not exit or release the handles, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
Here is an example program that shows the behaviour clearly:
#include "mbed.h"
LocalFileSystem local("local");
int main() {
printf("Hello World!\n");
wait(5.0);
printf("Opening File...\n"); // Drive should be marked as removed
FILE *fp = fopen("/local/test.txt", "w");
if(!fp) {
fprintf(stderr, "File /local/test.txt could not be opened!\n");
exit(1);
}
wait(5.0);
printf("Writing Data...\n");
fprintf(fp, "Hello World!");
wait(5.0);
printf("Closing File...\n");
fclose(fp);
// Drive should be restored. this is the same as just returning from main
wait(5);
}
Ensure you have the latest Firmware when using this feature!