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
Revision 1:e8699d7ca61a, committed 2018-04-12
- Comitter:
- hudakz
- Date:
- Thu Apr 12 17:35:57 2018 +0000
- Parent:
- 0:4457b60e87c8
- Child:
- 2:cb349fd2a36a
- Commit message:
- Updated.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Apr 12 16:56:26 2018 +0000
+++ b/main.cpp Thu Apr 12 17:35:57 2018 +0000
@@ -11,69 +11,60 @@
{
confSysClock(); //Configure system clock (72MHz HSE clock, 48MHz USB clock)
pc.baud(9600);
-
- pc.printf("Starting...\r\n");
+ // Create and mount SDFileSystem
fs = new SDFileSystem(PB_5, PB_4, PB_3, PA_10, "sd"); // mosi, miso, sck, cs
-
+ pc.printf("Mounting file system...\r\n");
int err = fs->mount();
pc.printf("%s\r\n", (err ? "Failed :(\r\n" : "OK\r\n"));
if (err)
return err;
-
+
// Open the file.
pc.printf("Opening file '/sd/mytest/sdtest.txt'... ");
-
fp = fopen("/sd/mytest/sdtest.txt", "w+");
pc.printf("%s\r\n", (!fp ? "Failed :(\r\n" : "OK\r\n"));
-
- if (!fp)
- {
+
+ if (!fp) {
// Check whether directory '/sd/mytest' exists.
pc.printf("\r\nChecking directory '/sd/mytest'...\r\n");
struct stat info;
err = stat("/sd/mytest", &info);
- if (err)
- {
+ if (err) {
pc.printf("Directory '/sd/mytest' does not exist.\r\n");
pc.printf("Trying to create it...");
err = mkdir("/sd/mytest", 0777);
pc.printf("%s\r\n", (err ? "Failed :(\r\n" : "OK\r\n"));
if (err)
- return err;
+ return err;
}
-
+
// Create a new 'sdtest.txt' file.
pc.printf("File not found, creating a new one...\r\n");
fp = fopen("/sd/mytest/sdtest.txt", "w+");
pc.printf("%s\r\n", (!fp ? "Failed :(" : "OK"));
- if (!fp)
- {
+ if (!fp) {
error("error: %s (%d)\r\n", strerror(errno), -errno);
return errno;
}
}
-
- for (int i = 0; i < 10; i++)
- {
+
+ for (int i = 0; i < 10; i++) {
pc.printf("Writing numbers (%d/%d)... ", i, 10);
err = fprintf(fp, " %d\r\n", i);
- if (err < 0)
- {
+ if (err < 0) {
pc.printf("Fail :(\r\n");
error("error: %s (%d)\r\n", strerror(errno), -errno);
- }
- else
+ } else
pc.printf("OK\r\n");
}
-
+
pc.printf("Writing numbers (%d/%d)... OK\r\n\r\n", 10, 10);
-
err = fclose(fp);
pc.printf("Closing file '/sd/mytest/sdtest.txt'... ");
pc.printf("%s\r\n", (err ? "Failed :(\r\n" : "OK\r\n"));
if (err)
- return err;
-
+ return err;
+
return 0;
}