sample of Memory File System Library, for SPI PRAM NP8P128A13 (Micron) see: http://mbed.org/users/okini3939/notebook/extend-memory/

Dependencies:   FatFileSystemCpp PRAMFileSystem mbed

Fork of SPIRAM_NP8P128A13TSM60E by Suga koubou

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002  * Memory File System Library, for SPI PRAM NP8P128A13 (Micron)
00003  * Copyright (c) 2012 Hiroshi Suga
00004  * Released under the MIT License: http://mbed.org/license/mit
00005  */
00006 
00007 #include "mbed.h"
00008 #include "PRAMFileSystem.h"
00009 
00010 DigitalOut myled(LED1);
00011 Serial pc(USBTX, USBRX);
00012 
00013 PRAMFileSystem mfs(p11, p12, p13, p14, "mfs"); // mosi, miso, sclk, cs
00014 DigitalOut hold(p15), reset(p16);
00015 
00016 
00017 int main() {
00018     int i;
00019     char buf[64];
00020     DIR *d;
00021     struct dirent *p;
00022     FILE *fp;
00023 
00024     hold = 1;
00025     reset = 0;
00026     pc.baud(115200);
00027     wait_ms(10);
00028     reset = 1;
00029     wait_ms(500);
00030 
00031     mfs.format();
00032 
00033     mkdir("/mfs/test", 0777);
00034     
00035     fp = fopen("/mfs/hello_world.txt", "w");
00036     if (fp) {
00037         fputs("Hello PRAM!", fp);
00038         fclose(fp);
00039     }
00040 
00041     d = opendir("/mfs");
00042     if (d) {
00043         while (p = readdir(d)) {
00044             printf(" - %s\r\n", p->d_name);
00045         }
00046     } else {
00047         printf("Could not open directory!\n");
00048     }
00049     closedir(d);
00050 
00051     fp = fopen("/mfs/hello_world.txt", "r");
00052     if (fp) {
00053         fgets(buf, sizeof(buf), fp);
00054         fclose(fp);
00055         printf("[%s]\r\n", buf);
00056     }
00057 }