Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDHCFileSystem mbed
main.cpp
00001 #include <mbed.h> 00002 #include "SDHCFileSystem.h" 00003 00004 #define DEBUG_LINE printf("%d\n", __LINE__); 00005 00006 Serial console(USBTX, USBRX); 00007 00008 void exitmsg(const char* message, int lineno) 00009 { 00010 fprintf(stderr, "%s at line# %d\n", message, lineno); 00011 exit(1); 00012 } 00013 00014 const int buffersize=1024; 00015 char buffer[buffersize]; 00016 00017 int main() 00018 { 00019 SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs, mount point 00020 00021 console.baud(921600); // mbed to pc usb serial supports: 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 230400, 460800, 921600 00022 00023 console.puts( 00024 "\x1b[2J\x1b[H" 00025 __FILE__ "\r\n" 00026 __DATE__ " " __TIME__ "\r\n" 00027 "\r\n"); 00028 00029 remove("/sd/sector.bin"); 00030 FILE* fp = fopen("/sd/sector.bin", "w+"); 00031 00032 char *p = buffer; 00033 for (unsigned int i=0; i<buffersize/2; ++i) 00034 { 00035 *(p++) = i & 0xFF; 00036 *(p++) = i >> 8; 00037 } 00038 if (fwrite(buffer, sizeof(char), buffersize, fp) != buffersize) 00039 exitmsg("failed to write", __LINE__); 00040 00041 fseek(fp, 0, SEEK_SET); 00042 if (fread(buffer, sizeof(char), buffersize, fp) != buffersize) 00043 exitmsg("failed to read", __LINE__); 00044 00045 p = buffer; 00046 for (unsigned int i=0; i<buffersize/2; ++i) 00047 { 00048 unsigned char lo = (*p++); 00049 unsigned char hi = (*p++); 00050 unsigned int value = lo | ((int)hi << 8); 00051 00052 if (value != i) 00053 { 00054 fprintf(stderr, "expected %d, got %d\n", i, value); 00055 exitmsg("failed", __LINE__); 00056 } 00057 } 00058 00059 fprintf(stderr, "success\n"); 00060 00061 fclose(fp); 00062 }
Generated on Sat Jul 16 2022 07:57:52 by
1.7.2