2 #include "SDFileSystem.h"
4 void led_blink(PinName led)
14 void notify_completion(bool success)
17 printf("{success}\n");
19 printf("{failure}\n");
22 led_blink(success ? LED1 : LED4);
25 #define TEST_STRING "Hello World!"
27 FILE *test_open(char *path, const char *mode)
31 f = fopen(path, mode);
33 printf("Error opening file\n");
34 notify_completion(false);
40 void test_write(FILE *f, const char *str)
42 int n = fprintf(f, str);
44 if (n != strlen(str)) {
45 printf("Error writing file\n");
46 notify_completion(false);
50 void test_close(FILE *f)
55 printf("Error closing file\n");
56 notify_completion(false);
60 DigitalOut led2(LED2);
64 #if defined(TARGET_KL25Z)
65 SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
66 #elif defined(TARGET_nRF51822)
67 //SDFileSystem sd(p20, p22, p25, p24, "sd");
68 SDFileSystem sd(p12, p13, p15, p14, "sd");
69 #elif defined(TARGET_NUCLEO_F030R8) || \
70 defined(TARGET_NUCLEO_F070RB) || \
71 defined(TARGET_NUCLEO_F072RB) || \
72 defined(TARGET_NUCLEO_F091RC) || \
73 defined(TARGET_NUCLEO_F103RB) || \
74 defined(TARGET_NUCLEO_F302R8) || \
75 defined(TARGET_NUCLEO_F303RE) || \
76 defined(TARGET_NUCLEO_F334R8) || \
77 defined(TARGET_NUCLEO_F401RE) || \
78 defined(TARGET_NUCLEO_F411RE) || \
79 defined(TARGET_NUCLEO_L053R8) || \
80 defined(TARGET_NUCLEO_L073RZ) || \
81 defined(TARGET_NUCLEO_L152RE)
82 SDFileSystem sd(D11, D12, D13, D10, "sd");
83 #elif defined(TARGET_LPC11U37H_401)
84 SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
86 SDFileSystem sd(p11, p12, p13, p14, "sd");
91 char *str = TEST_STRING;
92 char *buffer = (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING));
93 int str_len = strlen(TEST_STRING);
95 printf("Write files\n");
97 for (int i = 0; i < 10; i++) {
98 sprintf(filename, "/sd/test_%d.txt", i);
99 printf("Creating file: %s\n", filename);
100 f = test_open(filename, "w");
106 printf("List files:\n");
107 DIR *d = opendir("/sd");
109 printf("Error opening directory\n");
110 notify_completion(false);
114 while ((p = readdir(d)) != NULL)
115 printf("%s\n", p->d_name);
118 notify_completion(true);