Demonstrating bug in fat file system code. Fix is documented at http://mbed.org/forum/mbed/topic/2273/
Dependencies: SDHCFileSystem mbed
Revision 1:eccf128bdde1, committed 2012-01-11
- Comitter:
- davervw
- Date:
- Wed Jan 11 14:54:20 2012 +0000
- Parent:
- 0:227ab928d22c
- Commit message:
Changed in this revision
SDTest_fixed/FATFileSystem.lib | Show diff for this revision Revisions of this file |
SDTest_fixed/main.cpp | Show diff for this revision Revisions of this file |
diff -r 227ab928d22c -r eccf128bdde1 SDTest_fixed/FATFileSystem.lib --- a/SDTest_fixed/FATFileSystem.lib Wed Jan 11 14:53:43 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_unsupported/code/fatfilesystem/ \ No newline at end of file
diff -r 227ab928d22c -r eccf128bdde1 SDTest_fixed/main.cpp --- a/SDTest_fixed/main.cpp Wed Jan 11 14:53:43 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -#include <mbed.h> -#include "SDHCFileSystem.h" - -#define DEBUG_LINE printf("%d\n", __LINE__); - -Serial console(USBTX, USBRX); - -void exitmsg(const char* message, int lineno) -{ - fprintf(stderr, "%s at line# %d\n", message, lineno); - exit(1); -} - -const int buffersize=1024; -char buffer[buffersize]; - -int main() -{ - SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs, mount point - - console.baud(921600); // mbed to pc usb serial supports: 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 230400, 460800, 921600 - - console.puts( - "\x1b[2J\x1b[H" - __FILE__ "\r\n" - __DATE__ " " __TIME__ "\r\n" - "\r\n"); - - remove("/sd/sector.bin"); - FILE* fp = fopen("/sd/sector.bin", "w+"); - - char *p = buffer; - for (unsigned int i=0; i<buffersize/2; ++i) - { - *(p++) = i & 0xFF; - *(p++) = i >> 8; - } - if (fwrite(buffer, sizeof(char), buffersize, fp) != buffersize) - exitmsg("failed to write", __LINE__); - - fseek(fp, 0, SEEK_SET); - if (fread(buffer, sizeof(char), buffersize, fp) != buffersize) - exitmsg("failed to read", __LINE__); - - p = buffer; - for (unsigned int i=0; i<buffersize/2; ++i) - { - unsigned char lo = (*p++); - unsigned char hi = (*p++); - unsigned int value = lo | ((int)hi << 8); - - if (value != i) - { - fprintf(stderr, "expected %d, got %d\n", i, value); - exitmsg("failed", __LINE__); - } - } - - fprintf(stderr, "success\n"); - - fclose(fp); -}