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

Committer:
DieterGraef
Date:
Thu Mar 31 17:43:47 2016 +0000
Revision:
0:134f7a094930
Child:
1:7f463f6f904e
SDFileSystem for STM32F746 Discovery with 4bit SDMMC interface on fixed pins in DMA mode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DieterGraef 0:134f7a094930 1 #include "mbed.h"
DieterGraef 0:134f7a094930 2 #include "SDFileSystem.h"
DieterGraef 0:134f7a094930 3 #include <stdio.h>
DieterGraef 0:134f7a094930 4
DieterGraef 0:134f7a094930 5 DigitalOut myled(LED1);
DieterGraef 0:134f7a094930 6 SDFileSystem sd("sd");
DieterGraef 0:134f7a094930 7
DieterGraef 0:134f7a094930 8 // trim '\n'
DieterGraef 0:134f7a094930 9 void ntrim(char *str)
DieterGraef 0:134f7a094930 10 {
DieterGraef 0:134f7a094930 11 int i;
DieterGraef 0:134f7a094930 12 for (i = 0; str[i] != 0; ++i);
DieterGraef 0:134f7a094930 13
DieterGraef 0:134f7a094930 14 if (i > 0 && str[i - 1] == '\n')
DieterGraef 0:134f7a094930 15 str[i - 1] = 0;
DieterGraef 0:134f7a094930 16 }
DieterGraef 0:134f7a094930 17
DieterGraef 0:134f7a094930 18
DieterGraef 0:134f7a094930 19 int main() {
DieterGraef 0:134f7a094930 20 sd.mount();
DieterGraef 0:134f7a094930 21 FILE * fp;
DieterGraef 0:134f7a094930 22 fp = fopen("/sd/test.txt", "w");
DieterGraef 0:134f7a094930 23 if (fp == NULL)
DieterGraef 0:134f7a094930 24 {
DieterGraef 0:134f7a094930 25 printf("open error!!\r\n");
DieterGraef 0:134f7a094930 26 while(1);
DieterGraef 0:134f7a094930 27 }
DieterGraef 0:134f7a094930 28 fprintf(fp,"Writing to SD Card");
DieterGraef 0:134f7a094930 29 fclose (fp);
DieterGraef 0:134f7a094930 30 fp = fopen("/sd/test.txt", "r");
DieterGraef 0:134f7a094930 31 if (fp == NULL)
DieterGraef 0:134f7a094930 32 {
DieterGraef 0:134f7a094930 33 printf("open error!!\r\n");
DieterGraef 0:134f7a094930 34 while(1);
DieterGraef 0:134f7a094930 35 }
DieterGraef 0:134f7a094930 36 // read text file
DieterGraef 0:134f7a094930 37 char buf[1024];
DieterGraef 0:134f7a094930 38 while (fgets(buf, sizeof(buf), fp) != NULL)
DieterGraef 0:134f7a094930 39 {
DieterGraef 0:134f7a094930 40 ntrim(buf);
DieterGraef 0:134f7a094930 41 printf("%s\r\n", buf);
DieterGraef 0:134f7a094930 42 }
DieterGraef 0:134f7a094930 43
DieterGraef 0:134f7a094930 44 // file close
DieterGraef 0:134f7a094930 45 fclose(fp);
DieterGraef 0:134f7a094930 46 while(1) {
DieterGraef 0:134f7a094930 47 myled = 1; // LED is ON
DieterGraef 0:134f7a094930 48 wait(0.2); // 200 ms
DieterGraef 0:134f7a094930 49 myled = 0; // LED is OFF
DieterGraef 0:134f7a094930 50 wait(1.0); // 1 sec
DieterGraef 0:134f7a094930 51 }
DieterGraef 0:134f7a094930 52 }