![](/media/cache/profiles/crane.png.50x50_q85.jpg)
test
Dependencies: FlashAir_iSDIO SDFileSystem
main.cpp@2:e891da5a46a1, 2019-07-16 (annotated)
- Committer:
- mbed_crane_elec
- Date:
- Tue Jul 16 20:04:48 2019 +0000
- Revision:
- 2:e891da5a46a1
- Parent:
- 1:e7d6381479e1
1st
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_crane_elec | 0:0d4d83f88469 | 1 | /* FlashAir iSDIO sample |
mbed_crane_elec | 0:0d4d83f88469 | 2 | * Copyright (C) 2018 by Junichi SHIBA, PIAX Inc. |
mbed_crane_elec | 0:0d4d83f88469 | 3 | * |
mbed_crane_elec | 0:0d4d83f88469 | 4 | * This file is a FlashAir iSDIO sample program code |
mbed_crane_elec | 0:0d4d83f88469 | 5 | * Released under the BSD 2-Clause license. |
mbed_crane_elec | 0:0d4d83f88469 | 6 | * http://flashair-developers.com/documents/license.html |
mbed_crane_elec | 0:0d4d83f88469 | 7 | */ |
mbed_crane_elec | 0:0d4d83f88469 | 8 | #include "mbed.h" |
mbed_crane_elec | 0:0d4d83f88469 | 9 | #include "FlashAir_iSDIO.h" |
mbed_crane_elec | 0:0d4d83f88469 | 10 | |
mbed_crane_elec | 0:0d4d83f88469 | 11 | //#define USE_CONSOLE |
mbed_crane_elec | 0:0d4d83f88469 | 12 | |
mbed_crane_elec | 0:0d4d83f88469 | 13 | #if defined(TARGET_LPC11U24) |
mbed_crane_elec | 0:0d4d83f88469 | 14 | FlashAir_iSDIO sd(p11, p12, p13, p14, "sd"); // MOSI, MISO, SCLK, SSEL |
mbed_crane_elec | 0:0d4d83f88469 | 15 | #elif defined(TARGET_LPC1114) |
mbed_crane_elec | 0:0d4d83f88469 | 16 | FlashAir_iSDIO sd(p11, p12, p13, p14, "sd"); // MOSI, MISO, SCLK, SSEL |
mbed_crane_elec | 0:0d4d83f88469 | 17 | #elif defined(TARGET_LPC1549) |
mbed_crane_elec | 0:0d4d83f88469 | 18 | FlashAir_iSDIO sd(D11, D12, D13, D10, "sd"); // MOSI, MISO, SCLK, SSEL |
mbed_crane_elec | 0:0d4d83f88469 | 19 | #elif defined(TARGET_NUCLEO_L073RZ) // TOYBOARD |
mbed_crane_elec | 0:0d4d83f88469 | 20 | Serial console(PA_9, PA_10); // TX, RX |
mbed_crane_elec | 0:0d4d83f88469 | 21 | FlashAir_iSDIO sd(PB_15, PB_14, PB_13, PB_12, "sd", &console); // mosi(CMD), miso(DAT0), sclk(CLK), cs(DAT3) |
mbed_crane_elec | 0:0d4d83f88469 | 22 | DigitalOut ledB(PB_11, 1); // B |
mbed_crane_elec | 0:0d4d83f88469 | 23 | DigitalOut ledG(PB_10, 1); // G |
mbed_crane_elec | 0:0d4d83f88469 | 24 | DigitalOut ledR(PA_15, 1); // R |
mbed_crane_elec | 0:0d4d83f88469 | 25 | DigitalOut SD_VEN(PC_4, 0); // SD initialy off |
mbed_crane_elec | 0:0d4d83f88469 | 26 | DigitalIn SD_CD(PC_1); // SD_CD |
mbed_crane_elec | 0:0d4d83f88469 | 27 | #elif defined(TARGET_LPC11U35_401) // Airio-Base |
mbed_crane_elec | 0:0d4d83f88469 | 28 | //#elif defined(TARGET_MCU_LPC11U35_501) |
mbed_crane_elec | 0:0d4d83f88469 | 29 | Serial console(P0_19, P0_18); // TX, RX |
mbed_crane_elec | 0:0d4d83f88469 | 30 | //Serial pc(USBTX, USBRX); |
mbed_crane_elec | 0:0d4d83f88469 | 31 | FlashAir_iSDIO sd(P0_21, P0_22, P1_15, P0_17, "sd", &console); // mosi(CMD), miso(DAT0), sclk(CLK), cs(DAT3) |
mbed_crane_elec | 0:0d4d83f88469 | 32 | DigitalOut ledB(P0_7, 1); |
mbed_crane_elec | 0:0d4d83f88469 | 33 | DigitalOut ledG(P0_7, 1); |
mbed_crane_elec | 0:0d4d83f88469 | 34 | DigitalOut ledR(P0_7, 1); |
mbed_crane_elec | 0:0d4d83f88469 | 35 | DigitalOut SD_VEN(P1_16); |
mbed_crane_elec | 0:0d4d83f88469 | 36 | DigitalIn SD_CD(P1_19); |
mbed_crane_elec | 0:0d4d83f88469 | 37 | #else |
mbed_crane_elec | 0:0d4d83f88469 | 38 | #error |
mbed_crane_elec | 0:0d4d83f88469 | 39 | #endif |
mbed_crane_elec | 0:0d4d83f88469 | 40 | |
mbed_crane_elec | 0:0d4d83f88469 | 41 | |
mbed_crane_elec | 0:0d4d83f88469 | 42 | //************************************************** |
mbed_crane_elec | 0:0d4d83f88469 | 43 | |
mbed_crane_elec | 0:0d4d83f88469 | 44 | int main() |
mbed_crane_elec | 0:0d4d83f88469 | 45 | { |
mbed_crane_elec | 0:0d4d83f88469 | 46 | uint32_t sequenceId ; |
mbed_crane_elec | 0:0d4d83f88469 | 47 | ledG=0; ledB=0; |
mbed_crane_elec | 0:0d4d83f88469 | 48 | |
mbed_crane_elec | 0:0d4d83f88469 | 49 | #ifdef USE_CONSOLE |
mbed_crane_elec | 0:0d4d83f88469 | 50 | console.printf("start FlashAir iSDIO sample\n"); |
mbed_crane_elec | 0:0d4d83f88469 | 51 | #endif |
mbed_crane_elec | 0:0d4d83f88469 | 52 | |
mbed_crane_elec | 1:e7d6381479e1 | 53 | wait(1.0); |
mbed_crane_elec | 0:0d4d83f88469 | 54 | // supply power to SD card |
mbed_crane_elec | 0:0d4d83f88469 | 55 | SD_VEN = 1; |
mbed_crane_elec | 0:0d4d83f88469 | 56 | wait(5.0); |
mbed_crane_elec | 0:0d4d83f88469 | 57 | |
mbed_crane_elec | 0:0d4d83f88469 | 58 | if (SD_CD) { |
mbed_crane_elec | 0:0d4d83f88469 | 59 | #ifdef USE_CONSOLE |
mbed_crane_elec | 0:0d4d83f88469 | 60 | console.printf("SD: Not dected\n"); |
mbed_crane_elec | 0:0d4d83f88469 | 61 | #endif |
mbed_crane_elec | 0:0d4d83f88469 | 62 | } else { |
mbed_crane_elec | 0:0d4d83f88469 | 63 | #ifdef USE_CONSOLE |
mbed_crane_elec | 0:0d4d83f88469 | 64 | console.printf("SD: Detected\n"); |
mbed_crane_elec | 0:0d4d83f88469 | 65 | #endif |
mbed_crane_elec | 0:0d4d83f88469 | 66 | } |
mbed_crane_elec | 0:0d4d83f88469 | 67 | |
mbed_crane_elec | 0:0d4d83f88469 | 68 | // Initialize card |
mbed_crane_elec | 0:0d4d83f88469 | 69 | FILE *fp = fopen("/sd/isdio.txt", "w"); |
mbed_crane_elec | 0:0d4d83f88469 | 70 | fclose(fp); |
mbed_crane_elec | 0:0d4d83f88469 | 71 | |
mbed_crane_elec | 0:0d4d83f88469 | 72 | wait(15.0); |
mbed_crane_elec | 0:0d4d83f88469 | 73 | ledG=1; ledB=1; ledR=0; |
mbed_crane_elec | 0:0d4d83f88469 | 74 | |
mbed_crane_elec | 0:0d4d83f88469 | 75 | // disconnect |
mbed_crane_elec | 0:0d4d83f88469 | 76 | // 1. get sequenceID |
mbed_crane_elec | 0:0d4d83f88469 | 77 | // 2. issue disconnect command |
mbed_crane_elec | 0:0d4d83f88469 | 78 | // 3. wait response |
mbed_crane_elec | 0:0d4d83f88469 | 79 | sequenceId = sd.getNextSequenceId(); |
mbed_crane_elec | 0:0d4d83f88469 | 80 | sd.wlan_disconnect(sequenceId); |
mbed_crane_elec | 0:0d4d83f88469 | 81 | sd.waitResponse(sequenceId); |
mbed_crane_elec | 0:0d4d83f88469 | 82 | wait(5.0); |
mbed_crane_elec | 0:0d4d83f88469 | 83 | |
mbed_crane_elec | 0:0d4d83f88469 | 84 | ledB = 0; |
mbed_crane_elec | 0:0d4d83f88469 | 85 | |
mbed_crane_elec | 0:0d4d83f88469 | 86 | // establish |
mbed_crane_elec | 0:0d4d83f88469 | 87 | // 1. get sequenceID |
mbed_crane_elec | 0:0d4d83f88469 | 88 | // 2. issue establish command |
mbed_crane_elec | 0:0d4d83f88469 | 89 | // 3. wait resoonse |
mbed_crane_elec | 0:0d4d83f88469 | 90 | sequenceId = sd.getNextSequenceId(); |
mbed_crane_elec | 2:e891da5a46a1 | 91 | sd.wlan_establish(sequenceId, (uint8_t*)"isdiotest", (uint8_t*)"12345678", FlashAir_iSDIO::ENCMODE_WPA2PSK_AES); |
mbed_crane_elec | 0:0d4d83f88469 | 92 | wait(5.0); |
mbed_crane_elec | 0:0d4d83f88469 | 93 | ledG = 0; |
mbed_crane_elec | 0:0d4d83f88469 | 94 | |
mbed_crane_elec | 0:0d4d83f88469 | 95 | // shared mem |
mbed_crane_elec | 0:0d4d83f88469 | 96 | // 1. prepare test data |
mbed_crane_elec | 0:0d4d83f88469 | 97 | // 2. write data to shared mem area |
mbed_crane_elec | 0:0d4d83f88469 | 98 | // 3. read back and check |
mbed_crane_elec | 0:0d4d83f88469 | 99 | #define TESTDATA 0xdeadbeaf |
mbed_crane_elec | 0:0d4d83f88469 | 100 | uint32_t testdata = TESTDATA; |
mbed_crane_elec | 0:0d4d83f88469 | 101 | uint8_t data[sizeof(testdata)]; |
mbed_crane_elec | 0:0d4d83f88469 | 102 | memcpy(data, &testdata, sizeof(data)); |
mbed_crane_elec | 0:0d4d83f88469 | 103 | sd.write_shared_mem(0x0, data, sizeof(data)); |
mbed_crane_elec | 0:0d4d83f88469 | 104 | memset(data, 0x0, sizeof(data)); |
mbed_crane_elec | 0:0d4d83f88469 | 105 | sd.read_shared_mem(0x0, data, sizeof(data)); |
mbed_crane_elec | 0:0d4d83f88469 | 106 | |
mbed_crane_elec | 0:0d4d83f88469 | 107 | ledG=1; ledB=1; ledR=1; |
mbed_crane_elec | 0:0d4d83f88469 | 108 | |
mbed_crane_elec | 0:0d4d83f88469 | 109 | for(;;); |
mbed_crane_elec | 0:0d4d83f88469 | 110 | |
mbed_crane_elec | 0:0d4d83f88469 | 111 | } |