Example program for FileSystem on SD card over SPI on NUCLEO-F411RE and Wiznet5500
Dependencies: SDFileSystem mbed
Fork of Seeed_SDCard_Shield by
Diff: main.cpp
- Revision:
- 5:6dc74456e4a9
- Parent:
- 3:5edc67dee8b7
--- a/main.cpp Fri Feb 13 09:40:18 2015 +0000 +++ b/main.cpp Tue Dec 29 19:10:22 2015 +0000 @@ -19,27 +19,37 @@ #include "mbed.h" #include "SDFileSystem.h" -Serial pc(USBTX, USBRX); -SDFileSystem sd(D11, D12, D13, D10, "sd"); // MOSI, MISO, SCK, CS +Serial pc(SERIAL_TX, SERIAL_RX); +SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, D4, "sd"); // MOSI, MISO, SCK, CS + FILE *fp; -int main() { - wait(2); - pc.printf("Initializing\r\n"); +int main() +{ + pc.baud(115200); // console terminal to 115200 baud + wait(2); + + pc.printf("Initializing\r\n"); + + fp = fopen("/sd/hello.txt", "r"); - fp = fopen("/sd/hello.txt", "r"); - if (fp != NULL) { - fclose(fp); - remove("/sd/hello.txt"); - pc.printf("Remove an existing file with the same name\r\n"); - } + if (fp != NULL) + { + fclose(fp); + remove("/sd/hello.txt"); + pc.printf("Remove an existing file with the same name\r\n"); + } + + fp = fopen("/sd/hello.txt", "w"); - fp = fopen("/sd/hello.txt", "w"); - if (fp == NULL) { - pc.printf("Unable to write the file\r\n"); - } else { - fprintf(fp, "mbed SDCard application!"); - fclose(fp); - pc.printf("File successfully written!\r\n"); - } + if (fp == NULL) + { + pc.printf("Unable to write the file\r\n"); + } + else + { + fprintf(fp, "mbed SDCard application!"); + fclose(fp); + pc.printf("File successfully written!\r\n"); + } }