An example program for the S25FL216K flash memory

Dependencies:   S25FL216K_FATFileSystem mbed

Fork of S25FL216K_HelloWorld by Erik -

Revision:
6:d3431822f4a9
Parent:
4:6a2931c19204
--- 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);
     }