Bläddra i källkod

Add hidden Serial overflow debug options

etagle 6 år sedan
förälder
incheckning
99af086cea

+ 21
- 0
Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp Visa fil

@@ -72,6 +72,14 @@
72 72
     uint8_t rx_dropped_bytes = 0;
73 73
   #endif
74 74
 
75
+  #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
76
+    uint8_t rx_buffer_overruns = 0;
77
+  #endif
78
+
79
+  #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
80
+    uint8_t rx_framing_errors = 0;
81
+  #endif
82
+
75 83
   #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
76 84
     ring_buffer_pos_t rx_max_enqueued = 0;
77 85
   #endif
@@ -99,6 +107,19 @@
99 107
     // Get the next element
100 108
     ring_buffer_pos_t i = (ring_buffer_pos_t)(h + 1) & (ring_buffer_pos_t)(RX_BUFFER_SIZE - 1);
101 109
 
110
+    // This must read the M_UCSRxA register before reading the received byte to detect error causes
111
+    #if ENABLED(SERIAL_STATS_DROPPED_RX)
112
+      if (TEST(M_UCSRxA, M_DORx) && !++rx_dropped_bytes) --rx_dropped_bytes;
113
+    #endif
114
+
115
+    #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
116
+      if (TEST(M_UCSRxA, M_DORx) && !++rx_buffer_overruns) --rx_buffer_overruns;
117
+    #endif
118
+
119
+    #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
120
+      if (TEST(M_UCSRxA, M_FEx) && !++rx_framing_errors) --rx_framing_errors;
121
+    #endif
122
+
102 123
     // Read the character from the USART
103 124
     uint8_t c = M_UDRx;
104 125
 

+ 19
- 0
Marlin/src/HAL/HAL_AVR/MarlinSerial.h Visa fil

@@ -62,6 +62,9 @@
62 62
 #define M_TXCx             SERIAL_REGNAME(TXC,SERIAL_PORT,)
63 63
 #define M_RXCIEx           SERIAL_REGNAME(RXCIE,SERIAL_PORT,)
64 64
 #define M_UDREx            SERIAL_REGNAME(UDRE,SERIAL_PORT,)
65
+#define M_FEx              SERIAL_REGNAME(FE,SERIAL_PORT,)
66
+#define M_DORx             SERIAL_REGNAME(DOR,SERIAL_PORT,)
67
+#define M_UPEx             SERIAL_REGNAME(UPE,SERIAL_PORT,)
65 68
 #define M_UDRIEx           SERIAL_REGNAME(UDRIE,SERIAL_PORT,)
66 69
 #define M_UDRx             SERIAL_REGNAME(UDR,SERIAL_PORT,)
67 70
 #define M_UBRRxH           SERIAL_REGNAME(UBRR,SERIAL_PORT,H)
@@ -91,6 +94,14 @@
91 94
     extern uint8_t rx_dropped_bytes;
92 95
   #endif
93 96
 
97
+  #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
98
+    extern uint8_t rx_buffer_overruns;
99
+  #endif
100
+
101
+  #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
102
+    extern uint8_t rx_framing_errors;
103
+  #endif
104
+
94 105
   #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
95 106
     extern ring_buffer_pos_t rx_max_enqueued;
96 107
   #endif
@@ -112,6 +123,14 @@
112 123
         FORCE_INLINE static uint32_t dropped() { return rx_dropped_bytes; }
113 124
       #endif
114 125
 
126
+      #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
127
+        FORCE_INLINE static uint32_t buffer_overruns() { return rx_buffer_overruns; }
128
+      #endif
129
+
130
+      #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
131
+        FORCE_INLINE static uint32_t framing_errors() { return rx_framing_errors; }
132
+      #endif
133
+
115 134
       #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
116 135
         FORCE_INLINE static ring_buffer_pos_t rxMaxEnqueued() { return rx_max_enqueued; }
117 136
       #endif

+ 21
- 0
Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp Visa fil

@@ -98,6 +98,14 @@
98 98
     uint8_t rx_dropped_bytes = 0;
99 99
   #endif
100 100
 
101
+  #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
102
+    uint8_t rx_buffer_overruns = 0;
103
+  #endif
104
+
105
+  #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
106
+    uint8_t rx_framing_errors = 0;
107
+  #endif
108
+
101 109
   #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
102 110
     ring_buffer_pos_t rx_max_enqueued = 0;
103 111
   #endif
@@ -308,6 +316,19 @@
308 316
 
309 317
     // Acknowledge errors
310 318
     if ((status & UART_SR_OVRE) || (status & UART_SR_FRAME)) {
319
+
320
+      #if ENABLED(SERIAL_STATS_DROPPED_RX)
321
+        if (status & UART_SR_OVRE && !++rx_dropped_bytes) --rx_dropped_bytes;
322
+      #endif
323
+
324
+      #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
325
+        if (status & UART_SR_OVRE && !++rx_buffer_overruns) --rx_buffer_overruns;
326
+      #endif
327
+
328
+      #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
329
+        if (status & UART_SR_FRAME && !++rx_framing_errors) --rx_framing_errors;
330
+      #endif
331
+
311 332
       // TODO: error reporting outside ISR
312 333
       HWUART->UART_CR = UART_CR_RSTSTA;
313 334
     }

+ 16
- 0
Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h Visa fil

@@ -70,6 +70,14 @@
70 70
   extern uint8_t rx_dropped_bytes;
71 71
 #endif
72 72
 
73
+#if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
74
+  extern uint8_t rx_buffer_overruns;
75
+#endif
76
+
77
+#if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
78
+  extern uint8_t rx_framing_errors;
79
+#endif
80
+
73 81
 #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
74 82
   extern ring_buffer_pos_t rx_max_enqueued;
75 83
 #endif
@@ -91,6 +99,14 @@ public:
91 99
     FORCE_INLINE static uint32_t dropped() { return rx_dropped_bytes; }
92 100
   #endif
93 101
 
102
+  #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
103
+    FORCE_INLINE static uint32_t buffer_overruns() { return rx_buffer_overruns; }
104
+  #endif
105
+
106
+  #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
107
+    FORCE_INLINE static uint32_t framing_errors() { return rx_framing_errors; }
108
+  #endif
109
+
94 110
   #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
95 111
     FORCE_INLINE static ring_buffer_pos_t rxMaxEnqueued() { return rx_max_enqueued; }
96 112
   #endif

+ 17
- 0
Marlin/src/gcode/control/M111.cpp Visa fil

@@ -58,6 +58,23 @@ void GcodeSuite::M111() {
58 58
   }
59 59
   else {
60 60
     SERIAL_ECHOPGM(MSG_DEBUG_OFF);
61
+    #if !defined(__AVR__) || !defined(USBCON)
62
+      #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
63
+        SERIAL_ECHOLNPAIR("Buffer Overruns: ", customizedSerial.buffer_overruns());
64
+      #endif
65
+
66
+      #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
67
+        SERIAL_ECHOLNPAIR("Framing Errors: ", customizedSerial.framing_errors());
68
+      #endif
69
+
70
+      #if ENABLED(SERIAL_STATS_DROPPED_RX)
71
+        SERIAL_ECHOLNPAIR("Dropped bytes: ", customizedSerial.dropped());
72
+      #endif
73
+
74
+      #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
75
+        SERIAL_ECHOLNPAIR("Max RX Queue Size: ", customizedSerial.rxMaxEnqueued());
76
+      #endif
77
+    #endif //  !defined(__AVR__) || !defined(USBCON)
61 78
   }
62 79
   SERIAL_EOL();
63 80
 }

Laddar…
Avbryt
Spara