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
main.cpp@1:7f463f6f904e, 2016-04-12 (annotated)
- Committer:
- DieterGraef
- Date:
- Tue Apr 12 13:48:45 2016 +0000
- Revision:
- 1:7f463f6f904e
- Parent:
- 0:134f7a094930
- Child:
- 4:95e30a911d97
Added a locking mechanism for the SD Fat system for usage in RTOS environment.
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:7f463f6f904e | 19 | int main() { |
DieterGraef | 1:7f463f6f904e | 20 | printf("Starting Filetest"); |
DieterGraef | 0:134f7a094930 | 21 | sd.mount(); |
DieterGraef | 0:134f7a094930 | 22 | FILE * fp; |
DieterGraef | 0:134f7a094930 | 23 | fp = fopen("/sd/test.txt", "w"); |
DieterGraef | 0:134f7a094930 | 24 | if (fp == NULL) |
DieterGraef | 0:134f7a094930 | 25 | { |
DieterGraef | 0:134f7a094930 | 26 | printf("open error!!\r\n"); |
DieterGraef | 0:134f7a094930 | 27 | while(1); |
DieterGraef | 0:134f7a094930 | 28 | } |
DieterGraef | 0:134f7a094930 | 29 | fprintf(fp,"Writing to SD Card"); |
DieterGraef | 0:134f7a094930 | 30 | fclose (fp); |
DieterGraef | 0:134f7a094930 | 31 | fp = fopen("/sd/test.txt", "r"); |
DieterGraef | 0:134f7a094930 | 32 | if (fp == NULL) |
DieterGraef | 0:134f7a094930 | 33 | { |
DieterGraef | 0:134f7a094930 | 34 | printf("open error!!\r\n"); |
DieterGraef | 0:134f7a094930 | 35 | while(1); |
DieterGraef | 0:134f7a094930 | 36 | } |
DieterGraef | 0:134f7a094930 | 37 | // read text file |
DieterGraef | 0:134f7a094930 | 38 | char buf[1024]; |
DieterGraef | 0:134f7a094930 | 39 | while (fgets(buf, sizeof(buf), fp) != NULL) |
DieterGraef | 0:134f7a094930 | 40 | { |
DieterGraef | 0:134f7a094930 | 41 | ntrim(buf); |
DieterGraef | 0:134f7a094930 | 42 | printf("%s\r\n", buf); |
DieterGraef | 0:134f7a094930 | 43 | } |
DieterGraef | 0:134f7a094930 | 44 | |
DieterGraef | 0:134f7a094930 | 45 | // file close |
DieterGraef | 0:134f7a094930 | 46 | fclose(fp); |
DieterGraef | 0:134f7a094930 | 47 | while(1) { |
DieterGraef | 0:134f7a094930 | 48 | myled = 1; // LED is ON |
DieterGraef | 0:134f7a094930 | 49 | wait(0.2); // 200 ms |
DieterGraef | 0:134f7a094930 | 50 | myled = 0; // LED is OFF |
DieterGraef | 0:134f7a094930 | 51 | wait(1.0); // 1 sec |
DieterGraef | 0:134f7a094930 | 52 | } |
DieterGraef | 0:134f7a094930 | 53 | } |