SDFileSystem Library Test for Nucleo F401RE

Dependencies:   SDFileSystem mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002  * SDFileSystem Test
00003  * 
00004  * Library
00005  * SDFileSystem: https://developer.mbed.org/users/neilt6/code/SDFileSystem/ Revision:26
00006  * mbed: Revision: 124
00007  *
00008  * 2016.11.22 created
00009  *
00010  */
00011 
00012 #include "mbed.h"
00013 #include "SDFileSystem.h"
00014 
00015 //Create an SDFileSystem object
00016 SDFileSystem sd(D11, D12, D13, D10, "sd");
00017 
00018 int main()
00019 {
00020     //Mount the filesystem
00021     sd.mount();
00022 
00023     //Perform a write test
00024     printf("\nWriting to SD card...");
00025     FILE *fp = fopen("/sd/sdtest.txt", "w");
00026     if (fp != NULL) {
00027         fprintf(fp, "We're writing to an SD card!");
00028         fclose(fp);
00029         printf("success!\n");
00030     } else {
00031         printf("failed!\n");
00032     }
00033 
00034     //Perform a read test
00035     printf("Reading from SD card...");
00036     fp = fopen("/sd/sdtest.txt", "r");
00037     if (fp != NULL) {
00038         char c = fgetc(fp);
00039         if (c == 'W')
00040             printf("success!\n");
00041         else
00042             printf("incorrect char (%c)!\n", c);
00043         fclose(fp);
00044     } else {
00045         printf("failed!\n");
00046     }
00047 
00048     //Unmount the filesystem
00049     sd.unmount();
00050 }