![](/media/cache/profiles/f0fcf351df4eb6786e9bb6fc4e2dee02.jpg.50x50_q85.jpg)
Test program for FlashAir with iSDIO
Dependencies: FlashAir_iSDIO SDFileSystem
Diff: main.cpp
- Revision:
- 3:fc1908567f3b
- Parent:
- 2:e891da5a46a1
diff -r e891da5a46a1 -r fc1908567f3b main.cpp --- a/main.cpp Tue Jul 16 20:04:48 2019 +0000 +++ b/main.cpp Wed Aug 28 22:48:37 2019 +0000 @@ -1,111 +1,50 @@ -/* FlashAir iSDIO sample - * Copyright (C) 2018 by Junichi SHIBA, PIAX Inc. +/* + * Mbed Application program + * FlashAir control program * - * This file is a FlashAir iSDIO sample program code - * Released under the BSD 2-Clause license. - * http://flashair-developers.com/documents/license.html + * Copyright (c) 2018,'19 Kenji Arai / JH1PJL + * http://www.page.sannet.ne.jp/kenjia/index.html + * https://os.mbed.com/users/kenjiArai/ + * Created: April 4th, 2018 + * Revised: August 28th, 2019 */ + +/* + * FlashAir: + * https://flashair-developers.com/ja/ + * + * Reference program: + * https://os.mbed.com/users/mbed_crane_elec/code/FlashAir_iSDIO_sample_OS5_/ + * https://os.mbed.com/users/ban4jp/code/FlashAir_Twitter/ + * + * Tested board on Nucleo-F446RE + */ + +// Include -------------------------------------------------------------------- #include "mbed.h" #include "FlashAir_iSDIO.h" -//#define USE_CONSOLE +// Definition ----------------------------------------------------------------- + +// Constructor ---------------------------------------------------------------- +Serial pc(USBTX, USBRX, 115200); +Serial console(A0, A1); // TX, RX +// mosi(CMD), miso(DAT0), sclk(CLK), cs(DAT3) +FlashAir_iSDIO sd(D11, D12, D13, D10, "sd", &console); -#if defined(TARGET_LPC11U24) -FlashAir_iSDIO sd(p11, p12, p13, p14, "sd"); // MOSI, MISO, SCLK, SSEL -#elif defined(TARGET_LPC1114) -FlashAir_iSDIO sd(p11, p12, p13, p14, "sd"); // MOSI, MISO, SCLK, SSEL -#elif defined(TARGET_LPC1549) -FlashAir_iSDIO sd(D11, D12, D13, D10, "sd"); // MOSI, MISO, SCLK, SSEL -#elif defined(TARGET_NUCLEO_L073RZ) // TOYBOARD -Serial console(PA_9, PA_10); // TX, RX -FlashAir_iSDIO sd(PB_15, PB_14, PB_13, PB_12, "sd", &console); // mosi(CMD), miso(DAT0), sclk(CLK), cs(DAT3) -DigitalOut ledB(PB_11, 1); // B -DigitalOut ledG(PB_10, 1); // G -DigitalOut ledR(PA_15, 1); // R -DigitalOut SD_VEN(PC_4, 0); // SD initialy off -DigitalIn SD_CD(PC_1); // SD_CD -#elif defined(TARGET_LPC11U35_401) // Airio-Base -//#elif defined(TARGET_MCU_LPC11U35_501) -Serial console(P0_19, P0_18); // TX, RX -//Serial pc(USBTX, USBRX); -FlashAir_iSDIO sd(P0_21, P0_22, P1_15, P0_17, "sd", &console); // mosi(CMD), miso(DAT0), sclk(CLK), cs(DAT3) -DigitalOut ledB(P0_7, 1); -DigitalOut ledG(P0_7, 1); -DigitalOut ledR(P0_7, 1); -DigitalOut SD_VEN(P1_16); -DigitalIn SD_CD(P1_19); -#else -#error -#endif +// RAM ------------------------------------------------------------------------ + +// ROM / Constant data -------------------------------------------------------- +// Function prototypes -------------------------------------------------------- +extern void mon (void); -//************************************************** - +//------------------------------------------------------------------------------ +// Control Program +//------------------------------------------------------------------------------ int main() { - uint32_t sequenceId ; - ledG=0; ledB=0; - -#ifdef USE_CONSOLE - console.printf("start FlashAir iSDIO sample\n"); -#endif - - wait(1.0); - // supply power to SD card - SD_VEN = 1; - wait(5.0); - - if (SD_CD) { -#ifdef USE_CONSOLE - console.printf("SD: Not dected\n"); -#endif - } else { -#ifdef USE_CONSOLE - console.printf("SD: Detected\n"); -#endif + while(true) { + mon(); } - - // Initialize card - FILE *fp = fopen("/sd/isdio.txt", "w"); - fclose(fp); - - wait(15.0); - ledG=1; ledB=1; ledR=0; - - // disconnect - // 1. get sequenceID - // 2. issue disconnect command - // 3. wait response - sequenceId = sd.getNextSequenceId(); - sd.wlan_disconnect(sequenceId); - sd.waitResponse(sequenceId); - wait(5.0); - - ledB = 0; - - // establish - // 1. get sequenceID - // 2. issue establish command - // 3. wait resoonse - sequenceId = sd.getNextSequenceId(); - sd.wlan_establish(sequenceId, (uint8_t*)"isdiotest", (uint8_t*)"12345678", FlashAir_iSDIO::ENCMODE_WPA2PSK_AES); - wait(5.0); - ledG = 0; - - // shared mem - // 1. prepare test data - // 2. write data to shared mem area - // 3. read back and check - #define TESTDATA 0xdeadbeaf - uint32_t testdata = TESTDATA; - uint8_t data[sizeof(testdata)]; - memcpy(data, &testdata, sizeof(data)); - sd.write_shared_mem(0x0, data, sizeof(data)); - memset(data, 0x0, sizeof(data)); - sd.read_shared_mem(0x0, data, sizeof(data)); - - ledG=1; ledB=1; ledR=1; - - for(;;); - }