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: mbed SDFileSystem_NUCLEO_32
main.cpp
00001 #include "mbed.h" 00002 #include "SDFileSystem.h" 00003 00004 DigitalIn btn(D2); 00005 RawSerial pc(PA_2, PA_3); 00006 //SDFileSystem sd(D11, D12, D13, D10, "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); // mosi, miso, sclk, name, card detect, sw type, freq 00007 //SDFileSystem sd(PB_15, PB_14, PB_13, D4, "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); // mosi, miso, sclk, CS,name, card detect, sw type, freq 00008 SDFileSystem sd(D11,D12,D13,A0, "sd", NC, SDFileSystem::SWITCH_NONE,10000000); // mosi, miso, sclk, CS,name, card detect, sw type, freq 00009 00010 // trim '\n' 00011 void ntrim(char *str) 00012 { 00013 int i; 00014 for (i = 0; str[i] != 0; ++i); 00015 00016 if (i > 0 && str[i - 1] == '\n') 00017 str[i - 1] = 0; 00018 } 00019 00020 00021 int main() 00022 { 00023 pc.printf("Hello\r\n"); 00024 // SD filesystem 00025 // SDFileSystem *sd = new SDFileSystem(D11, D12, D13, D10, "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); // mosi, miso, sclk, name, card detect, sw type, freq 00026 00027 while (1) 00028 { 00029 // if (btn) continue; 00030 00031 // file open 00032 FILE *fp = fopen("/sd/test.txt", "r"); 00033 if (fp == NULL) 00034 { 00035 printf("open error!!\r\n"); 00036 goto neww; 00037 //while(1); 00038 } 00039 // read text file 00040 char buf[1024]; 00041 while (fgets(buf, sizeof(buf), fp) != NULL) 00042 { 00043 ntrim(buf); 00044 printf("%s\r\n", buf); 00045 } 00046 00047 // file close 00048 fclose(fp); 00049 neww: 00050 fp = fopen("/sd/test.txt", "a"); 00051 fprintf(fp,"test write\n"); 00052 fclose(fp); 00053 while(1); 00054 00055 wait(1); 00056 } 00057 }
Generated on Sat Aug 27 2022 22:31:24 by
1.7.2