NUCLEO-L476RG sdBlockDevice sample code. This is a test for the new SD-Block device driver using the latest MBED-OS dated 2017-05-22. This might not work when mbed-os make big changes in the library.

Fork of mbed-osSDBlockDevice_sampleCode by M J.

main.cpp

Committer:
mjm2016
Date:
2017-05-22
Revision:
10:423e0d0a7ef6
Parent:
0:8df79c088b12

File content as of revision 10:423e0d0a7ef6:

#include <mbed.h>
#include <SDBlockDevice.h>
#include <FATFileSystem.h>

SDBlockDevice sd(PA_7, PA_6, PA_5, PB_6);
///SDBlockDevice sd(D11, D12, D13, D10);
FATFileSystem fs("sd");
Serial pc(SERIAL_TX, SERIAL_RX);

void testSDCard(){
    pc.printf("\nWait for new connection...\n");
    mkdir("/sd/mjm2016", 0777);
    FILE *fp = fopen("/sd/mjm2016/sdBlockDeviceTest.txt", "w");
    if(fp == NULL) {
        pc.printf("Could not open file for write\n");
        return  ;
    }
    fprintf(fp, "sdBlockDeviceTest System say \"Hello, have fun!\" ");
    pc.printf("Writing to your SD-CARD finished. BYE!!"); 
    fclose(fp);
    }

int main()
{
    sd.init();
    fs.mount(&sd);
    testSDCard();
    fs.unmount();
    sd.deinit();
}