mbed-os

Fork of mbed-os by erkin yucel

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 #include "mbed.h"
elessair 0:f269e3021894 2 #include "SDFileSystem.h"
elessair 0:f269e3021894 3 #include "test_env.h"
elessair 0:f269e3021894 4
elessair 0:f269e3021894 5 #if defined(TARGET_KL25Z)
elessair 0:f269e3021894 6 SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
elessair 0:f269e3021894 7
elessair 0:f269e3021894 8 #elif defined(TARGET_KL46Z)
elessair 0:f269e3021894 9 SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
elessair 0:f269e3021894 10
elessair 0:f269e3021894 11 #elif defined(TARGET_K64F) || defined(TARGET_K66F)
elessair 0:f269e3021894 12 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
elessair 0:f269e3021894 13
elessair 0:f269e3021894 14 #elif defined(TARGET_K22F)
elessair 0:f269e3021894 15 SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
elessair 0:f269e3021894 16
elessair 0:f269e3021894 17 #elif defined(TARGET_K20D50M)
elessair 0:f269e3021894 18 SDFileSystem sd(PTD2, PTD3, PTD1, PTC2, "sd");
elessair 0:f269e3021894 19
elessair 0:f269e3021894 20 #elif defined(TARGET_nRF51822)
elessair 0:f269e3021894 21 SDFileSystem sd(p12, p13, p15, p14, "sd");
elessair 0:f269e3021894 22
elessair 0:f269e3021894 23 #elif defined(TARGET_NUCLEO_F030R8) || \
elessair 0:f269e3021894 24 defined(TARGET_NUCLEO_F070RB) || \
elessair 0:f269e3021894 25 defined(TARGET_NUCLEO_F072RB) || \
elessair 0:f269e3021894 26 defined(TARGET_NUCLEO_F091RC) || \
elessair 0:f269e3021894 27 defined(TARGET_NUCLEO_F103RB) || \
elessair 0:f269e3021894 28 defined(TARGET_NUCLEO_F302R8) || \
elessair 0:f269e3021894 29 defined(TARGET_NUCLEO_F303RE) || \
elessair 0:f269e3021894 30 defined(TARGET_NUCLEO_F334R8) || \
elessair 0:f269e3021894 31 defined(TARGET_NUCLEO_F401RE) || \
elessair 0:f269e3021894 32 defined(TARGET_NUCLEO_F410RB) || \
elessair 0:f269e3021894 33 defined(TARGET_NUCLEO_F411RE) || \
elessair 0:f269e3021894 34 defined(TARGET_NUCLEO_L053R8) || \
elessair 0:f269e3021894 35 defined(TARGET_NUCLEO_L073RZ) || \
elessair 0:f269e3021894 36 defined(TARGET_NUCLEO_L152RE)
elessair 0:f269e3021894 37 SDFileSystem sd(D11, D12, D13, D10, "sd");
elessair 0:f269e3021894 38
elessair 0:f269e3021894 39 #elif defined(TARGET_DISCO_F051R8) || \
elessair 0:f269e3021894 40 defined(TARGET_NUCLEO_L031K6)
elessair 0:f269e3021894 41 SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
elessair 0:f269e3021894 42
elessair 0:f269e3021894 43 #elif defined(TARGET_LPC2368)
elessair 0:f269e3021894 44 SDFileSystem sd(p11, p12, p13, p14, "sd");
elessair 0:f269e3021894 45
elessair 0:f269e3021894 46 #elif defined(TARGET_LPC11U68)
elessair 0:f269e3021894 47 SDFileSystem sd(D11, D12, D13, D10, "sd");
elessair 0:f269e3021894 48
elessair 0:f269e3021894 49 #elif defined(TARGET_LPC1549)
elessair 0:f269e3021894 50 SDFileSystem sd(D11, D12, D13, D10, "sd");
elessair 0:f269e3021894 51
elessair 0:f269e3021894 52 #elif defined(TARGET_RZ_A1H)
elessair 0:f269e3021894 53 SDFileSystem sd(P8_5, P8_6, P8_3, P8_4, "sd");
elessair 0:f269e3021894 54
elessair 0:f269e3021894 55 #elif defined(TARGET_LPC11U37H_401)
elessair 0:f269e3021894 56 SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
elessair 0:f269e3021894 57
elessair 0:f269e3021894 58 #else
elessair 0:f269e3021894 59 SDFileSystem sd(p11, p12, p13, p14, "sd");
elessair 0:f269e3021894 60 #endif
elessair 0:f269e3021894 61
elessair 0:f269e3021894 62 namespace {
elessair 0:f269e3021894 63 const char *sd_file_path = "/sd/out.txt";
elessair 0:f269e3021894 64 const int DATA_SIZE = 256;
elessair 0:f269e3021894 65 }
elessair 0:f269e3021894 66
elessair 0:f269e3021894 67 int main() {
elessair 0:f269e3021894 68 MBED_HOSTTEST_TIMEOUT(15);
elessair 0:f269e3021894 69 MBED_HOSTTEST_SELECT(default_auto);
elessair 0:f269e3021894 70 MBED_HOSTTEST_DESCRIPTION(SD File System);
elessair 0:f269e3021894 71 MBED_HOSTTEST_START("MBED_A12");
elessair 0:f269e3021894 72
elessair 0:f269e3021894 73 uint8_t data_written[DATA_SIZE] = { 0 };
elessair 0:f269e3021894 74 bool result = false;
elessair 0:f269e3021894 75
elessair 0:f269e3021894 76 // Fill data_written buffer with random data
elessair 0:f269e3021894 77 // Write these data into the file
elessair 0:f269e3021894 78 bool write_result = false;
elessair 0:f269e3021894 79 {
elessair 0:f269e3021894 80 printf("SD: Writing ... ");
elessair 0:f269e3021894 81 FILE *f = fopen(sd_file_path, "w");
elessair 0:f269e3021894 82 if (f) {
elessair 0:f269e3021894 83 for (int i = 0; i < DATA_SIZE; i++) {
elessair 0:f269e3021894 84 data_written[i] = rand() % 0XFF;
elessair 0:f269e3021894 85 fprintf(f, "%c", data_written[i]);
elessair 0:f269e3021894 86 }
elessair 0:f269e3021894 87 write_result = true;
elessair 0:f269e3021894 88 fclose(f);
elessair 0:f269e3021894 89 }
elessair 0:f269e3021894 90 printf("[%s]\r\n", write_result ? "OK" : "FAIL");
elessair 0:f269e3021894 91 }
elessair 0:f269e3021894 92
elessair 0:f269e3021894 93 // Read back the data from the file and store them in data_read
elessair 0:f269e3021894 94 bool read_result = false;
elessair 0:f269e3021894 95 {
elessair 0:f269e3021894 96 printf("SD: Reading data ... ");
elessair 0:f269e3021894 97 FILE *f = fopen(sd_file_path, "r");
elessair 0:f269e3021894 98 if (f) {
elessair 0:f269e3021894 99 read_result = true;
elessair 0:f269e3021894 100 for (int i = 0; i < DATA_SIZE; i++) {
elessair 0:f269e3021894 101 uint8_t data = fgetc(f);
elessair 0:f269e3021894 102 if (data != data_written[i]) {
elessair 0:f269e3021894 103 read_result = false;
elessair 0:f269e3021894 104 break;
elessair 0:f269e3021894 105 }
elessair 0:f269e3021894 106 }
elessair 0:f269e3021894 107 fclose(f);
elessair 0:f269e3021894 108 }
elessair 0:f269e3021894 109 printf("[%s]\r\n", read_result ? "OK" : "FAIL");
elessair 0:f269e3021894 110 }
elessair 0:f269e3021894 111
elessair 0:f269e3021894 112 result = write_result && read_result;
elessair 0:f269e3021894 113 MBED_HOSTTEST_RESULT(result);
elessair 0:f269e3021894 114 }