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: SDFileSystem mbed
Fork of Nucleo_Ex05_SD by
Diff: main.cpp
- Revision:
- 0:b0a3ecd53c7d
- Child:
- 1:d65338ce2e7c
diff -r 000000000000 -r b0a3ecd53c7d main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Mar 21 08:58:22 2016 +0000
@@ -0,0 +1,46 @@
+#include "mbed.h"
+#include "SDFileSystem.h"
+
+DigitalIn btn(USER_BUTTON);
+
+// trim '\n'
+void ntrim(char *str)
+{
+ int i;
+ for (i = 0; str[i] != 0; ++i);
+
+ if (i > 0 && str[i - 1] == '\n')
+ str[i - 1] = 0;
+}
+
+int main()
+{
+ // SD filesystem
+ SDFileSystem *sd = new SDFileSystem(PB_15, PB_14, PB_13, PA_9, "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); // mosi, miso, sclk, name, card detect, sw type, freq
+
+ while (1)
+ {
+ if (btn) continue;
+
+ // file open
+ FILE *fp = fopen("/sd/test.txt", "r");
+ if (fp == NULL)
+ {
+ printf("open error!!\r\n");
+ while(1);
+ }
+
+ // read text file
+ char buf[1024];
+ while (fgets(buf, sizeof(buf), fp) != NULL)
+ {
+ ntrim(buf);
+ printf("%s\r\n", buf);
+ }
+
+ // file close
+ fclose(fp);
+
+ wait(1);
+ }
+}
