Example program for FileSystem on SD card over SPI on NUCLEO-F411RE and Wiznet5500

Dependencies:   SDFileSystem mbed

Fork of Seeed_SDCard_Shield by Shields

Committer:
sjallouli
Date:
Tue Dec 29 19:10:22 2015 +0000
Revision:
5:6dc74456e4a9
Parent:
3:5edc67dee8b7
Port to NUCLEO-F411RE and Wiznet5500

Who changed what in which revision?

UserRevisionLine numberNew contents of line
screamer 3:5edc67dee8b7 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
screamer 3:5edc67dee8b7 2 *
screamer 3:5edc67dee8b7 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
screamer 3:5edc67dee8b7 4 * and associated documentation files (the "Software"), to deal in the Software without
screamer 3:5edc67dee8b7 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
screamer 3:5edc67dee8b7 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
screamer 3:5edc67dee8b7 7 * Software is furnished to do so, subject to the following conditions:
screamer 3:5edc67dee8b7 8 *
screamer 3:5edc67dee8b7 9 * The above copyright notice and this permission notice shall be included in all copies or
screamer 3:5edc67dee8b7 10 * substantial portions of the Software.
screamer 3:5edc67dee8b7 11 *
screamer 3:5edc67dee8b7 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
screamer 3:5edc67dee8b7 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
screamer 3:5edc67dee8b7 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
screamer 3:5edc67dee8b7 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
screamer 3:5edc67dee8b7 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
screamer 3:5edc67dee8b7 17 */
screamer 3:5edc67dee8b7 18
screamer 0:525c842a3c89 19 #include "mbed.h"
screamer 0:525c842a3c89 20 #include "SDFileSystem.h"
screamer 0:525c842a3c89 21
sjallouli 5:6dc74456e4a9 22 Serial pc(SERIAL_TX, SERIAL_RX);
sjallouli 5:6dc74456e4a9 23 SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, D4, "sd"); // MOSI, MISO, SCK, CS
sjallouli 5:6dc74456e4a9 24
screamer 0:525c842a3c89 25 FILE *fp;
screamer 0:525c842a3c89 26
sjallouli 5:6dc74456e4a9 27 int main()
sjallouli 5:6dc74456e4a9 28 {
sjallouli 5:6dc74456e4a9 29 pc.baud(115200); // console terminal to 115200 baud
sjallouli 5:6dc74456e4a9 30 wait(2);
sjallouli 5:6dc74456e4a9 31
sjallouli 5:6dc74456e4a9 32 pc.printf("Initializing\r\n");
sjallouli 5:6dc74456e4a9 33
sjallouli 5:6dc74456e4a9 34 fp = fopen("/sd/hello.txt", "r");
screamer 0:525c842a3c89 35
sjallouli 5:6dc74456e4a9 36 if (fp != NULL)
sjallouli 5:6dc74456e4a9 37 {
sjallouli 5:6dc74456e4a9 38 fclose(fp);
sjallouli 5:6dc74456e4a9 39 remove("/sd/hello.txt");
sjallouli 5:6dc74456e4a9 40 pc.printf("Remove an existing file with the same name\r\n");
sjallouli 5:6dc74456e4a9 41 }
sjallouli 5:6dc74456e4a9 42
sjallouli 5:6dc74456e4a9 43 fp = fopen("/sd/hello.txt", "w");
screamer 0:525c842a3c89 44
sjallouli 5:6dc74456e4a9 45 if (fp == NULL)
sjallouli 5:6dc74456e4a9 46 {
sjallouli 5:6dc74456e4a9 47 pc.printf("Unable to write the file\r\n");
sjallouli 5:6dc74456e4a9 48 }
sjallouli 5:6dc74456e4a9 49 else
sjallouli 5:6dc74456e4a9 50 {
sjallouli 5:6dc74456e4a9 51 fprintf(fp, "mbed SDCard application!");
sjallouli 5:6dc74456e4a9 52 fclose(fp);
sjallouli 5:6dc74456e4a9 53 pc.printf("File successfully written!\r\n");
sjallouli 5:6dc74456e4a9 54 }
screamer 0:525c842a3c89 55 }