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

Revision:
1:3a2094fa7c4c
Parent:
0:4d4598bd9119
Child:
2:4ed4e19338da
--- a/main.cpp	Fri Nov 09 01:57:47 2012 +0000
+++ b/main.cpp	Fri Nov 09 06:24:22 2012 +0000
@@ -1,5 +1,5 @@
 /*
- * SPI RAM NP8P128A13TSM60E (Micron)
+ * SPI PRAM NP8P128A13TSM60E (Micron)
  *   128Mbit
  */
 #include "mbed.h"
@@ -37,7 +37,6 @@
 
     while (ram_status() & 1) {
         // write in progress
-        wait_us(10);
     }
 
     cs = 0;
@@ -51,7 +50,7 @@
     spi.write((addr >> 8) & 0xff);
     spi.write(addr & 0xff);
 
-    len = len - (addr & 0x1f);
+    len = len - (addr & 0x3f);
     for (i = 0; i < len; i ++) {
         spi.write(buf[i]);
     }
@@ -76,13 +75,15 @@
 }
 
 int main() {
-    int i;
+    int i, j;
     char buf[64];
+    Timer t;
 
     cs = 1;
     hold = 1;
     reset = 0;
     pc.baud(115200);
+    spi.frequency(16000000);
     wait_ms(10);
     reset = 1;
     wait_ms(500);
@@ -97,18 +98,20 @@
 
     printf("Status Register : %02x\r\n", ram_status());
 
+    printf("\r\nHELLO test\r\n");
+    
     printf("RAM write\r\n");
     strcpy(buf, "Hello!");
     ram_write(0, buf, 6);
-
+    
     for (i = 0; i < 64; i ++) {
         buf[i] = i;
     }
-    ram_write(6, buf, 64);
+    ram_write(6, buf, 64 - 6);
 
-    wait_ms(500);
+    wait(1);
     memset(buf, 0, 64);
-
+    
     printf("RAM read\r\n");
     ram_read(0, buf, 64);
     for (i = 0; i < 64; i ++) {
@@ -117,10 +120,35 @@
             printf("\r\n");
     }
 
-    while(1) {
-        myled = 1;
-        wait(0.2);
-        myled = 0;
-        wait(0.2);
+    wait(1);
+
+    printf("\r\nWrite/Read time\r\n");
+
+    printf("RAM write\r\n");
+    t.reset();
+    t.start();
+    for (i = 0; i < 0x1000000; i += 64) {
+        buf[0] = (i >> 6) & 0xff;
+        ram_write(i, buf, 64);
+        if ((i & 0x0ffff) == 0) printf(".");
     }
+    t.stop();
+    printf("\r\ntime %f, %f KBytes/sec\r\n", t.read(), (float)0x1000000 / 1024 / t.read());
+
+    wait(1);
+
+    printf("RAM read\r\n");
+    t.reset();
+    t.start();
+    for (i = 0; i < 0x1000000; i += 64) {
+        ram_read(i, buf, 64);
+        if (buf[0] != ((i >> 6) & 0xff)) {
+            printf("error %d\r\n", i);
+            break;
+        }
+        if ((i & 0x0ffff) == 0) printf(".");
+    }
+    t.stop();
+    printf("\r\ntime %f, %f KBytes/sec\r\n", t.read(), (float)0x1000000 / 1024 / t.read());
+
 }