Example program demonstrates SD card library
Dependencies: SDFileSystem USBDevice max32630fthr
Fork of FTHR_SD_Demo by
This example program writes "Hello World!" into a file named "myfile.txt" on the card inserted into the microSD card connector.
main.cpp@8:be1c3495b9ea, 2017-11-17 (annotated)
- Committer:
- h_keyur
- Date:
- Fri Nov 17 20:59:27 2017 +0000
- Revision:
- 8:be1c3495b9ea
- Parent:
- 6:96d8d823e292
Changed the SDFileSystem library; Does not include FATFileSystem. FATFileSystem is pulled from mbed-os/features/filesystem/
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
switches | 0:60a522ae2e35 | 1 | #include "mbed.h" |
switches | 1:90313362ec11 | 2 | #include "max32630fthr.h" |
switches | 1:90313362ec11 | 3 | #include "SDFileSystem.h" |
switches | 0:60a522ae2e35 | 4 | |
switches | 6:96d8d823e292 | 5 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
switches | 3:247c750f9f3d | 6 | |
switches | 1:90313362ec11 | 7 | DigitalOut rLED(LED1); |
switches | 1:90313362ec11 | 8 | DigitalOut gLED(LED2); |
switches | 0:60a522ae2e35 | 9 | |
switches | 1:90313362ec11 | 10 | SDFileSystem sd(P0_5, P0_6, P0_4, P0_7, "sd"); // mosi, miso, sclk, cs |
switches | 0:60a522ae2e35 | 11 | |
switches | 0:60a522ae2e35 | 12 | // main() runs in its own thread in the OS |
switches | 0:60a522ae2e35 | 13 | // (note the calls to Thread::wait below for delays) |
switches | 0:60a522ae2e35 | 14 | int main() |
switches | 0:60a522ae2e35 | 15 | { |
switches | 6:96d8d823e292 | 16 | gLED = LED_ON; |
switches | 1:90313362ec11 | 17 | rLED = LED_ON; |
switches | 1:90313362ec11 | 18 | |
switches | 1:90313362ec11 | 19 | FILE *fp = fopen("/sd/myfile.txt", "w"); |
switches | 1:90313362ec11 | 20 | fprintf(fp, "Hello World!\n"); |
switches | 1:90313362ec11 | 21 | fclose(fp); |
switches | 1:90313362ec11 | 22 | rLED = LED_OFF; |
switches | 0:60a522ae2e35 | 23 | |
switches | 0:60a522ae2e35 | 24 | while (true) { |
switches | 1:90313362ec11 | 25 | gLED = !gLED; |
switches | 0:60a522ae2e35 | 26 | Thread::wait(500); |
switches | 0:60a522ae2e35 | 27 | } |
switches | 0:60a522ae2e35 | 28 | } |
switches | 0:60a522ae2e35 | 29 |