ECE 4180 / Mbed 2 deprecated 4180-L2-P13-SDCardRead

Dependencies:   mbed 4180-L2-P13

Files at this revision

API Documentation at this revision

Comitter:
glanier9
Date:
Tue Mar 09 16:11:35 2021 +0000
Commit message:
Final version

Changed in this revision

SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 0167d43aad96 SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Tue Mar 09 16:11:35 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/ECE-41801234/code/4180-L2-P13/#628e794eb35d
diff -r 000000000000 -r 0167d43aad96 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Mar 09 16:11:35 2021 +0000
@@ -0,0 +1,57 @@
+#include "mbed.h"
+#include "SDFileSystem.h"
+ 
+SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
+Serial          pc(USBTX, USBRX);
+LocalFileSystem chip("uc");\
+ 
+int main() {
+    FILE * pFile;
+    long lSize;
+    char * buffer;
+    size_t result;
+    
+    printf("Hello World!\n");   
+ 
+    mkdir("/sd/mydir", 0777);
+    
+    FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
+    if(fp == NULL) {
+        error("Could not open file for write\n");
+    }
+    fprintf(fp, "Hello SD File World!");
+    fclose(fp); 
+ 
+    printf("Goodbye World!\n");
+    
+    pFile = fopen("/sd/mydir/sdtest.txt", "r"); 
+    if (pFile==NULL) {
+        fputs ("File error",stderr);
+        exit (1);
+    }
+    // obtain file size:
+    fseek (pFile , 0 , SEEK_END);
+    lSize = ftell (pFile);
+    rewind (pFile);
+    pc.printf("File Size: %d\n",lSize);
+    
+    buffer = (char*) malloc (sizeof(char)*lSize);
+    if (buffer == NULL) {
+        fputs ("Memory error",stderr);
+        exit (2);
+    }
+    
+    // copy the file into the buffer:
+    result = fread (buffer,1,lSize,pFile);
+    if (result != lSize) {
+        fputs ("Reading error",stderr);
+        exit (3);
+    }
+    pc.printf("%s",buffer);
+    /* the whole file is now loaded in the memory buffer. */
+    fclose (pFile);
+    free (buffer);
+    return 0;
+    
+    
+}
\ No newline at end of file
diff -r 000000000000 -r 0167d43aad96 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Mar 09 16:11:35 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file