Skip to content

ESP32-S2, TWAI crash WiFi. #7964

@FedericoAndrades

Description

@FedericoAndrades

Board

ESP32-S2-Wrover

Device Description

ESP32-S2-wrover on PCB prototype

Hardware Configuration

GPIO 5 is CAN_TX
GPIO 4 is CAN_RX

Version

v2.0.7

IDE Name

Arduino IDE

Operating System

Windows11

Flash frequency

80Mhz

PSRAM enabled

no

Upload speed

Internal USB 921600

Description

Hi, sorry for my english, it's from google.
I want to use the ESP32-S2-wrover with WiFi and TWAI, but when I enable the TWAI port the WiFi crashes, and I can't get it to work.
I have reduced it to the fact that if the GPIO5 port is not defined as an output and in a low state, the WiFi does not work, but the TWAI driver has the GPIO5 on the CAN_TX pin.
Any idea where the problem could be, or any solution?
Thanks

Sketch

/*
 WiFi Web Server LED Blink

 A simple web server that lets you blink an LED via the web.
 This sketch will print the IP address of your WiFi Shield (once connected)
 to the Serial monitor. From there, you can open that address in a web browser
 to turn on and off the LED on pin 5.

 If the IP address of your shield is yourAddress:
 http://yourAddress/H turns the LED on
 http://yourAddress/L turns it off

 This example is written for a network using WPA2 encryption. For insecure
 WEP or WPA, change the Wifi.begin() call and use Wifi.setMinSecurity() accordingly.

 Circuit:
 * WiFi shield attached
 * LED attached to pin 5

 created for arduino 25 Nov 2012
 by Tom Igoe

ported for sparkfun esp32 
31.01.2017 by Jan Hendrik Berlin
 
 */
#include "Arduino.h"
#include "FS.h"
#include "FFat.h"

#include <WiFi.h>

const char* ssid     = "Andrades_LAB";
const char* password = "34341189";

#include <SimpleFTPServer.h>

WiFiServer server(80);

FtpServer ftpSrv;

void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){
  switch (ftpOperation) {
    case FTP_CONNECT:
      Serial.println(F("FTP: Connected!"));
      break;
    case FTP_DISCONNECT:
      Serial.println(F("FTP: Disconnected!"));
      break;
    case FTP_FREE_SPACE_CHANGE:
      Serial.printf("FTP: Free space change, free %u of %u!\n", freeSpace, totalSpace);
      break;
    default:
      break;
  }
};
void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize){
  switch (ftpOperation) {
    case FTP_UPLOAD_START:
      Serial.println(F("FTP: Upload start!"));
      break;
    case FTP_UPLOAD:
      Serial.printf("FTP: Upload of file %s byte %u\n", name, transferredSize);
      break;
    case FTP_TRANSFER_STOP:
      Serial.println(F("FTP: Finish transfer!"));
      break;
    case FTP_TRANSFER_ERROR:
      Serial.println(F("FTP: Transfer error!"));
      break;
    default:
      break;
  }

  /* FTP_UPLOAD_START = 0,
   * FTP_UPLOAD = 1,
   *
   * FTP_DOWNLOAD_START = 2,
   * FTP_DOWNLOAD = 3,
   *
   * FTP_TRANSFER_STOP = 4,
   * FTP_DOWNLOAD_STOP = 4,
   * FTP_UPLOAD_STOP = 4,
   *
   * FTP_TRANSFER_ERROR = 5,
   * FTP_DOWNLOAD_ERROR = 5,
   * FTP_UPLOAD_ERROR = 5
   */
};

void setup()
{
    Serial.begin(115200);
    while(!Serial);

    //FFat.format();
    
    pinMode(5, OUTPUT);      // set the LED pin mode
    digitalWrite( 5 , HIGH); // Is not LOW WIFI not work!!!!

    delay(10);

    // We start by connecting to a WiFi network

    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }

    Serial.println("");
    Serial.println("WiFi connected.");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    
    server.begin();

  /////FTP Setup, ensure FFAT is started before ftp;  /////////
  Serial.print(F("Inizializing FS..."));
  if (FFat.begin(true)){
      Serial.println(F("done."));
  }else{
      Serial.println(F("fail."));
      while (true) { delay(1000); };
  }

  ftpSrv.setCallback(_callback);
  ftpSrv.setTransferCallback(_transferCallback);

  Serial.println("Start FTP with user: user and passwd: password!");
  ftpSrv.begin("user","password");    //username, password for ftp.   (default 21, 50009 for PASV)

}

void loop(){
 WiFiClient client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    Serial.println("New Client.");           // print a message out the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();

            // the content of the HTTP response follows the header:
            client.print("Click <a href=\"/H\">here</a> to turn the LED on pin 5 on.<br>");
            client.print("Click <a href=\"/L\">here</a> to turn the LED on pin 5 off.<br>");

            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
          } else {    // if you got a newline, then clear currentLine:
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }

        // Check to see if the client request was "GET /H" or "GET /L":
        if (currentLine.endsWith("GET /H")) {
          digitalWrite(5, HIGH);               // GET /H turns the LED on
        }
        if (currentLine.endsWith("GET /L")) {
          digitalWrite(5, LOW);                // GET /L turns the LED off
        }
      }
    }
    // close the connection:
    client.stop();
    Serial.println("Client Disconnected.");
  }
    ftpSrv.handleFTP();        //make sure in loop you call handleFTP()!!

}

Debug Message

ESP-ROM:esp32s2-rc4-20191025<CR><LF>
Build:Oct 25 2019<CR><LF>
rst:0x3 (RTC_SW_SYS_RST),boot:0x0 (DOWNLOAD(USB/UART0/1/SPI))<CR><LF>
Saved PC:0x40026a55<CR><LF>
waiting for download<CR><LF>
ESP-ROM:esp32s2-rc4-20191025<CR><LF>
Build:Oct 25 2019<CR><LF>
rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)<CR><LF>
Saved PC:0x4002897f<CR><LF>
SPIWP:0xee<CR><LF>
mode:DIO, clock div:1<CR><LF>
load:0x3ffe6100,len:0x524<CR><LF>
load:0x4004c000,len:0xa70<CR><LF>
load:0x40050000,len:0x2958<CR><LF>
entry 0x4004c18c<CR><LF>
[320537][D][esp32-hal-tinyusb.c:675] tinyusb_enable_interface(): Interface CDC enabled<CR><LF>
[320537][V][WiFiServer.h:42] WiFiServer(): WiFiServer::WiFiServer(port=80, ...)<CR><LF>
[320540][V][WiFiServer.h:42] WiFiServer(): WiFiServer::WiFiServer(port=21, ...)<CR><LF>
[320547][V][WiFiServer.h:42] WiFiServer(): WiFiServer::WiFiServer(port=50009, ...)<CR><LF>
[320556][D][esp32-hal-tinyusb.c:564] tinyusb_load_enabled_interfaces(): Load Done: if_num: 2, descr_len: 75, if_mask: 0x10<CR><LF>
[329075][D][WiFiGeneric.cpp:931] _eventCallback(): Arduino Event: 0 - WIFI_READY<CR><LF>
[329128][V][WiFiGeneric.cpp:340] _arduino_event_cb(): STA Started<CR><LF>
[329129][D][WiFiGeneric.cpp:931] _eventCallback(): Arduino Event: 2 - STA_START<CR><LF>
[329131][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0<CR><LF>
[331560][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: Andrades_LAB, BSSID: 00:00:00:00:00:00, Reason: 201<CR><LF>
[331560][D][WiFiGeneric.cpp:931] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED<CR><LF>
[331568][W][WiFiGeneric.cpp:955] _eventCallback(): Reason: 201 - NO_AP_FOUND<CR><LF>
[331575][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi Reconnect Running<CR><LF>
[331582][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0<CR><LF>
[334006][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: Andrades_LAB, BSSID: 00:00:00:00:00:00, Reason: 201<CR><LF>
[334006][D][WiFiGeneric.cpp:931] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED<CR><LF>
[334014][W][WiFiGeneric.cpp:955] _eventCallback(): Reason: 201 - NO_AP_FOUND<CR><LF>
[334020][D][WiFiGeneric.cpp:979] _eventCallback(): WiFi AutoReconnect Running<CR><LF>
[334028][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0<CR><LF>
[336453][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: Andrades_LAB, BSSID: 00:00:00:00:00:00, Reason: 201<CR><LF>
[336454][D][WiFiGeneric.cpp:931] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED<CR><LF>
[336461][W][WiFiGeneric.cpp:955] _eventCallback(): Reason: 201 - NO_AP_FOUND<CR><LF>
[336468][D][WiFiGeneric.cpp:979] _eventCallback(): WiFi AutoReconnect Running<CR><LF>
[336476][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0<CR><LF>
[338899][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: Andrades_LAB, BSSID: 00:00:00:00:00:00, Reason: 201<CR><LF>
[338900][D][WiFiGeneric.cpp:931] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED<CR><LF>
[338907][W][WiFiGeneric.cpp:955] _eventCallback(): Reason: 201 - NO_AP_FOUND<CR><LF>
[338914][D][WiFiGeneric.cpp:979] _eventCallback(): WiFi AutoReconnect Running<CR><LF>
[338922][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0<CR><LF>
[341351][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: Andrades_LAB, BSSID: 00:00:00:00:00:00, Reason: 201<CR><LF>
[341352][D][WiFiGeneric.cpp:931] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED<CR><LF>
[341359][W][WiFiGeneric.cpp:955] _eventCallback(): Reason: 201 - NO_AP_FOUND<CR><LF>
[341366][D][WiFiGeneric.cpp:979] _eventCallback(): WiFi AutoReconnect Running<CR><LF>
[341374][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0<CR><LF>

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions