Skip to content

Commit

Permalink
Move XON/XOFF handler from Uart to UartChannel
Browse files Browse the repository at this point in the history
This fixes a hang that can happen if, for example, a TMC2209
sends 0x11 which is XON, thus triggering software flow control.
One way to trigger the failure is to issue $H twice on an
Fysetc E4 controller.
  • Loading branch information
MitchBradley committed Jun 7, 2024
1 parent 4648d98 commit 95be53d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 0 additions & 5 deletions FluidNC/src/Uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ int Uart::read() {
}
uint8_t c;
int res = uart_read_bytes(uart_port_t(_uart_num), &c, 1, 0);
if (res == 1 && c == 0x11) {
// 0x11 is XON. If we receive that, it is a request to use software flow control
setSwFlowControl(true, -1, -1);
return -1;
}
return res == 1 ? c : -1;
}

Expand Down
8 changes: 7 additions & 1 deletion FluidNC/src/UartChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ bool UartChannel::lineComplete(char* line, char c) {
}

int UartChannel::read() {
return _uart->read();
int c = _uart->read();
if (c == 0x11) {
// 0x11 is XON. If we receive that, it is a request to use software flow control
_uart->setSwFlowControl(true, -1, -1);
return -1;
}
return c;
}

void UartChannel::flushRx() {
Expand Down

0 comments on commit 95be53d

Please sign in to comment.