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
Revision 2:4ed4e19338da, committed 2012-11-12
- Comitter:
- okini3939
- Date:
- Mon Nov 12 15:38:55 2012 +0000
- Parent:
- 1:3a2094fa7c4c
- Commit message:
- 1st build
Changed in this revision
diff -r 3a2094fa7c4c -r 4ed4e19338da FatFileSystemCpp.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FatFileSystemCpp.lib Mon Nov 12 15:38:55 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/igorsk/code/FatFileSystemCpp/#88f22c32a456
diff -r 3a2094fa7c4c -r 4ed4e19338da PRAMFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PRAMFileSystem.lib Mon Nov 12 15:38:55 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/okini3939/code/PRAMFileSystem/#475e05403ad8
diff -r 3a2094fa7c4c -r 4ed4e19338da main.cpp --- a/main.cpp Fri Nov 09 06:24:22 2012 +0000 +++ b/main.cpp Mon Nov 12 15:38:55 2012 +0000 @@ -1,154 +1,57 @@ /* - * SPI PRAM NP8P128A13TSM60E (Micron) - * 128Mbit + * Memory File System Library, for SPI PRAM NP8P128A13 (Micron) + * Copyright (c) 2012 Hiroshi Suga + * Released under the MIT License: http://mbed.org/license/mit */ -#include "mbed.h" -#define CMD_WREN 0x06 // Write enable -#define CMD_WRDI 0x04 // Write disable -#define CMD_RDID 0x9f // Read identification -#define CMD_RDSR 0x05 // Read status register -#define CMD_WRSR 0x01 // Write status registe -#define CMD_READ 0x03 // Read data bytes -#define CMD_FREAD 0x0b // Read data bytes at higher speed -#define CMD_PP 0x02 // Page program (legacy program) -#define CMD_PP_BA 0x22 // Page program (bit-alterable write) -#define CMD_PP_1S 0xd1 // Page program (On all 1s) -#define CMD_SE 0xd8 // Sector erase +#include "mbed.h" +#include "PRAMFileSystem.h" DigitalOut myled(LED1); Serial pc(USBTX, USBRX); -SPI spi(p11, p12, p13); // mosi, miso, sclk -DigitalOut cs(p14), hold(p15), reset(p16); - -int ram_status () { - int r; - - cs = 0; - spi.write(CMD_RDSR); - r = spi.write(0); - cs = 1; - return r; -} - -int ram_write (int addr, char *buf, int len) { - int i; - - while (ram_status() & 1) { - // write in progress - } - - cs = 0; - spi.write(CMD_WREN); - cs = 1; - wait_us(10); +PRAMFileSystem mfs(p11, p12, p13, p14, "mfs"); // mosi, miso, sclk, cs +DigitalOut hold(p15), reset(p16); - cs = 0; - spi.write(CMD_PP_BA); - spi.write((addr >> 16) & 0xff); - spi.write((addr >> 8) & 0xff); - spi.write(addr & 0xff); - - len = len - (addr & 0x3f); - for (i = 0; i < len; i ++) { - spi.write(buf[i]); - } - cs = 1; - return i; -} - -int ram_read (int addr, char *buf, int len) { - int i; - - cs = 0; - spi.write(CMD_READ); - spi.write((addr >> 16) & 0xff); - spi.write((addr >> 8) & 0xff); - spi.write(addr & 0xff); - - for (i = 0; i < len; i ++) { - buf[i] = spi.write(0); - } - cs = 1; - return i; -} int main() { - int i, j; + int i; char buf[64]; - Timer t; + DIR *d; + struct dirent *p; + FILE *fp; - cs = 1; hold = 1; reset = 0; pc.baud(115200); - spi.frequency(16000000); wait_ms(10); reset = 1; wait_ms(500); - - cs = 0; - spi.write(CMD_RDID); - printf("RAM Manufacturer ID : %02x\r\n", spi.write(0)); - i = (spi.write(0) << 8) | spi.write(0); - printf("RAM Device ID : %04x\r\n", i); - cs = 1; - wait_ms(10); - printf("Status Register : %02x\r\n", ram_status()); + mfs.format(); - printf("\r\nHELLO test\r\n"); + mkdir("/mfs/test", 0777); - 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 - 6); - - wait(1); - memset(buf, 0, 64); - - printf("RAM read\r\n"); - ram_read(0, buf, 64); - for (i = 0; i < 64; i ++) { - printf(" %02x", buf[i]); - if ((i & 0x0f) == 0x0f) - printf("\r\n"); + fp = fopen("/mfs/hello_world.txt", "w"); + if (fp) { + fputs("Hello PRAM!", fp); + fclose(fp); } - 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("."); + d = opendir("/mfs"); + if (d) { + while (p = readdir(d)) { + printf(" - %s\r\n", p->d_name); + } + } else { + printf("Could not open directory!\n"); } - t.stop(); - printf("\r\ntime %f, %f KBytes/sec\r\n", t.read(), (float)0x1000000 / 1024 / t.read()); + closedir(d); - 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("."); + fp = fopen("/mfs/hello_world.txt", "r"); + if (fp) { + fgets(buf, sizeof(buf), fp); + fclose(fp); + printf("[%s]\r\n", buf); } - t.stop(); - printf("\r\ntime %f, %f KBytes/sec\r\n", t.read(), (float)0x1000000 / 1024 / t.read()); - }