![](/media/cache/profiles/251bd0442dfcc53b5a761e050f8022b8.50x50_q85.jpg)
Demonstrating bug in fat file system code. Fix is documented at http://mbed.org/forum/mbed/topic/2273/
Dependencies: SDHCFileSystem mbed
main.cpp@0:227ab928d22c, 2012-01-11 (annotated)
- Committer:
- davervw
- Date:
- Wed Jan 11 14:53:43 2012 +0000
- Revision:
- 0:227ab928d22c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
davervw | 0:227ab928d22c | 1 | #include <mbed.h> |
davervw | 0:227ab928d22c | 2 | #include "SDHCFileSystem.h" |
davervw | 0:227ab928d22c | 3 | |
davervw | 0:227ab928d22c | 4 | #define DEBUG_LINE printf("%d\n", __LINE__); |
davervw | 0:227ab928d22c | 5 | |
davervw | 0:227ab928d22c | 6 | Serial console(USBTX, USBRX); |
davervw | 0:227ab928d22c | 7 | |
davervw | 0:227ab928d22c | 8 | void exitmsg(const char* message, int lineno) |
davervw | 0:227ab928d22c | 9 | { |
davervw | 0:227ab928d22c | 10 | fprintf(stderr, "%s at line# %d\n", message, lineno); |
davervw | 0:227ab928d22c | 11 | exit(1); |
davervw | 0:227ab928d22c | 12 | } |
davervw | 0:227ab928d22c | 13 | |
davervw | 0:227ab928d22c | 14 | const int buffersize=1024; |
davervw | 0:227ab928d22c | 15 | char buffer[buffersize]; |
davervw | 0:227ab928d22c | 16 | |
davervw | 0:227ab928d22c | 17 | int main() |
davervw | 0:227ab928d22c | 18 | { |
davervw | 0:227ab928d22c | 19 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs, mount point |
davervw | 0:227ab928d22c | 20 | |
davervw | 0:227ab928d22c | 21 | console.baud(921600); // mbed to pc usb serial supports: 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 230400, 460800, 921600 |
davervw | 0:227ab928d22c | 22 | |
davervw | 0:227ab928d22c | 23 | console.puts( |
davervw | 0:227ab928d22c | 24 | "\x1b[2J\x1b[H" |
davervw | 0:227ab928d22c | 25 | __FILE__ "\r\n" |
davervw | 0:227ab928d22c | 26 | __DATE__ " " __TIME__ "\r\n" |
davervw | 0:227ab928d22c | 27 | "\r\n"); |
davervw | 0:227ab928d22c | 28 | |
davervw | 0:227ab928d22c | 29 | remove("/sd/sector.bin"); |
davervw | 0:227ab928d22c | 30 | FILE* fp = fopen("/sd/sector.bin", "w+"); |
davervw | 0:227ab928d22c | 31 | |
davervw | 0:227ab928d22c | 32 | char *p = buffer; |
davervw | 0:227ab928d22c | 33 | for (unsigned int i=0; i<buffersize/2; ++i) |
davervw | 0:227ab928d22c | 34 | { |
davervw | 0:227ab928d22c | 35 | *(p++) = i & 0xFF; |
davervw | 0:227ab928d22c | 36 | *(p++) = i >> 8; |
davervw | 0:227ab928d22c | 37 | } |
davervw | 0:227ab928d22c | 38 | if (fwrite(buffer, sizeof(char), buffersize, fp) != buffersize) |
davervw | 0:227ab928d22c | 39 | exitmsg("failed to write", __LINE__); |
davervw | 0:227ab928d22c | 40 | |
davervw | 0:227ab928d22c | 41 | fseek(fp, 0, SEEK_SET); |
davervw | 0:227ab928d22c | 42 | if (fread(buffer, sizeof(char), buffersize, fp) != buffersize) |
davervw | 0:227ab928d22c | 43 | exitmsg("failed to read", __LINE__); |
davervw | 0:227ab928d22c | 44 | |
davervw | 0:227ab928d22c | 45 | p = buffer; |
davervw | 0:227ab928d22c | 46 | for (unsigned int i=0; i<buffersize/2; ++i) |
davervw | 0:227ab928d22c | 47 | { |
davervw | 0:227ab928d22c | 48 | unsigned char lo = (*p++); |
davervw | 0:227ab928d22c | 49 | unsigned char hi = (*p++); |
davervw | 0:227ab928d22c | 50 | unsigned int value = lo | ((int)hi << 8); |
davervw | 0:227ab928d22c | 51 | |
davervw | 0:227ab928d22c | 52 | if (value != i) |
davervw | 0:227ab928d22c | 53 | { |
davervw | 0:227ab928d22c | 54 | fprintf(stderr, "expected %d, got %d\n", i, value); |
davervw | 0:227ab928d22c | 55 | exitmsg("failed", __LINE__); |
davervw | 0:227ab928d22c | 56 | } |
davervw | 0:227ab928d22c | 57 | } |
davervw | 0:227ab928d22c | 58 | |
davervw | 0:227ab928d22c | 59 | fprintf(stderr, "success\n"); |
davervw | 0:227ab928d22c | 60 | |
davervw | 0:227ab928d22c | 61 | fclose(fp); |
davervw | 0:227ab928d22c | 62 | } |