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