Rainer Raul
/
testsdprogram
mbed studio
Revision 0:6444a20e1a0e, committed 2022-05-18
- Comitter:
- rainerraul
- Date:
- Wed May 18 14:43:41 2022 +0000
- Commit message:
- mbed studio
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Wed May 18 14:43:41 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/rainerraul/code/SDFileSystem/#c04836714316
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed May 18 14:43:41 2022 +0000 @@ -0,0 +1,46 @@ +#include "mbed.h" +#include "stdio.h" +#include "stdint.h" +#include "stdlib.h" +#include "SPI.h" +#include "SDFileSystem.h" + +Serial terminal(USBTX, USBRX); + +//Create an SDFileSystem object +SDFileSystem sd(PA_7, PA_6, PA_5, PB_6, "sd"); // mosi, miso, sclk, cs + +int main() +{ + wait(0.5); + terminal.baud(115200); + //Mount the filesystem + sd.mount(); + //Perform a write test + printf("\nWriting to SD card..."); + FILE *fp = fopen("/sd/sdtest.txt", "w"); + if (fp != NULL) { + fprintf(fp, "We're writing to an SD card!"); + fclose(fp); + printf("success!\n"); + } else { + printf("failed!\n"); + } + + //Perform a read test + printf("Reading from SD card..."); + fp = fopen("/sd/sdtest.txt", "r"); + if (fp != NULL) { + char c = fgetc(fp); + if (c == 'W') + printf("success!\n"); + else + printf("incorrect char (%c)!\n", c); + fclose(fp); + } else { + printf("failed!\n"); + } + sd.unmount(); + //Unmount the filesystem + // sd.unmount(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed May 18 14:43:41 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.lib Wed May 18 14:43:41 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/rainerraul/code/mbed/#f324e9ab2364