Nucleo-L476RG using SD-CARD library. The program is functioning but might get problem if you update the mbed. In two different times I got problem with mbed library as no SPI clock was generated. At the time I publish this library the mbed is broken.

Dependencies:   SDFileSystem

Committer:
mjm2016
Date:
Fri Apr 07 10:33:54 2017 +0000
Revision:
0:fdd58267bc13
Reference code for testing SD-Card with MBED-OS. ; The SD-Card works with this revision, but updating MBED-OS might cause problem. I can confirm that the current mbed-rev at 2017-04-07 is broken. ; Use this sample code as reference

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mjm2016 0:fdd58267bc13 1 #include "mbed.h"
mjm2016 0:fdd58267bc13 2 #include "SDFileSystem.h"
mjm2016 0:fdd58267bc13 3 //Nucleo L476RG_SDCARD test
mjm2016 0:fdd58267bc13 4
mjm2016 0:fdd58267bc13 5
mjm2016 0:fdd58267bc13 6
mjm2016 0:fdd58267bc13 7 /* SD: Description nucleo PINNR (from top to down of the right-connector-left pins):
mjm2016 0:fdd58267bc13 8 1 CS PB_6 9
mjm2016 0:fdd58267bc13 9 2 MOSI PA_7 8
mjm2016 0:fdd58267bc13 10 3 GND GND
mjm2016 0:fdd58267bc13 11 4 3.3V 3.3V
mjm2016 0:fdd58267bc13 12 5 SCLK PA_5 6
mjm2016 0:fdd58267bc13 13 6 -
mjm2016 0:fdd58267bc13 14 7 MISO PA_6 7
mjm2016 0:fdd58267bc13 15 8
mjm2016 0:fdd58267bc13 16
mjm2016 0:fdd58267bc13 17 */
mjm2016 0:fdd58267bc13 18 // MOSI, MISO, SCLK, CS, name
mjm2016 0:fdd58267bc13 19 SDFileSystem sd(PA_7, PA_6, PA_5, PB_6, "sd");
mjm2016 0:fdd58267bc13 20
mjm2016 0:fdd58267bc13 21
mjm2016 0:fdd58267bc13 22 int main() {
mjm2016 0:fdd58267bc13 23 printf("\nWait for new connection...\n");
mjm2016 0:fdd58267bc13 24
mjm2016 0:fdd58267bc13 25 mkdir("/sd/mydir", 0777);
mjm2016 0:fdd58267bc13 26 printf("\nDirectory created\n");
mjm2016 0:fdd58267bc13 27 FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
mjm2016 0:fdd58267bc13 28 if(fp == NULL) {
mjm2016 0:fdd58267bc13 29 printf("Could not open file for write\n");
mjm2016 0:fdd58267bc13 30 }
mjm2016 0:fdd58267bc13 31 fprintf(fp, "Hello fun SD Card World!");
mjm2016 0:fdd58267bc13 32 fclose(fp);
mjm2016 0:fdd58267bc13 33 printf("Text written to the SD-CARD\n");
mjm2016 0:fdd58267bc13 34 }