arduino / arduino/ArduinoCore-avr

Mega 2560 Serial1, Hang on HardwareSerial::flush()

Open
#281 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
1.5k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

This is probably (?) related to previous issue arduino/Arduino#1742, but happens with 1.6.8. I'm running some Dynamixel smart servos from the hardware serial ports on the board; AX-12As off Serial0, and XL-320s off Serial1. As far as I can tell the hang isn't happening on Serial0, although obviously the two ports are being used slightly differently. Both are run at 1000000 baud.

Basically, everything will be fine for anywhere between 2-20s, but once the hang is triggered the board is completely unresponsive until power off/on or serial reset (reset button does nothing). I've got a logic analyser hooked up, and the final packet on the serial line is always sent in full. Control just doesn't make it past the subsequent `flush()`. Code looks like this:

```
// Write out the buffered packet
for (int i = 0; i < _packet_length + 7; i++) {
unsigned char b = _packet_data[i];
Serial1.write(b);
}

// Ensure output completed before we switch comm modes
Serial1.flush();
digitalWrite(CommPin, 0);
```

That `CommPin` line stays HIGH for the rest of time. Replacing the `flush()` with a bunch of asm `nop`s (to delay for a microsecond or three) works without issue.

Contributor guide

No contributing guide indexed for this repository

Research direction

No source file or test is named. Start by tracing HardwareSerial::flush() for Serial1 on the Mega 2560 and reproduce the provided write/flush sequence at 1000000 baud, comparing it with Serial0 and the logic-analyser output. Done means flush returns and CommPin is driven LOW without requiring a power cycle.

Written by the indexing model from the issue text.

Assessment

Tech stack
arduino, c
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.