An example program for the S25FL216K flash memory

Dependencies:   S25FL216K_FATFileSystem mbed

Fork of S25FL216K_HelloWorld by Erik -

Files at this revision

API Documentation at this revision

Comitter:
mkilivan
Date:
Tue Dec 23 21:41:08 2014 +0000
Parent:
5:1a2c6c946686
Commit message:
tidy up and update library path

Changed in this revision

S25FL216K_FATFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
S25FL216K_USBFileSystem.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 1a2c6c946686 -r d3431822f4a9 S25FL216K_FATFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/S25FL216K_FATFileSystem.lib	Tue Dec 23 21:41:08 2014 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mkilivan/code/S25FL216K_FATFileSystem/#3303a45c8980
diff -r 1a2c6c946686 -r d3431822f4a9 S25FL216K_USBFileSystem.lib
--- a/S25FL216K_USBFileSystem.lib	Fri Dec 19 14:45:49 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/mkilivan/code/S25FL216K_USBFileSystem/#2642d0729f55
diff -r 1a2c6c946686 -r d3431822f4a9 main.cpp
--- a/main.cpp	Fri Dec 19 14:45:49 2014 +0000
+++ b/main.cpp	Tue Dec 23 21:41:08 2014 +0000
@@ -1,17 +1,30 @@
 #include "mbed.h"
-#include "Flash_USBFileSystem.h"
+#include "Flash_FileSystem.h"
 
-DigitalOut myled(LED1);
-//FlashUSB flash(PTD6, PTD7, PTB11, PTE4);
-FlashUSB flash(P0_9, P0_8, P0_7, P0_6);
-
+FlashSPI flash(P0_9, P0_8, P0_7, P0_6, "flash");
 
 int main()
 {
     wait(0.1);
     printf("Hello World!\r\n");
+    char buffer[100];
+    FILE *fp;
 
-    FILE *fp = fopen("/USB/in1.txt", "w");
+    int i;
+    
+    printf("directory list\r\n");
+    DIR *d = opendir("/flash");               // Opens the root directory of the local file system
+    struct dirent *p;
+    i = 0;
+    while((p = readdir(d)) != NULL) {         // Print the names of the files in the local file system
+        printf("%s\r\n", p->d_name);          // to stdout.
+        i++;
+    }
+    closedir(d);
+    printf("total %d files found.\r\n\n", i);
+    
+    fp = fopen("/flash/in1.txt", "a");
+    printf("-0-\r\n");
 
     if(fp == NULL) {
         printf("Could not open file, assuming unformatted disk!\r\n");
@@ -22,15 +35,42 @@
         while(1);
     } else {
         wait(0.2);
-        fprintf(fp, "Type your text here!");
+        fprintf(fp, "hello ");
+        fclose(fp);
+    }
+    
+    wait(0.5);
+        
+    fp = fopen("/flash/in2.txt", "a");
+    if (fp == NULL) {
+        printf("out.txt can't created.\r\n");
+    } else {
+        wait(0.2);
+        fprintf(fp, "Hello 2 ");
         fclose(fp);
     }
     
-    fp = fopen("/USB/in2.txt", "w");
+    wait(0.5);
+    
+    fp = fopen("/flash/in1.txt", "r");
     if (fp == NULL) {
-        printf("out.txt can't created.\r\n");
-    } else {
-        fprintf(fp, "Hello World!\r\n");
+        printf("in1.txt can't open to read.\r\n");
+    } else
+    {
+        fgets (buffer, 100, fp);
+        printf("%s\r\n", buffer);
+        fclose(fp);
+    }
+
+    wait(0.5);
+       
+    fp = fopen("/flash/in2.txt", "r");
+    if (fp == NULL) {
+        printf("in2.txt can't open to read.\r\n");
+    } else
+    {
+        fgets (buffer, 100, fp);
+        printf("%s\r\n", buffer);
         fclose(fp);
     }
 
diff -r 1a2c6c946686 -r d3431822f4a9 mbed.lib
--- a/mbed.lib	Fri Dec 19 14:45:49 2014 +0000
+++ b/mbed.lib	Tue Dec 23 21:41:08 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/#673126e12c73
+http://mbed.org/users/mbed_official/code/mbed/#4fc01daae5a5