MKRGSM icon indicating copy to clipboard operation
MKRGSM copied to clipboard

MKR 1400 Hangs when antenna removed caused by Serial Flush

Open momor10 opened this issue 6 years ago • 1 comments

Hello, disconnecting the antenna during runtime will cause the MKR 1400 (didnt test any other) to crash. It happens in the MODEM.cpp in the send method during the _uart->flush();

void ModemClass::send(const char* command)
{
  if (_lowPowerMode) {
    digitalWrite(_dtrPin, LOW);
    delay(5);
  }

  // compare the time of the last response or URC and ensure 
  // at least 20ms have passed before sending a new command
  unsigned long delta = millis() - _lastResponseOrUrcMillis;
  if(delta < MODEM_MIN_RESPONSE_OR_URC_WAIT_TIME_MS) {
    delay(MODEM_MIN_RESPONSE_OR_URC_WAIT_TIME_MS - delta);
  }

  _uart->println(command);
  _uart->flush(); //crashes here
  _atCommandState = AT_COMMAND_IDLE;
  _ready = 0;
}

it doesnt matter when the antenna is disconnected , it always happens at the next call of that line. Im not sure how the antenna and the uart are related to eachother. why would it crash and why wouldnt it recover after reconnecting the antenna. After commenting out the _uart->flush() line it works and recovers from the signal loss after reconnecting the antenna. However im sure that line wasnt added just for fun. So is there another way to make sure all data are transmitted without using flush?

Im also having stability issues and waiting for https://github.com/arduino-libraries/MKRGSM/issues/66 and https://github.com/arduino-libraries/MKRGSM/issues/27 to be resolved. For now i added some timeouts to the while loops in the GSMClient.cpp and am testing..

momor10 avatar Dec 11 '18 14:12 momor10

it will actually hang in the while loop of the Uart::flush() method in https://github.com/arduino/ArduinoCore-samd/blob/master/cores/arduino/Uart.cpp:

void Uart::flush()
{
  while(txBuffer.available()); // wait until TX buffer is empty <-- stuck here

  sercom->flushUART();
}

momor10 avatar Dec 12 '18 15:12 momor10