From 860d98a897912505594bfa54c5f39380440840ee Mon Sep 17 00:00:00 2001
From: Dave Johnson <davejohnson3000@gmail.com>
Date: Mon, 4 Dec 2017 14:48:19 -0800
Subject: [PATCH] [1.1.x] SERIAL_XON_XOFF not supported on USB-native AVR
 devices (#8653)

* SERIAL_XON_XOFF not supported on USB-native AVR devices

User could enable SERIAL_XON_XOFF on USB-native devices and it would not be enabled without warning, but M115 would report the capability as available.
---
 Marlin/MarlinSerial.h | 29 ++++++++++++++---------------
 Marlin/SanityCheck.h  |  7 +++++++
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/Marlin/MarlinSerial.h b/Marlin/MarlinSerial.h
index a986ae61fb0..020959c5f18 100644
--- a/Marlin/MarlinSerial.h
+++ b/Marlin/MarlinSerial.h
@@ -75,27 +75,26 @@
 #define BIN 2
 #define BYTE 0
 
+// Define constants and variables for buffering serial data.
+// Use only 0 or powers of 2 greater than 1
+// : [0, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, ...]
+#ifndef RX_BUFFER_SIZE
+  #define RX_BUFFER_SIZE 128
+#endif
+// 256 is the max TX buffer limit due to uint8_t head and tail.
+#ifndef TX_BUFFER_SIZE
+  #define TX_BUFFER_SIZE 32
+#endif
+
 #ifndef USBCON
-  // Define constants and variables for buffering incoming serial data.  We're
-  // using a ring buffer (I think), in which rx_buffer_head is the index of the
-  // location to which to write the next incoming character and rx_buffer_tail
-  // is the index of the location from which to read.
-  // Use only powers of 2.
-  // : [0, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, ...]
-  #ifndef RX_BUFFER_SIZE
-    #define RX_BUFFER_SIZE 128
-  #endif
-  // 256 is the max TX buffer climit due to uint8_t head and tail.
-  #ifndef TX_BUFFER_SIZE
-    #define TX_BUFFER_SIZE 32
+  #if ENABLED(SERIAL_XON_XOFF) && RX_BUFFER_SIZE < 1024
+    #error "SERIAL_XON_XOFF requires RX_BUFFER_SIZE >= 1024 for reliable transfers without drops."
   #endif
 
-  #if ENABLED(SERIAL_XON_XOFF) && RX_BUFFER_SIZE < 1024
-    #error "XON/XOFF requires RX_BUFFER_SIZE >= 1024 for reliable transfers without drops."
-  #endif
   #if !IS_POWER_OF_2(RX_BUFFER_SIZE) || RX_BUFFER_SIZE < 2
     #error "RX_BUFFER_SIZE must be a power of 2 greater than 1."
   #endif
+
   #if TX_BUFFER_SIZE && (TX_BUFFER_SIZE < 2 || TX_BUFFER_SIZE > 256 || !IS_POWER_OF_2(TX_BUFFER_SIZE))
     #error "TX_BUFFER_SIZE must be 0, a power of 2 greater than 1, and no greater than 256."
   #endif
diff --git a/Marlin/SanityCheck.h b/Marlin/SanityCheck.h
index 0d2fac1c6e1..1ad7aa9b435 100644
--- a/Marlin/SanityCheck.h
+++ b/Marlin/SanityCheck.h
@@ -245,6 +245,13 @@
   #error "WEBSITE_URL must be specified."
 #endif
 
+/**
+ * Serial
+ */
+#if defined(USBCON) && ENABLED(SERIAL_XON_XOFF)
+  #error "SERIAL_XON_XOFF is not supported on USB-native AVR devices."
+#endif
+
 /**
  * Dual Stepper Drivers
  */