This demo reads a bitmap from a FAT formatted SD-card, copies it to flash and displays it on the screen. The demo is based on the following project: https://os.mbed.com/users/DieterGraef/code/DISCO-F746NG_SDFileSystem/

Dependencies:   LCD_DISCO_F746NG TS_DISCO_F746NG mbed FATFileSystem

Fork of DISCO-F746NG_SDFileSystem by Dieter Graef

main.cpp

Committer:
DieterGraef
Date:
2016-03-31
Revision:
0:134f7a094930
Child:
1:7f463f6f904e

File content as of revision 0:134f7a094930:

#include "mbed.h"
#include "SDFileSystem.h"
#include <stdio.h>

DigitalOut myled(LED1);
SDFileSystem sd("sd");

// trim '\n'
void ntrim(char *str)
{
    int i;
    for (i = 0; str[i] != 0; ++i);

    if (i > 0 && str[i - 1] == '\n')
        str[i - 1] = 0;
}


int main() {  
    sd.mount();
    FILE * fp;
        fp = fopen("/sd/test.txt", "w");
        if (fp == NULL)
        {
            printf("open error!!\r\n");
            while(1);
        }
        fprintf(fp,"Writing to SD Card");
        fclose (fp);       
        fp = fopen("/sd/test.txt", "r");
        if (fp == NULL)
        {
            printf("open error!!\r\n");
            while(1);
        }
        // read text file
        char buf[1024];
        while (fgets(buf, sizeof(buf), fp) != NULL)
        {
            ntrim(buf);
            printf("%s\r\n", buf);
        }

        // file close
        fclose(fp);
    while(1) {
        myled = 1; // LED is ON
        wait(0.2); // 200 ms
        myled = 0; // LED is OFF
        wait(1.0); // 1 sec
    }
}