Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

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