ESP32 Featherwing Bootloader Can't Maintain Stable Serial

For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
hydroArgentum
 
Posts: 4
Joined: Mon Jan 11, 2016 4:07 pm

ESP32 Featherwing Bootloader Can't Maintain Stable Serial

Post by hydroArgentum »

I was trying to update my Adafruit AirLift FeatherWing - ESP32 WiFi Co-Processor using the Adafruit Feather nRF52840 Express. However, I seem to be encountering some difficulties. Here are the steps I've taken:

First, I soldered the pads of the ESPRX, ESPTX, and ESPGPIO0 on the back of the FeatherWing.

Second, I put the nRF52840 in bootloader mode, downloaded Adafruit-Feather-NRF52840-FeatherWing-Passthru.UF2 from the guide, and copied it to the feather's BOOT drive.

Next, I installed esptool on Python 3.9.7 using pip.

After that, I downloaded NINA_W102-1.7.4.bin from the guide and ran (my Feather's on COM3 when running in normal mode):

Code: Select all

esptool.py --port COM3 --before no_reset --baud 115200 write_flash 0 NINA_W102-1.7.4.bin
And I get this error:
A fatal error occurred: Failed to connect to Espressif device: Invalid head of packet (0x00)

So, then, I attempted to use the SerialESPPassthrough.ino from the same guide. When I tried verifying the Arduino sketch, some errors regarding Serial. So, I decided to look around and eventually found to add "#include "Adafruit_TinyUSB.h"" to the sketch.

Verifying and uploading this SerialESPPassthrough.ino is possible:

Code: Select all

#include <Adafruit_NeoPixel.h>
#include "Adafruit_TinyUSB.h"

unsigned long baud = 115200;

#if defined(ADAFRUIT_FEATHER_M4_EXPRESS) || \
  defined(ADAFRUIT_FEATHER_M0_EXPRESS) || \
  defined(ARDUINO_AVR_FEATHER32U4) || \
  defined(ARDUINO_NRF52840_FEATHER) || \
  defined(ADAFRUIT_ITSYBITSY_M0) || \
  defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS) || \
  defined(ARDUINO_AVR_ITSYBITSY32U4_3V) || \
  defined(ARDUINO_NRF52_ITSYBITSY)
  // Configure the pins used for the ESP32 connection
  #define SerialESP32   Serial1
  #define SPIWIFI       SPI  // The SPI port
  #define SPIWIFI_SS    13   // Chip select pin
  #define ESP32_RESETN  12   // Reset pin
  #define SPIWIFI_ACK   11   // a.k.a BUSY or READY pin
  #define ESP32_GPIO0   10
  #define NEOPIXEL_PIN   8
#elif defined(ARDUINO_AVR_FEATHER328P)
  #define SerialESP32   Serial1
  #define SPIWIFI       SPI  // The SPI port
  #define SPIWIFI_SS     4   // Chip select pin
  #define ESP32_RESETN   3   // Reset pin
  #define SPIWIFI_ACK    2   // a.k.a BUSY or READY pin
  #define ESP32_GPIO0   -1
  #define NEOPIXEL_PIN   8
#elif defined(TEENSYDUINO)
  #define SerialESP32   Serial1
  #define SPIWIFI       SPI  // The SPI port
  #define SPIWIFI_SS     5   // Chip select pin
  #define ESP32_RESETN   6   // Reset pin
  #define SPIWIFI_ACK    9   // a.k.a BUSY or READY pin
  #define ESP32_GPIO0   -1
  #define NEOPIXEL_PIN   8
#elif defined(ARDUINO_NRF52832_FEATHER )
  #define SerialESP32   Serial1
  #define SPIWIFI       SPI  // The SPI port
  #define SPIWIFI_SS    16  // Chip select pin
  #define ESP32_RESETN  15  // Reset pin
  #define SPIWIFI_ACK    7  // a.k.a BUSY or READY pin
  #define ESP32_GPIO0   -1
  #define NEOPIXEL_PIN   8
#elif !defined(SPIWIFI_SS)  // if the wifi definition isnt in the board variant
  // Don't change the names of these #define's! they match the variant ones
  #define SerialESP32   Serial1
  #define SPIWIFI       SPI
  #define SPIWIFI_SS    10   // Chip select pin
  #define SPIWIFI_ACK    7   // a.k.a BUSY or READY pin
  #define ESP32_RESETN   5   // Reset pin
  #define ESP32_GPIO0   -1   // Not connected
  #define NEOPIXEL_PIN   8
#endif

#if defined(ADAFRUIT_PYPORTAL)
  #define PIN_NEOPIXEL   2
#elif defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE)
  #define PIN_NEOPIXEL   40
#endif

Adafruit_NeoPixel pixel = Adafruit_NeoPixel(1, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);

void setup() {
  Serial.begin(baud);
  pixel.begin();
  pixel.setPixelColor(0, 10, 10, 10); pixel.show();

  while (!Serial);
  pixel.setPixelColor(0, 50, 50, 50); pixel.show();

  delay(100);
  SerialESP32.begin(baud);

  pinMode(SPIWIFI_SS, OUTPUT);
  pinMode(ESP32_GPIO0, OUTPUT);
  pinMode(ESP32_RESETN, OUTPUT);
  
  // manually put the ESP32 in upload mode
  digitalWrite(ESP32_GPIO0, LOW);
  digitalWrite(SPIWIFI_SS, LOW);

  delay(100);
  digitalWrite(ESP32_RESETN, LOW);
  delay(100);
  digitalWrite(ESP32_RESETN, HIGH);
  pixel.setPixelColor(0, 20, 20, 0); pixel.show();
  delay(100);
}

void loop() {
  while (Serial.available()) {
    pixel.setPixelColor(0, 10, 0, 0); pixel.show();
    SerialESP32.write(Serial.read());
  }

  while (SerialESP32.available()) {
    pixel.setPixelColor(0, 0, 0, 10); pixel.show();
    Serial.write(SerialESP32.read());
  }
}
Uploading this and running the esptool command again ends up with the same error:
A fatal error occurred: Failed to connect to Espressif device: Invalid head of packet (0x00)

I can run the example networkscan sketch from WiFiNINA, which seems to work even when the pads are soldered, so I can confirm that the ESP32 is working in standard mode.

So, before posting this, I began poking around again, and I found that, when opening the Serial Monitor after running the sketch, I can see:

Code: Select all

ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x3 (D
Looking at this, I noticed that the "(D" in the end seems to be cut off of something. Searching for more information, that line should be "rst:0x1 (POWERON_RESET),boot:0x3 (DOWNLOAD_BOOT(UART0/UART1/SDIO_REI_REO_V2))" and the next line should say "waiting for download", but for some reason, the serial communication seems to fail before it can reach that point. I've also verified that the .UF2 method also behaves the same way.

Is there something I can do in this scenario? I've been scouring for any information and thinking of other ways to try and approach this issue, but I've seem to have come to an impasse.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: ESP32 Featherwing Bootloader Can't Maintain Stable Seria

Post by mikeysklar »

Do you think the update might have worked with the AirLift and you need to proceed with removing the AirLift temporary solder points you had done pre-upgrade and trying the ScanNetworks script.

https://learn.adafruit.com/adafruit-air ... 3041621-35
Verifying the Upgraded Firmware Version
To verify everything is working correctly, we'll load up either an Arduino sketch or CircuitPython code. At this point, you must desolder the connections between the Optional ESP32 control pins you made earlier using a solder sucker or a bit of solder wick.
Arduino
If you were previously using your ESP32 with Arduino, you should load up an Arduino sketch to verify everything is working properly and the version of the nina-fw correlates with the version the sketch reads.

Open up File->Examples->WiFiNINA->ScanNetworks and upload the sketch. Then, open the Serial Monitor. You should see the firmware version printed out to the serial monitor.

User avatar
hydroArgentum
 
Posts: 4
Joined: Mon Jan 11, 2016 4:07 pm

Re: ESP32 Featherwing Bootloader Can't Maintain Stable Seria

Post by hydroArgentum »

Unfortunately, I don't think that the update took. But to make sure, I've removed the solder from the pads (verifying the disconnection with a continuity check) and re-ran the ScanNetworks sketch.

The serial monitor prints out:

Code: Select all

WiFi Scanning test
1.2.2
Firmware OK
Then prints the MAC, and then the 10 WiFi APs with the strongest signals near me.

I believe that, upon successful update using NINA_W102-1.7.4.bin, the second line should have printed as 1.7.4.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: ESP32 Featherwing Bootloader Can't Maintain Stable Seria

Post by mikeysklar »

Are you using the Airlift ESP32 Featherwing stacked on top of your Feather nRF52 or are you manually wiring connections?

When uploading the SerialESPPassthrough.ino were the ESP pads already soldered. I believe you need to upload the Arduino pass through sketch before soldering.

If you have these stacked could you post a photo of soldering on the headers for both the Airlift and Feather nRF52.

User avatar
hydroArgentum
 
Posts: 4
Joined: Mon Jan 11, 2016 4:07 pm

Re: ESP32 Featherwing Bootloader Can't Maintain Stable Seria

Post by hydroArgentum »

I'm stacking the two boards together. My Feather nRF is on top (because I accidentally switched the headers... fortunately, it does make it easy to hit the UserSW + RESET to go to the bootloader mode) and the ESP32 is on bottom.

Before writing this, I tried removing the ESP32 Feathering and uploading the SerialESPPassthrough sketch. I'm still getting the error:
A fatal error occurred: Failed to connect to Espressif device: Invalid head of packet (0x00)

So, I began poking around some more and I realized that I could spy on the UART communication and print additional information by adding the "--trace" argument to the esptool command. Though this, I came upon some bad news:

First, here a few lines of what is received by the nRF in the Serial communication:

Code: Select all

\r
rst:0x1 (POWERON_RESET),boot:0x2 (DOWNLOAD_BOOT(UART0/UART1/SDIO_REI_FEO_V2))\r
waiting for download\r
\0ets Jul 29 2019 12:21:46\r
\r
rst:0x1 (POWERON_RESET),boot:0x2 (DOWNLOAD_BOOT(UART0/UART1/SDIO_REI_FEO_V2))\r
waiting for download\r
\x01\b\x04\0 UUU\0\0\0\0
\x01\b\x04\0 UUU\0\0\0\0
\x01\b\x04\0 UUU\0\0\0\0
\x01\b\x04\0 UUU\0\0\0\0
\x01\b\x04\0 UUU\0\0\0\0
\x01\b\x04\0 UUU\0\0\0\0
\x01\b\x04\0 UUU\0\0\0\0
\x01\b\x04\0 UUU\0\0\0\0
\x01\b\x04\0\a\a\x12 \0\0\0\0
\x01\b\x04\0\a\a\x12 \0\0\0\0
\x01\b\x04\0\a\a\x12 \0\0\0\0
\x01\b\x04\0\a\a\x12 \0\0\0\0
\x01\b\x04\0\a\a\x12 \0\0\0\0
\x01\b\x04\0\a\a\x12 \0\0\0\0
\x01\b\x04\0\a\a\x12 \0\0\0\0
\x01\b\x04\0\a\a\x12 \0\0\0\0
A couple things I learned here:
  • Each newline in the output (where the line isn't preceded by an '/r') above starts and ends with 0xc0 (I removed the character as the forum considers it spam). This byte is used to start and end packets when communicating with the ESP32 bootloader.
  • Even though I had trouble with printing the whole bootloader message in Serial Monitor, spying on the serial lines shows that the complete message was received by the nRF.
  • \x01\b\x04\0\a\a\x12 \0\0\0\0 -> 0x010804000707122000000000 after converting it to hex.
This 3rd bullet point is the expected behavior of the ESP32 bootloader. As explained by projectgus, esptool expects that the ESP32 bootloader sends the same exact response packet 8 consecutive times for the communication between esptool and the ESP bootloader to be considered successful: https://github.com/espressif/esptool/issues/570

Spying on the Serial communication shows that the identical response packet was received by the nRF from the ESP at least 8 times, so I tried looking at the esptool trace logs (this is just a snippet of one single round of call and response):

Code: Select all

TRACE +0.064 command op=0x08 data len=36 wait_response=1 timeout=0.100 data=
    0707122055555555 5555555555555555 | ... UUUUUUUUUUUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    55555555                          | UUUU
TRACE +0.000 Write 46 bytes:
    c000082400000000 0007071220555555 | ...$........ UUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    5555555555555555 5555555555c0     | UUUUUUUUUUUUU.
TRACE +0.054 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.008 Read 7 bytes: 08040007071220
TRACE +0.000 Read 1 bytes: 00
TRACE +0.000 Read 2 bytes: 0000
TRACE +0.000 Read 2 bytes: 00c0
TRACE +0.005 Received full packet: 010804000707122000000000
TRACE +0.005 Read 7 bytes: c0010804000707
TRACE +0.005 Read 5 bytes: 1220000000
TRACE +0.000 Read 1 bytes: 00
TRACE +0.000 Read 1 bytes: c0
TRACE +0.000 Received full packet: 010804000707122000000000
TRACE +0.011 Read 8 bytes: c001080400070712
TRACE +0.000 Read 1 bytes: 20
TRACE +0.001 Read 1 bytes: 00
TRACE +0.004 Read 3 bytes: 000000
TRACE +0.000 Read 2 bytes: c0c0
TRACE +0.001 Received full packet: 010804000707122000000000
TRACE +0.002 Read 4 bytes: 01080400
TRACE +0.000 Read 1 bytes: 07
TRACE +0.000 Read 1 bytes: 07
TRACE +0.000 Read 1 bytes: 12
TRACE +0.005 Read 1 bytes: 20
TRACE +0.000 Read 1 bytes: 00
TRACE +0.004 Read 4 bytes: 000000c0
TRACE +0.001 Received full packet: 010804000707122000000000
TRACE +0.005 Read 7 bytes: c0010804000707
TRACE +0.000 Read 1 bytes: 12
TRACE +0.000 Read 1 bytes: 20
TRACE +0.000 Read 1 bytes: 00
TRACE +0.005 Read 1 bytes: 00
TRACE +0.000 Read 2 bytes: 0000
TRACE +0.004 Read 2 bytes: 0704
TRACE +0.000 Read 1 bytes: c0
TRACE +0.000 Received full packet: 0108040007071220000000000704
TRACE +0.005 Read 1 bytes: 00
TRACE +0.000 Read invalid data: 00
The first 4 packets are received fine, but the 5th packet somehow gets extraneous data appended to it:
010804000707122000000000 (First 4 packets)
0108040007071220000000000704 (Fifth packet)

And the sync fails from there. So something must be happening between the computer and the nRF.

I've isolated the best I could by switching USB cables, switching computers, and installing all Adafruit Windows Drivers, but I got the same result, which means that the issue is most likely caused by either the nRF module itself or the drivers, neither of which offer any easy solution.
Attachments
Sorry the pictures are so bad: I couldn't get good results even at various angles and different light sources and my phone really didn't want to focus in on anything, even on manual mode.
Sorry the pictures are so bad: I couldn't get good results even at various angles and different light sources and my phone really didn't want to focus in on anything, even on manual mode.
20210910_182934 (2).jpg (532.88 KiB) Viewed 187 times
20210910_182648 (2).jpg
20210910_182648 (2).jpg (682.45 KiB) Viewed 187 times
20210910_182530 (2).jpg
20210910_182530 (2).jpg (676.93 KiB) Viewed 187 times

User avatar
hydroArgentum
 
Posts: 4
Joined: Mon Jan 11, 2016 4:07 pm

Re: ESP32 Featherwing Bootloader Can't Maintain Stable Seria

Post by hydroArgentum »

Some small updates: I found a Feather M0 Feather and managed to modify the SerialESPPassthrough.ino file to upload it to the M0. I was able to update the ESP32 using esptool with the M0 Feather.

Additionally, I noticed that the Serial Monitor becomes unstable (strange output at times; Serial Monitor takes a long while to close) when the ESP32 is active with the nRF52840, so it might be the case that the ESP32 Featherwing is interfering with the nRF52840 Feather's native USB somehow. Maybe this pair of devices is not compatible?

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: ESP32 Featherwing Bootloader Can't Maintain Stable Seria

Post by mikeysklar »

@hydroArgentum,

You are good at this.

Great job finding the --trace flags for esptool and watching the transfers. The fifth packet with extranous data is indeed interesting. Since you have shown your setup is working with the Feather M0 we should investigate if this is nRF52 specific issue.

I'm going to ask the guide author to take a look at this thread as he might have some thoughts on the source of the 5th packet '0704' appendage which seems to be the culprit.

Locked
Please be positive and constructive with your questions and comments.

Return to “Wireless: WiFi and Bluetooth”