Skip to content

Reproducible crashing software serial to tcp bridge #1211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
celsworth opened this issue Dec 13, 2015 · 1 comment
Closed

Reproducible crashing software serial to tcp bridge #1211

celsworth opened this issue Dec 13, 2015 · 1 comment

Comments

@celsworth
Copy link

Hi,

I can fairly reproducibly crash the following code:

#include "Arduino.h"

#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>

#include <WiFiUdp.h>

#include <WiFiClient.h>
#include <ESP8266mDNS.h>
#include <ArduinoOTA.h>


WiFiServer server(2001);
WiFiClient client;

// RX on GPIO14. GPIO12 is ignored for now.
SoftwareSerial swSer(14, 12, false, 128);

void setup()
{
    Serial.begin(9600);

    WiFi.persistent(false);
    WiFi.begin("xx", "xx");
    WiFi.mode(WIFI_STA);

    ArduinoOTA.begin();

    server.begin();

    swSer.begin(9600);
}

unsigned int last_send = 0;
char buf[512];
int buflen = 0;

// this will run fine forever until you connect on the tcp socket and then
// it crashes fairly soon afterwards
void loop()
{
    ArduinoOTA.handle();

    if (server.hasClient())
        client = server.available();

    if (swSer.available())
    {
        char d = swSer.read();
        buf[buflen++] = d;

        Serial.print(d);

    }

    // if buffer is getting full, or its been 50ms since send, empty the buffer
    if (buflen > 0 && (buflen > 500 || millis() - last_send > 50))
    {
        buf[buflen] = '\0';

        if (client.connected())
            client.print(buf);

        Serial.print(buf);

        buflen = 0;
        last_send = millis();
    }   
}

SoftwareSerial is from https://github.com/plerup/espsoftwareserial

Connect the serial output of some other compatible device (I just use another ESP spitting out some debug information in a loop) to GPIO14 and wait :)

As per the comment in there, if you don't connect to the tcp socket at all then it doesn't crash. But once you connect, the crash comes reasonably quickly (can take a bit of time, depending on the serial datarate I think).

Any idea whats going on here? Some sort of interrupt clash?

There is no exception printed or anything, the ESP just hangs and then reboots. I don't even see a wdt message, oddly.

@celsworth
Copy link
Author

Some gitter discussion reveals that this probably is because interrupts are disabled too long (or too often, or a combination of both), done by SoftwareSerial.

if I swap out SoftwareSerial for the real Serial then the problems instantly go away because I don't have to disable interrupts for such a long time.

So this is probably unfixable, just a way the ESP8266 is, unless anyone has any suggestions please feel free to close.

Many thanks @Links2004 for the help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants