SDFileSystem for STM32F746NG Discovery with 4bit SDMMC interface on fixed pins in DMA mode

Dependencies:   BSP_DISCO_F746NG SDFileSystem mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "SDFileSystem.h"
00003 #include <stdio.h>
00004 
00005 DigitalOut myled(LED1);
00006 SDFileSystem sd("sd");
00007 
00008 // trim '\n'
00009 void ntrim(char *str)
00010 {
00011     int i;
00012     for (i = 0; str[i] != 0; ++i);
00013 
00014     if (i > 0 && str[i - 1] == '\n')
00015         str[i - 1] = 0;
00016 }
00017 
00018 
00019 int main() { 
00020     printf("Starting Filetest"); 
00021     sd.mount();
00022     FILE * fp;
00023         fp = fopen("/sd/test.txt", "w");
00024         if (fp == NULL)
00025         {
00026             printf("open error!!\r\n");
00027             while(1);
00028         }
00029         fprintf(fp,"Writing to SD Card");
00030         fclose (fp);       
00031         fp = fopen("/sd/test.txt", "r");
00032         if (fp == NULL)
00033         {
00034             printf("open error!!\r\n");
00035             while(1);
00036         }
00037         // read text file
00038         char buf[1024];
00039         while (fgets(buf, sizeof(buf), fp) != NULL)
00040         {
00041             ntrim(buf);
00042             printf("%s\r\n", buf);
00043         }
00044 
00045         // file close
00046         fclose(fp);
00047     while(1) {
00048         myled = 1; // LED is ON
00049         wait(0.2); // 200 ms
00050         myled = 0; // LED is OFF
00051         wait(1.0); // 1 sec
00052     }
00053 }