From f087a578953866f3056bf6312f09f571b0b3c7ab Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 24 Oct 2016 23:01:19 -0500 Subject: [PATCH 01/24] Added support for ESP8266 Fixes #262 --- .travis.yml | 2 +- avrpins.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ library.json | 3 ++- usbhost.h | 2 ++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c9351a50..f8ffbecd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -74,4 +74,4 @@ install: - platformio lib install 62 416 417 script: - - platformio ci --board=uno --board=teensy31 --board=due --lib="." + - platformio ci --board=uno --board=teensy31 --board=due --board=esp12e --board=nodemcu --lib="." diff --git a/avrpins.h b/avrpins.h index b73a6bc6..4b0d37a4 100644 --- a/avrpins.h +++ b/avrpins.h @@ -1242,6 +1242,52 @@ MAKE_PIN(P13, 13); // #undef MAKE_PIN +#elif defined(ESP8266) + +#define pgm_read_pointer(p) pgm_read_ptr(p) + +#define MAKE_PIN(className, pin) \ +class className { \ +public: \ + static void Set() { \ + digitalWrite(pin, HIGH);\ + } \ + static void Clear() { \ + digitalWrite(pin, LOW); \ + } \ + static void SetDirRead() { \ + pinMode(pin, INPUT); \ + } \ + static void SetDirWrite() { \ + pinMode(pin, OUTPUT); \ + } \ + static uint8_t IsSet() { \ + return digitalRead(pin); \ + } \ +}; + +// Pinout for ESP-12 module +// 0 .. 16 - Digital pins +MAKE_PIN(P0, 0); +MAKE_PIN(P1, 1); // TX0 +MAKE_PIN(P2, 2); // TX1 +MAKE_PIN(P3, 3); // RX0 +MAKE_PIN(P4, 4); // SDA +MAKE_PIN(P5, 5); // SCL +MAKE_PIN(P6, 6); +MAKE_PIN(P7, 7); +MAKE_PIN(P8, 8); +MAKE_PIN(P9, 9); +MAKE_PIN(P10, 10); +MAKE_PIN(P11, 11); +MAKE_PIN(P12, 12); // MISO +MAKE_PIN(P13, 13); // MOSI +MAKE_PIN(P14, 14); // SCK +MAKE_PIN(P15, 15); // SS +MAKE_PIN(P16, 16); + +#undef MAKE_PIN + #else #error "Please define board in avrpins.h" diff --git a/library.json b/library.json index a26311d1..7251409b 100644 --- a/library.json +++ b/library.json @@ -49,6 +49,7 @@ "teensy", "atmelsam", "nordicnrf51", - "ststm32" + "ststm32", + "espressif8266" ] } diff --git a/usbhost.h b/usbhost.h index 15a57bd1..b655f44b 100644 --- a/usbhost.h +++ b/usbhost.h @@ -97,6 +97,8 @@ typedef SPi< P13, P11, P12, P10 > spi; typedef SPi< P76, P75, P74, P10 > spi; #elif defined(RBL_NRF51822) typedef SPi< P16, P18, P17, P10 > spi; +#elif defined(ESP8266) +typedef SPi< P14, P13, P12, P15 > spi; #else #error "No SPI entry in usbhost.h" #endif From 6fbe00703a45416821f6429f9eedd75f719eb323 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 24 Oct 2016 23:11:46 -0500 Subject: [PATCH 02/24] Workaround issue with SPI_HAS_TRANSACTION is just defined and not set to a value in the ESP8266 Arduino core --- usbhost.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/usbhost.h b/usbhost.h index b655f44b..8b4fc36b 100644 --- a/usbhost.h +++ b/usbhost.h @@ -39,7 +39,7 @@ public: SPI_SS::SetDirWrite(); SPI_SS::Set(); } -#elif SPI_HAS_TRANSACTION +#elif defined(SPI_HAS_TRANSACTION) static void init() { SPI.begin(); // The SPI library with transaction will take care of setting up the pins - settings is set in beginTransaction() SPI_SS::SetDirWrite(); @@ -154,7 +154,7 @@ MAX3421e< SPI_SS, INTR >::MAX3421e() { template< typename SPI_SS, typename INTR > void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { XMEM_ACQUIRE_SPI(); -#if SPI_HAS_TRANSACTION +#if defined(SPI_HAS_TRANSACTION) SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0)); // The MAX3421E can handle up to 26MHz, use MSB First and SPI mode 0 #endif SPI_SS::Clear(); @@ -164,7 +164,7 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { c[0] = reg | 0x02; c[1] = data; spi4teensy3::send(c, 2); -#elif SPI_HAS_TRANSACTION +#elif defined(SPI_HAS_TRANSACTION) uint8_t c[2]; c[0] = reg | 0x02; c[1] = data; @@ -185,7 +185,7 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { #endif SPI_SS::Set(); -#if SPI_HAS_TRANSACTION +#if defined(SPI_HAS_TRANSACTION) SPI.endTransaction(); #endif XMEM_RELEASE_SPI(); @@ -197,7 +197,7 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { template< typename SPI_SS, typename INTR > uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* data_p) { XMEM_ACQUIRE_SPI(); -#if SPI_HAS_TRANSACTION +#if defined(SPI_HAS_TRANSACTION) SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0)); // The MAX3421E can handle up to 26MHz, use MSB First and SPI mode 0 #endif SPI_SS::Clear(); @@ -206,7 +206,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* spi4teensy3::send(reg | 0x02); spi4teensy3::send(data_p, nbytes); data_p += nbytes; -#elif SPI_HAS_TRANSACTION +#elif defined(SPI_HAS_TRANSACTION) SPI.transfer(reg | 0x02); SPI.transfer(data_p, nbytes); data_p += nbytes; @@ -238,7 +238,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* #endif SPI_SS::Set(); -#if SPI_HAS_TRANSACTION +#if defined(SPI_HAS_TRANSACTION) SPI.endTransaction(); #endif XMEM_RELEASE_SPI(); @@ -260,7 +260,7 @@ void MAX3421e< SPI_SS, INTR >::gpioWr(uint8_t data) { template< typename SPI_SS, typename INTR > uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) { XMEM_ACQUIRE_SPI(); -#if SPI_HAS_TRANSACTION +#if defined(SPI_HAS_TRANSACTION) SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0)); // The MAX3421E can handle up to 26MHz, use MSB First and SPI mode 0 #endif SPI_SS::Clear(); @@ -274,7 +274,7 @@ uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) { uint8_t rv = 0; HAL_SPI_Receive(&SPI_Handle, &rv, 1, HAL_MAX_DELAY); SPI_SS::Set(); -#elif !defined(SPDR) || SPI_HAS_TRANSACTION +#elif !defined(SPDR) || defined(SPI_HAS_TRANSACTION) SPI.transfer(reg); uint8_t rv = SPI.transfer(0); // Send empty byte SPI_SS::Set(); @@ -287,7 +287,7 @@ uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) { uint8_t rv = SPDR; #endif -#if SPI_HAS_TRANSACTION +#if defined(SPI_HAS_TRANSACTION) SPI.endTransaction(); #endif XMEM_RELEASE_SPI(); @@ -299,7 +299,7 @@ uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) { template< typename SPI_SS, typename INTR > uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* data_p) { XMEM_ACQUIRE_SPI(); -#if SPI_HAS_TRANSACTION +#if defined(SPI_HAS_TRANSACTION) SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0)); // The MAX3421E can handle up to 26MHz, use MSB First and SPI mode 0 #endif SPI_SS::Clear(); @@ -308,7 +308,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* spi4teensy3::send(reg); spi4teensy3::receive(data_p, nbytes); data_p += nbytes; -#elif SPI_HAS_TRANSACTION +#elif defined(SPI_HAS_TRANSACTION) SPI.transfer(reg); memset(data_p, 0, nbytes); // Make sure we send out empty bytes SPI.transfer(data_p, nbytes); @@ -350,7 +350,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* #endif SPI_SS::Set(); -#if SPI_HAS_TRANSACTION +#if defined(SPI_HAS_TRANSACTION) SPI.endTransaction(); #endif XMEM_RELEASE_SPI(); From 736eebcc36d097ba9e311bf164f9b0c435dbce92 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 24 Oct 2016 23:20:38 -0500 Subject: [PATCH 03/24] Do not generate warnings for unused functions --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f8ffbecd..225e1c66 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,7 +63,7 @@ env: install: - pip install -U platformio - - export PLATFORMIO_BUILD_FLAGS="-DDEBUG_USB_HOST -DWIICAMERA -Wall -Werror -Wno-strict-aliasing" + - export PLATFORMIO_BUILD_FLAGS="-DDEBUG_USB_HOST -DWIICAMERA -Wall -Werror -Wno-strict-aliasing -Wno-unused-function" # # Libraries from PlatformIO Library Registry: From 58015d611d2bd5fc5774d2c98c134754489797f9 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 24 Oct 2016 23:27:19 -0500 Subject: [PATCH 04/24] Use SPI.writeBytes instead of SPI.transfer on the ESP8266 --- usbhost.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/usbhost.h b/usbhost.h index 8b4fc36b..daff87a7 100644 --- a/usbhost.h +++ b/usbhost.h @@ -168,7 +168,11 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { uint8_t c[2]; c[0] = reg | 0x02; c[1] = data; +#ifdef ESP8266 + SPI.writeBytes(c, 2); +#else SPI.transfer(c, 2); +#endif #elif defined(STM32F4) uint8_t c[2]; c[0] = reg | 0x02; @@ -208,7 +212,11 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* data_p += nbytes; #elif defined(SPI_HAS_TRANSACTION) SPI.transfer(reg | 0x02); +#ifdef ESP8266 + SPI.writeBytes(data_p, nbytes); +#else SPI.transfer(data_p, nbytes); +#endif data_p += nbytes; #elif defined(__ARDUINO_X86__) SPI.transfer(reg | 0x02); @@ -311,7 +319,11 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* #elif defined(SPI_HAS_TRANSACTION) SPI.transfer(reg); memset(data_p, 0, nbytes); // Make sure we send out empty bytes +#ifdef ESP8266 + SPI.writeBytes(data_p, nbytes); +#else SPI.transfer(data_p, nbytes); +#endif data_p += nbytes; #elif defined(__ARDUINO_X86__) SPI.transfer(reg); From aa3731c230343575870c2e031a96a2e619229bec Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 25 Oct 2016 00:06:15 -0500 Subject: [PATCH 05/24] Workaround the following issue: https://github.com/esp8266/Arduino/issues/2078 Also see: https://travis-ci.org/felis/USB_Host_Shield_2.0/jobs/170350078 --- settings.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/settings.h b/settings.h index 1fb371d8..c8856a24 100644 --- a/settings.h +++ b/settings.h @@ -177,4 +177,16 @@ extern SPI_HandleTypeDef SPI_Handle; // Needed to be declared in your main.cpp #define MFK_CASTUINT8T #endif +// Workaround issue: https://github.com/esp8266/Arduino/issues/2078 +#ifdef ESP8266 +#undef PROGMEM +#define PROGMEM +#undef PSTR +#define PSTR(s) (s) +#undef pgm_read_byte +#define pgm_read_byte(addr) (*reinterpret_cast(addr)) +#undef pgm_read_word +#define pgm_read_word(addr) (*reinterpret_cast(addr)) +#endif + #endif /* SETTINGS_H */ From 31570861fe427068f54aa3fe90b85425d4591cc5 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 25 Oct 2016 00:01:55 -0500 Subject: [PATCH 06/24] Updated README --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e7345efb..d77b3bed 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ Currently the following boards are supported by the library: * Please see: . * STM32F4 * Currently the [NUCLEO-F446RE](http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF262063) is supported featuring the STM32F446. Take a look at the following example code: . +* ESP8266 is supported using the [ESP8266 Arduino core](https://github.com/esp8266/Arduino) The following boards need to be activated manually in [settings.h](settings.h): @@ -317,11 +318,11 @@ HID devices are also supported by the library. However these require you to writ ### [MIDI Library](usbh_midi.cpp) -The library support MIDI devices. +The library support MIDI devices. You can convert USB MIDI keyboard to legacy serial MIDI. -* [USB_MIDI_converter.ino](examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino) -* [USB_MIDI_converter_multi.ino](examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino) +* [USB_MIDI_converter.ino](examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino) +* [USB_MIDI_converter_multi.ino](examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino) For information see the following page: . From 238c26908f116ee21ea5f5b320aa46e703eee3ec Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 25 Oct 2016 01:38:24 -0500 Subject: [PATCH 07/24] Use pin 15 and 16 for SS and INT respectivly The Wifio is not supported for now --- README.md | 1 + UsbCore.h | 2 ++ settings.h | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/README.md b/README.md index d77b3bed..01fb8a50 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ Currently the following boards are supported by the library: * STM32F4 * Currently the [NUCLEO-F446RE](http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF262063) is supported featuring the STM32F446. Take a look at the following example code: . * ESP8266 is supported using the [ESP8266 Arduino core](https://github.com/esp8266/Arduino) + * Note it uses pin 15 and 16 for SS and INT respectively The following boards need to be activated manually in [settings.h](settings.h): diff --git a/UsbCore.h b/UsbCore.h index fdec87b0..43703f63 100644 --- a/UsbCore.h +++ b/UsbCore.h @@ -39,6 +39,8 @@ typedef MAX3421e MAX3421E; // Arduino Mega ADK typedef MAX3421e MAX3421E; // Balanduino #elif defined(__ARDUINO_X86__) && PLATFORM_ID == 0x06 typedef MAX3421e MAX3421E; // The Intel Galileo supports much faster read and write speed at pin 2 and 3 +#elif defined(ESP8266) +typedef MAX3421e MAX3421E; // ESP8266 boards #else typedef MAX3421e MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.), Intel Edison, Intel Galileo 2 or Teensy 2.0 and 3.0 #endif diff --git a/settings.h b/settings.h index c8856a24..068bceba 100644 --- a/settings.h +++ b/settings.h @@ -189,4 +189,8 @@ extern SPI_HandleTypeDef SPI_Handle; // Needed to be declared in your main.cpp #define pgm_read_word(addr) (*reinterpret_cast(addr)) #endif +#ifdef ARDUINO_ESP8266_WIFIO +#error "This board is currently not supported" +#endif + #endif /* SETTINGS_H */ From 231fb542a8f42d5ada6325bdb5a3a2e1d8d37348 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 25 Oct 2016 03:23:40 -0500 Subject: [PATCH 08/24] SPI pins are defined in newer version of Arduino See: https://github.com/arduino/Arduino/pull/4814 --- usbhost.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/usbhost.h b/usbhost.h index daff87a7..3e8bd7a8 100644 --- a/usbhost.h +++ b/usbhost.h @@ -85,7 +85,19 @@ public: }; /* SPI pin definitions. see avrpins.h */ -#if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) +#if defined(PIN_SPI_SCK) && defined(PIN_SPI_MOSI) && defined(PIN_SPI_MISO) && defined(PIN_SPI_SS) +// Use pin defines: https://github.com/arduino/Arduino/pull/4814 +// Based on: https://www.mikeash.com/pyblog/friday-qa-2015-03-20-preprocessor-abuse-and-optional-parentheses.html +#define NOTHING_EXTRACT +#define EXTRACT(...) EXTRACT __VA_ARGS__ +#define PASTE(x, ...) x ## __VA_ARGS__ +#define EVALUATING_PASTE(x, ...) PASTE(x, __VA_ARGS__) +#define UNPAREN(x) EVALUATING_PASTE(NOTHING_, EXTRACT x) +#define APPEND_PIN(pin) P ## pin // Appends the pin to 'P', e.g. 1 becomes P1 +#define MAKE_PIN(x) EVALUATING_PASTE(APPEND_, PIN(UNPAREN(x))) +typedef SPi< MAKE_PIN(PIN_SPI_SCK), MAKE_PIN(PIN_SPI_MOSI), MAKE_PIN(PIN_SPI_MISO), MAKE_PIN(PIN_SPI_SS) > spi; +#undef MAKE_PIN +#elif defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) typedef SPi< Pb1, Pb2, Pb3, Pb0 > spi; #elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) typedef SPi< Pb5, Pb3, Pb4, Pb2 > spi; From 6af321a7ac6c735f8fc8e3224e2c408cac7625b2 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 26 Oct 2016 00:58:51 -0500 Subject: [PATCH 09/24] Use transferBytes when we want to receive data --- usbhost.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usbhost.h b/usbhost.h index 3e8bd7a8..6eb8d663 100644 --- a/usbhost.h +++ b/usbhost.h @@ -332,11 +332,11 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* SPI.transfer(reg); memset(data_p, 0, nbytes); // Make sure we send out empty bytes #ifdef ESP8266 - SPI.writeBytes(data_p, nbytes); + SPI.transferBytes(data_p, data_p, nbytes); #else SPI.transfer(data_p, nbytes); -#endif data_p += nbytes; +#endif #elif defined(__ARDUINO_X86__) SPI.transfer(reg); SPI.transferBuffer(NULL, data_p, nbytes); From dc2a224d2e6e683be4fa6c11743fd14c0ee07052 Mon Sep 17 00:00:00 2001 From: huming2207 Date: Wed, 2 Nov 2016 23:13:09 +1100 Subject: [PATCH 10/24] Change INT pin to GPIO0 temporarily as it cannot attach interrupt. --- README.md | 5 ++++- UsbCore.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 01fb8a50..a8b415bc 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,10 @@ Currently the following boards are supported by the library: * STM32F4 * Currently the [NUCLEO-F446RE](http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF262063) is supported featuring the STM32F446. Take a look at the following example code: . * ESP8266 is supported using the [ESP8266 Arduino core](https://github.com/esp8266/Arduino) - * Note it uses pin 15 and 16 for SS and INT respectively + * Note it uses pin 15 and 0 for SS and INT respectively + * Also please be aware that: + * GPIO16 is **NOT** usable, as it will be used for some other purposes. For example, reset the SoC itself from sleep mode. + * GPIO6 to 11 is also **NOT** usable, as they are used to connect SPI flash chip and it is used for storing the executable binary content. The following boards need to be activated manually in [settings.h](settings.h): diff --git a/UsbCore.h b/UsbCore.h index 43703f63..f9fc6641 100644 --- a/UsbCore.h +++ b/UsbCore.h @@ -40,7 +40,7 @@ typedef MAX3421e MAX3421E; // Balanduino #elif defined(__ARDUINO_X86__) && PLATFORM_ID == 0x06 typedef MAX3421e MAX3421E; // The Intel Galileo supports much faster read and write speed at pin 2 and 3 #elif defined(ESP8266) -typedef MAX3421e MAX3421E; // ESP8266 boards +typedef MAX3421e MAX3421E; // ESP8266 boards #else typedef MAX3421e MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.), Intel Edison, Intel Galileo 2 or Teensy 2.0 and 3.0 #endif From 03ba29ca246471427d8abb9a71dc413d77d6ef60 Mon Sep 17 00:00:00 2001 From: huming2207 Date: Wed, 2 Nov 2016 23:15:08 +1100 Subject: [PATCH 11/24] Remove unusable pins --- avrpins.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/avrpins.h b/avrpins.h index 4b0d37a4..76445e47 100644 --- a/avrpins.h +++ b/avrpins.h @@ -1268,23 +1268,18 @@ public: \ // Pinout for ESP-12 module // 0 .. 16 - Digital pins +// GPIO 6 to 11 and 16 are not usable in this library. + MAKE_PIN(P0, 0); MAKE_PIN(P1, 1); // TX0 MAKE_PIN(P2, 2); // TX1 MAKE_PIN(P3, 3); // RX0 MAKE_PIN(P4, 4); // SDA MAKE_PIN(P5, 5); // SCL -MAKE_PIN(P6, 6); -MAKE_PIN(P7, 7); -MAKE_PIN(P8, 8); -MAKE_PIN(P9, 9); -MAKE_PIN(P10, 10); -MAKE_PIN(P11, 11); MAKE_PIN(P12, 12); // MISO MAKE_PIN(P13, 13); // MOSI MAKE_PIN(P14, 14); // SCK MAKE_PIN(P15, 15); // SS -MAKE_PIN(P16, 16); #undef MAKE_PIN From 8f44b6247077adcd2b1524a0f84ee5126f501cc0 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 1 Feb 2017 11:20:09 +0100 Subject: [PATCH 12/24] Only define WIICAMERA for WiiIRCamera example --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0cdc4828..8a0adf38 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,7 @@ env: - PLATFORMIO_CI_SRC=examples/Bluetooth/SPPMulti - PLATFORMIO_CI_SRC=examples/Bluetooth/Wii - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiBalanceBoard - - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiIRCamera + - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiIRCamera PLATFORMIO_BUILD_FLAGS="-DWIICAMERA" - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiMulti - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiUProController - PLATFORMIO_CI_SRC=examples/board_qc @@ -63,7 +63,7 @@ env: install: - pip install -U platformio - - export PLATFORMIO_BUILD_FLAGS="-DDEBUG_USB_HOST -DWIICAMERA -Wall -Werror -Wno-unused-function" + - export PLATFORMIO_BUILD_FLAGS="$PLATFORMIO_BUILD_FLAGS -DDEBUG_USB_HOST -Wall -Werror -Wno-unused-function" # # Libraries from PlatformIO Library Registry: From 14cf737d7d4c1ca77e85a8946ad147a6da5457e4 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 1 Feb 2017 11:26:35 +0100 Subject: [PATCH 13/24] Only ignore unused functions when building for the ESP8266 This should be removed when the ESP8266 core is updated in PlatformIO: https://github.com/esp8266/Arduino/pull/2881 --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8a0adf38..afd87022 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,7 +63,7 @@ env: install: - pip install -U platformio - - export PLATFORMIO_BUILD_FLAGS="$PLATFORMIO_BUILD_FLAGS -DDEBUG_USB_HOST -Wall -Werror -Wno-unused-function" + - export PLATFORMIO_BUILD_FLAGS="$PLATFORMIO_BUILD_FLAGS -DDEBUG_USB_HOST -Wall -Werror" # # Libraries from PlatformIO Library Registry: @@ -74,4 +74,6 @@ install: - platformio lib install 62 416 417 script: - - platformio ci --board=uno --board=due --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc --board=esp12e --board=nodemcu --lib="." + - platformio ci --lib="." --board=uno --board=due --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc + - export PLATFORMIO_BUILD_FLAGS="$PLATFORMIO_BUILD_FLAGS -Wno-unused-function" # Workaround https://github.com/esp8266/Arduino/pull/2881 + - platformio ci --lib="." --board=esp12e --board=nodemcu From 7b0487da80d71729a9dbe92100c23eb9915e094e Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 1 Feb 2017 16:53:31 +0100 Subject: [PATCH 14/24] Try to set build flags --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index afd87022..23434961 100644 --- a/.travis.yml +++ b/.travis.yml @@ -75,5 +75,4 @@ install: script: - platformio ci --lib="." --board=uno --board=due --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc - - export PLATFORMIO_BUILD_FLAGS="$PLATFORMIO_BUILD_FLAGS -Wno-unused-function" # Workaround https://github.com/esp8266/Arduino/pull/2881 - - platformio ci --lib="." --board=esp12e --board=nodemcu + - platformio ci --verbose --lib="." --board=esp12e --board=nodemcu --project-option="build_flags=-Wno-unused-function" # Workaround https://github.com/esp8266/Arduino/pull/2881 From 3952d900ff3381f9562da8a07b29eb3cfa23f788 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 14 Feb 2017 00:27:35 +0100 Subject: [PATCH 15/24] Reset the watchdog timer on the ESP8266 See: https://github.com/felis/USB_Host_Shield_2.0/pull/263#issuecomment-279222338 --- examples/board_qc/board_qc.ino | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/examples/board_qc/board_qc.ino b/examples/board_qc/board_qc.ino index 573c3ce0..12d70c6c 100644 --- a/examples/board_qc/board_qc.ino +++ b/examples/board_qc/board_qc.ino @@ -60,6 +60,9 @@ void setup() { uint8_t sample_rd = 0; uint8_t gpinpol_copy = Usb.regRd(rGPINPOL); for(uint8_t i = 0; i < 16; i++) { +#ifdef ESP8266 + yield(); // needed in order to reset the watchdog timer on the ESP8266 +#endif for(uint16_t j = 0; j < 65535; j++) { Usb.regWr(rGPINPOL, sample_wr); sample_rd = Usb.regRd(rGPINPOL); @@ -206,7 +209,11 @@ void loop() { print_hex(buf.bNumConfigurations, 8); /**/ E_Notify(PSTR("\r\n\nAll tests passed. Press RESET to restart test"), 0x80); - while(1); + while(1) { +#ifdef ESP8266 + yield(); // needed in order to reset the watchdog timer on the ESP8266 +#endif + } } break; case( USB_STATE_ERROR): @@ -228,6 +235,9 @@ void halt55() { while(1) { Usb.regWr(0x55, 0x55); +#ifdef ESP8266 + yield(); // needed in order to reset the watchdog timer on the ESP8266 +#endif } } @@ -253,7 +263,11 @@ void print_hex(int v, int num_places) { /* prints "Press any key" and returns when key is pressed */ void press_any_key() { E_Notify(PSTR("\r\nPress any key to continue..."), 0x80); - while(Serial.available() <= 0); //wait for input + while(Serial.available() <= 0) { // wait for input +#ifdef ESP8266 + yield(); // needed in order to reset the watchdog timer on the ESP8266 +#endif + } Serial.read(); //empty input buffer return; } From 9de76a07dca539a238f6739328dd603d324689b3 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 22 Mar 2017 14:10:39 +0100 Subject: [PATCH 16/24] 14cf737d7d4c1ca77e85a8946ad147a6da5457e4 is no longer needed --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b9c00915..5d8ffb65 100644 --- a/.travis.yml +++ b/.travis.yml @@ -74,6 +74,4 @@ install: - platformio lib install 62 416 417 script: - - platformio ci --lib="." --board=uno --board=due --board=genuino101 --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc - - export PLATFORMIO_BUILD_FLAGS="$PLATFORMIO_BUILD_FLAGS -Wno-unused-function" # Workaround https://github.com/esp8266/Arduino/pull/2881 - - platformio ci --lib="." --board=esp12e --board=nodemcu + - platformio ci --lib="." --board=uno --board=due --board=genuino101 --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc --board=esp12e --board=nodemcu From 18a36f8627f0f3ed80d34e5a4171ee773d679028 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 11 May 2017 17:55:13 +0200 Subject: [PATCH 17/24] Split variable to prevent warnings on the ESP8266 platform See: https://travis-ci.org/felis/USB_Host_Shield_2.0/jobs/230952435#L1149 --- examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino b/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino index 397acdcb..5706b992 100644 --- a/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino +++ b/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino @@ -69,7 +69,8 @@ void MIDI_poll() pid = Midi.pid; } if (Midi.RecvData( &rcvd, bufMidi) == 0 ) { - sprintf(buf, "%08lX: ", (uint32_t)millis()); + uint32_t time = (uint32_t)millis(); + sprintf(buf, "%04X%04X: ", (uint16_t)(time >> 16), (uint16_t)(time & 0xFFFF)); // Split variable to prevent warnings on the ESP8266 platform Serial.print(buf); Serial.print(rcvd); Serial.print(':'); From a057d83d5e5a5dd3129edd3b793dbbef3462087e Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 6 Jun 2017 23:38:38 +0200 Subject: [PATCH 18/24] Do not use fixed width integer types for the TinyGPS example, as this causes issues on the ESP8266 platform --- examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino index 8b30622d..af13b6bc 100644 --- a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino +++ b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino @@ -150,12 +150,12 @@ void printFloat(double number, int16_t digits) void gpsdump(TinyGPS &gps) { - int32_t lat, lon; + long lat, lon; float flat, flon; - uint32_t age, date, time, chars; - int16_t year; + unsigned long age, date, time, chars; + int year; uint8_t month, day, hour, minute, second, hundredths; - uint16_t sentences, failed; + unsigned short sentences, failed; gps.get_position(&lat, &lon, &age); Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon); @@ -175,7 +175,7 @@ void gpsdump(TinyGPS &gps) feedgps(); - gps.crack_datetime((int*)&year, &month, &day, &hour, &minute, &second, &hundredths, &age); + gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age); Serial.print("Date: "); Serial.print(static_cast(month)); Serial.print("/"); Serial.print(static_cast(day)); Serial.print("/"); Serial.print(year); Serial.print(" Time: "); Serial.print(static_cast(hour)); Serial.print(":"); Serial.print(static_cast(minute)); Serial.print(":"); Serial.print(static_cast(second)); Serial.print("."); Serial.print(static_cast(hundredths)); Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms."); @@ -189,7 +189,7 @@ void gpsdump(TinyGPS &gps) feedgps(); - gps.stats(&chars, (unsigned short*)&sentences, (unsigned short*)&failed); + gps.stats(&chars, &sentences, &failed); Serial.print("Stats: characters: "); Serial.print(chars); Serial.print(" sentences: "); Serial.print(sentences); Serial.print(" failed checksum: "); Serial.println(failed); } From a68614a2e8466a663505025abde6dd4e4344fbf6 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 13 Jun 2017 11:55:05 +0200 Subject: [PATCH 19/24] The data needs to be aligned to 32-bit when sending using SPI.writeBytes and SPI.transferBytes for the ESP8266 --- usbhost.h | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/usbhost.h b/usbhost.h index 62e4fbb2..e5eecbb1 100644 --- a/usbhost.h +++ b/usbhost.h @@ -177,12 +177,15 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { c[1] = data; spi4teensy3::send(c, 2); #elif defined(SPI_HAS_TRANSACTION) +#ifdef ESP8266 + uint32_t c[2]; // The data needs to be aligned to 32-bit + c[0] = reg | 0x02; + c[1] = data; + SPI.writeBytes(c, 2); +#else uint8_t c[2]; c[0] = reg | 0x02; c[1] = data; -#ifdef ESP8266 - SPI.writeBytes(c, 2); -#else SPI.transfer(c, 2); #endif #elif defined(STM32F4) @@ -222,13 +225,9 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* spi4teensy3::send(reg | 0x02); spi4teensy3::send(data_p, nbytes); data_p += nbytes; -#elif defined(SPI_HAS_TRANSACTION) +#elif defined(SPI_HAS_TRANSACTION) && !defined(ESP8266) SPI.transfer(reg | 0x02); -#ifdef ESP8266 - SPI.writeBytes(data_p, nbytes); -#else SPI.transfer(data_p, nbytes); -#endif data_p += nbytes; #elif defined(__ARDUINO_X86__) SPI.transfer(reg | 0x02); @@ -239,7 +238,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* HAL_SPI_Transmit(&SPI_Handle, &data, 1, HAL_MAX_DELAY); HAL_SPI_Transmit(&SPI_Handle, data_p, nbytes, HAL_MAX_DELAY); data_p += nbytes; -#elif !defined(SPDR) +#elif !defined(SPDR) // ESP8266 SPI.transfer(reg | 0x02); while(nbytes) { SPI.transfer(*data_p); @@ -328,15 +327,11 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* spi4teensy3::send(reg); spi4teensy3::receive(data_p, nbytes); data_p += nbytes; -#elif defined(SPI_HAS_TRANSACTION) +#elif defined(SPI_HAS_TRANSACTION) && !defined(ESP8266) SPI.transfer(reg); memset(data_p, 0, nbytes); // Make sure we send out empty bytes -#ifdef ESP8266 - SPI.transferBytes(data_p, data_p, nbytes); -#else SPI.transfer(data_p, nbytes); data_p += nbytes; -#endif #elif defined(__ARDUINO_X86__) SPI.transfer(reg); SPI.transferBuffer(NULL, data_p, nbytes); @@ -346,7 +341,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* memset(data_p, 0, nbytes); // Make sure we send out empty bytes HAL_SPI_Receive(&SPI_Handle, data_p, nbytes, HAL_MAX_DELAY); data_p += nbytes; -#elif !defined(SPDR) +#elif !defined(SPDR) // ESP8266 SPI.transfer(reg); while(nbytes) { *data_p++ = SPI.transfer(0); From 453a4e1f7f1211d3c04dd1823135163b89c8de5f Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 13 Jun 2017 12:18:40 +0200 Subject: [PATCH 20/24] Explicit cast the data to an uint8_t pointer It is then cast back to uint32_t in the SPI library: https://github.com/esp8266/Arduino/blob/40c159fcf5c5ecf9edec8e7ada49c82ece19e6d0/libraries/SPI/SPI.cpp#L402 --- usbhost.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usbhost.h b/usbhost.h index e5eecbb1..e434ed7d 100644 --- a/usbhost.h +++ b/usbhost.h @@ -181,7 +181,7 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { uint32_t c[2]; // The data needs to be aligned to 32-bit c[0] = reg | 0x02; c[1] = data; - SPI.writeBytes(c, 2); + SPI.writeBytes((uint8_t*)c, 2); #else uint8_t c[2]; c[0] = reg | 0x02; From 84bab2d74849ef32fe14b9c2b748439a8002628e Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 13 Jun 2017 12:40:07 +0200 Subject: [PATCH 21/24] Do not use SPI.writeBytes on the ESP8266 --- usbhost.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/usbhost.h b/usbhost.h index e434ed7d..8f97121e 100644 --- a/usbhost.h +++ b/usbhost.h @@ -176,24 +176,17 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { c[0] = reg | 0x02; c[1] = data; spi4teensy3::send(c, 2); -#elif defined(SPI_HAS_TRANSACTION) -#ifdef ESP8266 - uint32_t c[2]; // The data needs to be aligned to 32-bit - c[0] = reg | 0x02; - c[1] = data; - SPI.writeBytes((uint8_t*)c, 2); -#else +#elif defined(SPI_HAS_TRANSACTION) && !defined(ESP8266) uint8_t c[2]; c[0] = reg | 0x02; c[1] = data; SPI.transfer(c, 2); -#endif #elif defined(STM32F4) uint8_t c[2]; c[0] = reg | 0x02; c[1] = data; HAL_SPI_Transmit(&SPI_Handle, c, 2, HAL_MAX_DELAY); -#elif !defined(SPDR) +#elif !defined(SPDR) // ESP8266 SPI.transfer(reg | 0x02); SPI.transfer(data); #else From c2b6dbf94300ae70d1230a266ba3df1255ecb300 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 13 Jun 2017 12:57:27 +0200 Subject: [PATCH 22/24] Use pin 5 for INT on the ESP8266 --- README.md | 2 +- UsbCore.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3246f733..9a42558e 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ Currently the following boards are supported by the library: * STM32F4 * Currently the [NUCLEO-F446RE](http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF262063) is supported featuring the STM32F446. Take a look at the following example code: . * ESP8266 is supported using the [ESP8266 Arduino core](https://github.com/esp8266/Arduino) - * Note it uses pin 15 and 0 for SS and INT respectively + * Note it uses pin 15 and 5 for SS and INT respectively * Also please be aware that: * GPIO16 is **NOT** usable, as it will be used for some other purposes. For example, reset the SoC itself from sleep mode. * GPIO6 to 11 is also **NOT** usable, as they are used to connect SPI flash chip and it is used for storing the executable binary content. diff --git a/UsbCore.h b/UsbCore.h index 3374b640..f78300ca 100644 --- a/UsbCore.h +++ b/UsbCore.h @@ -40,7 +40,7 @@ typedef MAX3421e MAX3421E; // Balanduino #elif defined(__ARDUINO_X86__) && PLATFORM_ID == 0x06 typedef MAX3421e MAX3421E; // The Intel Galileo supports much faster read and write speed at pin 2 and 3 #elif defined(ESP8266) -typedef MAX3421e MAX3421E; // ESP8266 boards +typedef MAX3421e MAX3421E; // ESP8266 boards #else typedef MAX3421e MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.), Intel Edison, Intel Galileo 2 or Teensy 2.0 and 3.x #endif From da253b25bc2e77424df217622ea46c99e9033ca5 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 13 Jun 2017 12:57:56 +0200 Subject: [PATCH 23/24] Reset the watchdog timer on the ESP8266 when the sketch is done --- examples/USB_desc/USB_desc.ino | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/USB_desc/USB_desc.ino b/examples/USB_desc/USB_desc.ino index cda8505c..8341c503 100644 --- a/examples/USB_desc/USB_desc.ino +++ b/examples/USB_desc/USB_desc.ino @@ -104,7 +104,11 @@ void loop() Usb.ForEachUsbDevice(&PrintAllDescriptors); Usb.ForEachUsbDevice(&PrintAllAddresses); - while ( 1 ); //stop + while ( 1 ) { // stop +#ifdef ESP8266 + yield(); // needed in order to reset the watchdog timer on the ESP8266 +#endif + } } } From c8b7c9a0180500c89caac5a7804c17f47e6b14e9 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 13 Jun 2017 13:02:15 +0200 Subject: [PATCH 24/24] Added yield() inside the for-loops as well --- examples/board_qc/board_qc.ino | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/board_qc/board_qc.ino b/examples/board_qc/board_qc.ino index 12d70c6c..8ff41dda 100644 --- a/examples/board_qc/board_qc.ino +++ b/examples/board_qc/board_qc.ino @@ -88,6 +88,9 @@ void setup() { uint8_t tmpbyte; E_Notify(PSTR("\r\nGPIO test. Connect GPIN0 to GPOUT7, GPIN1 to GPOUT6, and so on"), 0x80); for(uint8_t sample_gpio = 0; sample_gpio < 255; sample_gpio++) { +#ifdef ESP8266 + yield(); // needed in order to reset the watchdog timer on the ESP8266 +#endif Usb.gpioWr(sample_gpio); tmpbyte = Usb.gpioRd(); /* bit reversing code copied vetbatim from http://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious */ @@ -115,6 +118,9 @@ void setup() { /* Restart oscillator */ E_Notify(PSTR("\r\nResetting oscillator\r\n"), 0x80); for(uint16_t i = 0; i < 100; i++) { +#ifdef ESP8266 + yield(); // needed in order to reset the watchdog timer on the ESP8266 +#endif E_Notify(PSTR("\rReset number "), 0x80); Serial.print(i, DEC); Usb.regWr(rUSBCTL, bmCHIPRES); //reset