Browse Source

Serial buffer over run work around for v2.0.0 (#9236)

* Work around for serial buffer over run

PronterFace sends a lot of M105 commands.  During long operations such
as UBL's G29 P1, G29 P2, G29 P4 and G26 this can over run the serial
buffer.   This results (very often) in a M1 (actually a M1M105) ending
up in the command queue.

Until we figure out a better way to resolve this issue, this will keep
the UBL commands from experiencing bogus commands at thier completion.
Roxy-3D 6 years ago
parent
commit
bfd9728cf4
No account linked to committer's email address

+ 4
- 1
Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp View File

@@ -69,6 +69,8 @@
69 69
     uint8_t xon_xoff_state = XON_XOFF_CHAR_SENT | XON_CHAR;
70 70
   #endif
71 71
 
72
+  void clear_command_queue(); 
73
+
72 74
   #if ENABLED(SERIAL_STATS_DROPPED_RX)
73 75
     uint8_t rx_dropped_bytes = 0;
74 76
   #endif
@@ -388,7 +390,8 @@
388 390
     // reading rx_buffer_head and updating rx_buffer_tail, the previous rx_buffer_head
389 391
     // may be written to rx_buffer_tail, making the buffer appear full rather than empty.
390 392
     CRITICAL_SECTION_START;
391
-      rx_buffer.head = rx_buffer.tail;
393
+      rx_buffer.head = rx_buffer.tail = 0;
394
+      clear_command_queue(); 
392 395
     CRITICAL_SECTION_END;
393 396
 
394 397
     #if ENABLED(SERIAL_XON_XOFF)

+ 3
- 3
Marlin/src/config/examples/FolgerTech/i3-2020/Configuration.h View File

@@ -555,7 +555,7 @@
555 555
  * Override with M203
556 556
  *                                      X, Y, Z, E0 [, E1[, E2[, E3[, E4]]]]
557 557
  */
558
-#define DEFAULT_MAX_FEEDRATE          { 250, 250, 2, 17 }
558
+#define DEFAULT_MAX_FEEDRATE          { 250, 250, 4, 17 }
559 559
 
560 560
 /**
561 561
  * Default Max Acceleration (change/s) change = mm/s
@@ -587,7 +587,7 @@
587 587
  */
588 588
 #define DEFAULT_XJERK                  8.5
589 589
 #define DEFAULT_YJERK                  8.5
590
-#define DEFAULT_ZJERK                  0.3
590
+#define DEFAULT_ZJERK                  0.75
591 591
 #define DEFAULT_EJERK                  4.0
592 592
 
593 593
 //===========================================================================
@@ -916,7 +916,7 @@
916 916
   /**
917 917
    * Enable the G26 Mesh Validation Pattern tool.
918 918
    */
919
-  //#define G26_MESH_VALIDATION
919
+  #define G26_MESH_VALIDATION
920 920
   #if ENABLED(G26_MESH_VALIDATION)
921 921
     #define MESH_TEST_NOZZLE_SIZE    0.4  // (mm) Diameter of primary nozzle.
922 922
     #define MESH_TEST_LAYER_HEIGHT   0.2  // (mm) Default layer height for the G26 Mesh Validation Tool.

+ 1
- 1
Marlin/src/config/examples/FolgerTech/i3-2020/Configuration_adv.h View File

@@ -1562,7 +1562,7 @@
1562 1562
  * Fully assembled MAX7219 boards can be found on the internet for under $2(US).
1563 1563
  * For example, see https://www.ebay.com/sch/i.html?_nkw=332349290049
1564 1564
  */
1565
-//#define MAX7219_DEBUG
1565
+#define MAX7219_DEBUG
1566 1566
 #if ENABLED(MAX7219_DEBUG)
1567 1567
 //#define MAX7219_CLK_PIN   64  // on RAMPS       // Configuration of the 3 pins to control the display
1568 1568
 //#define MAX7219_DIN_PIN   57  // on RAMPS

+ 3
- 3
Marlin/src/feature/bedlevel/ubl/ubl.h View File

@@ -93,7 +93,7 @@ class unified_bed_leveling {
93 93
     static bool g29_parameter_parsing();
94 94
     static void find_mean_mesh_height();
95 95
     static void shift_mesh_height();
96
-    static void probe_entire_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map, const bool stow_probe, bool do_furthest);
96
+    static void probe_entire_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map, const bool stow_probe, bool do_furthest) _O0;
97 97
     static void tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3);
98 98
     static void tilt_mesh_based_on_probed_grid(const bool do_ubl_mesh_map);
99 99
     static void g29_what_command();
@@ -117,8 +117,8 @@ class unified_bed_leveling {
117 117
     static void save_ubl_active_state_and_disable();
118 118
     static void restore_ubl_active_state_and_leave();
119 119
     static void display_map(const int);
120
-    static mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType, const float&, const float&, const bool, uint16_t[16]);
121
-    static mesh_index_pair find_furthest_invalid_mesh_point();
120
+    static mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType, const float&, const float&, const bool, uint16_t[16]) _O0;
121
+    static mesh_index_pair find_furthest_invalid_mesh_point() _O0;
122 122
     static void reset();
123 123
     static void invalidate();
124 124
     static void set_all_mesh_points_to_value(const float);

+ 22
- 13
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp View File

@@ -36,6 +36,7 @@
36 36
   #include "../../../module/planner.h"
37 37
   #include "../../../module/probe.h"
38 38
   #include "../../../gcode/gcode.h"
39
+  #include "../../../core/serial.h"
39 40
   #include "../../../gcode/parser.h"
40 41
   #include "../../../feature/bedlevel/bedlevel.h"
41 42
   #include "../../../libs/least_squares_fit.h"
@@ -59,8 +60,6 @@
59 60
 
60 61
   extern float meshedit_done;
61 62
   extern long babysteps_done;
62
-  //extern bool set_probe_deployed(bool);
63
-  //extern void set_bed_leveling_enabled(bool);
64 63
 
65 64
   #define SIZE_OF_LITTLE_RAISE 1
66 65
   #define BIG_RAISE_NOT_NEEDED 0
@@ -720,7 +719,7 @@
720 719
           }
721 720
         }
722 721
       }
723
-      safe_delay(5);
722
+      safe_delay(15);
724 723
       return false;
725 724
     }
726 725
 
@@ -754,6 +753,7 @@
754 753
             while (is_lcd_clicked()) idle();
755 754
             lcd_external_control = false;
756 755
             restore_ubl_active_state_and_leave();
756
+            lcd_quick_feedback(true);
757 757
             safe_delay(50);  // Debounce the Encoder wheel
758 758
             return;
759 759
           }
@@ -771,6 +771,9 @@
771 771
           const float measured_z = probe_pt(rawx, rawy, stow_probe, g29_verbose_level); // TODO: Needs error handling
772 772
           z_values[location.x_index][location.y_index] = measured_z;
773 773
         }
774
+        MYSERIAL0.flush(); // G29 P2's take a long time to complete.   PronterFace can
775
+                           // over run the serial character buffer with M105's without
776
+                           // this fix
774 777
 
775 778
       } while (location.x_index >= 0 && --max_iterations);
776 779
 
@@ -853,6 +856,7 @@
853 856
       do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
854 857
       lcd_external_control = false;
855 858
       KEEPALIVE_STATE(IN_HANDLER);
859
+      lcd_quick_feedback(true);
856 860
       ubl.restore_ubl_active_state_and_leave();
857 861
     }
858 862
 
@@ -908,9 +912,12 @@
908 912
           SERIAL_PROTOCOL_F(z_values[location.x_index][location.y_index], 6);
909 913
           SERIAL_EOL();
910 914
         }
915
+        MYSERIAL0.flush(); // G29 P2's take a long time to complete.   PronterFace can
916
+                           // over run the serial character buffer with M105's without
917
+                           // this fix
911 918
       } while (location.x_index >= 0 && location.y_index >= 0);
912 919
 
913
-      if (do_ubl_mesh_map) display_map(g29_map_type);
920
+      if (do_ubl_mesh_map) display_map(g29_map_type);  // show user where we're probing
914 921
 
915 922
       restore_ubl_active_state_and_leave();
916 923
       KEEPALIVE_STATE(IN_HANDLER);
@@ -1035,12 +1042,12 @@
1035 1042
 
1036 1043
   static uint8_t ubl_state_at_invocation = 0;
1037 1044
 
1038
-  #ifdef UBL_DEVEL_DEBUGGING
1045
+  #if ENABLED(UBL_DEVEL_DEBUGGING)
1039 1046
     static uint8_t ubl_state_recursion_chk = 0;
1040 1047
   #endif
1041 1048
 
1042 1049
   void unified_bed_leveling::save_ubl_active_state_and_disable() {
1043
-    #ifdef UBL_DEVEL_DEBUGGING
1050
+    #if ENABLED(UBL_DEVEL_DEBUGGING)
1044 1051
       ubl_state_recursion_chk++;
1045 1052
       if (ubl_state_recursion_chk != 1) {
1046 1053
         SERIAL_ECHOLNPGM("save_ubl_active_state_and_disabled() called multiple times in a row.");
@@ -1056,7 +1063,7 @@
1056 1063
   }
1057 1064
 
1058 1065
   void unified_bed_leveling::restore_ubl_active_state_and_leave() {
1059
-    #ifdef UBL_DEVEL_DEBUGGING
1066
+    #if ENABLED(UBL_DEVEL_DEBUGGING)
1060 1067
       if (--ubl_state_recursion_chk) {
1061 1068
         SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times.");
1062 1069
         #if ENABLED(NEWPANEL)
@@ -1110,11 +1117,12 @@
1110 1117
     SERIAL_ECHOLNPAIR("MESH_MAX_Y  " STRINGIFY(MESH_MAX_Y) "=", MESH_MAX_Y);
1111 1118
     safe_delay(50);
1112 1119
     SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_X  ", GRID_MAX_POINTS_X);
1120
+    safe_delay(50);
1113 1121
     SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_Y  ", GRID_MAX_POINTS_Y);
1114
-    safe_delay(25);
1122
+    safe_delay(50);
1115 1123
     SERIAL_ECHOLNPAIR("MESH_X_DIST  ", MESH_X_DIST);
1116 1124
     SERIAL_ECHOLNPAIR("MESH_Y_DIST  ", MESH_Y_DIST);
1117
-    safe_delay(25);
1125
+    safe_delay(50);
1118 1126
 
1119 1127
     SERIAL_PROTOCOLPGM("X-Axis Mesh Points at: ");
1120 1128
     for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
@@ -1139,7 +1147,7 @@
1139 1147
     SERIAL_EOL();
1140 1148
     safe_delay(50);
1141 1149
 
1142
-    #ifdef UBL_DEVEL_DEBUGGING
1150
+    #if ENABLED(UBL_DEVEL_DEBUGGING)
1143 1151
       SERIAL_PROTOCOLLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation);
1144 1152
       SERIAL_EOL();
1145 1153
       SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
@@ -1352,6 +1360,7 @@
1352 1360
       lcd_return_to_status();
1353 1361
       do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
1354 1362
       LCD_MESSAGEPGM(MSG_EDITING_STOPPED);
1363
+      lcd_quick_feedback(true);
1355 1364
     }
1356 1365
 
1357 1366
     void unified_bed_leveling::fine_tune_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map) {
@@ -1417,6 +1426,9 @@
1417 1426
             do_blocking_move_to_z(h_offset + new_z); // Move the nozzle as the point is edited
1418 1427
           #endif
1419 1428
           idle();
1429
+          MYSERIAL0.flush(); // G29 P2's take a long time to complete.   PronterFace can
1430
+                             // over run the serial character buffer with M105's without
1431
+                             // this fix
1420 1432
         } while (!is_lcd_clicked());
1421 1433
 
1422 1434
         if (!lcd_map_control) lcd_return_to_status();
@@ -1426,9 +1438,6 @@
1426 1438
         // Let's work on specifying a proper API for the LCD ASAP, OK?
1427 1439
         lcd_external_control = true;
1428 1440
 
1429
-        // this sequence to detect an is_lcd_clicked() debounce it and leave if it is
1430
-        // a Press and Hold is repeated in a lot of places (including G26_Mesh_Validation.cpp).   This
1431
-        // should be redone and compressed.
1432 1441
         if (click_and_hold(abort_fine_tune))
1433 1442
           goto FINE_TUNE_EXIT;
1434 1443
 

+ 21
- 8
Marlin/src/gcode/bedlevel/G26.cpp View File

@@ -437,6 +437,9 @@ inline bool turn_on_heaters() {
437 437
             SERIAL_EOL();
438 438
           }
439 439
           idle();
440
+          MYSERIAL0.flush(); // G26 takes a long time to complete.   PronterFace can
441
+                             // over run the serial character buffer with M105's without
442
+                             // this fix
440 443
         }
441 444
     #if ENABLED(ULTRA_LCD)
442 445
       }
@@ -459,6 +462,10 @@ inline bool turn_on_heaters() {
459 462
       SERIAL_EOL();
460 463
     }
461 464
     idle();
465
+
466
+    MYSERIAL0.flush(); // G26 takes a long time to complete.   PronterFace can
467
+                       // over run the serial character buffer with M105's without
468
+                       // this fix
462 469
   }
463 470
 
464 471
   #if ENABLED(ULTRA_LCD)
@@ -680,12 +687,12 @@ void GcodeSuite::G26() {
680 687
   set_bed_leveling_enabled(!parser.seen('D'));
681 688
 
682 689
   if (current_position[Z_AXIS] < Z_CLEARANCE_BETWEEN_PROBES) {
683
-SERIAL_PROTOCOLLNPGM("! move nozzle to Z_CLEARANCE_BETWEEN_PROBES height.");
684
-SERIAL_ECHOLNPAIR("  Z at:", current_position[Z_AXIS]);
690
+//  SERIAL_PROTOCOLLNPGM("! move nozzle to Z_CLEARANCE_BETWEEN_PROBES height.");
691
+//  SERIAL_ECHOLNPAIR("  Z at:", current_position[Z_AXIS]);
685 692
     do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
686 693
     stepper.synchronize();
687 694
     set_current_from_destination();
688
-SERIAL_ECHOLNPAIR("  Z now at:", current_position[Z_AXIS]);
695
+//  SERIAL_ECHOLNPAIR("  Z now at:", current_position[Z_AXIS]);
689 696
   }
690 697
 
691 698
   if (turn_on_heaters() != G26_OK) goto LEAVE;
@@ -711,14 +718,14 @@ SERIAL_ECHOLNPAIR("  Z now at:", current_position[Z_AXIS]);
711 718
 
712 719
   // Move nozzle to the specified height for the first layer
713 720
   set_destination_from_current();
714
-SERIAL_PROTOCOLLNPGM("! moving nozzle to 1st layer height.");
715
-SERIAL_ECHOLNPAIR("  Z1 at:", current_position[Z_AXIS]);
721
+//SERIAL_PROTOCOLLNPGM("! moving nozzle to 1st layer height.");
722
+//SERIAL_ECHOLNPAIR("  Z1 at:", current_position[Z_AXIS]);
716 723
 
717 724
   destination[Z_AXIS] = g26_layer_height;
718 725
   move_to(destination, 0.0);
719
-  stepper.synchronize();
720
-  set_destination_from_current();
721
-SERIAL_ECHOLNPAIR("  Z2 at:", current_position[Z_AXIS]);
726
+//stepper.synchronize();
727
+//set_destination_from_current();
728
+//SERIAL_ECHOLNPAIR("  Z2 at:", current_position[Z_AXIS]);
722 729
   move_to(destination, g26_ooze_amount);
723 730
 
724 731
   #if ENABLED(ULTRA_LCD)
@@ -823,11 +830,17 @@ SERIAL_ECHOLNPAIR("  Z2 at:", current_position[Z_AXIS]);
823 830
         //}
824 831
 
825 832
         print_line_from_here_to_there(rx, ry, g26_layer_height, xe, ye, g26_layer_height);
833
+        MYSERIAL0.flush(); // G26 takes a long time to complete.   PronterFace can
834
+                           // over run the serial character buffer with M105's without
835
+                           // this fix
826 836
 
827 837
       }
828 838
       if (look_for_lines_to_connect())
829 839
         goto LEAVE;
830 840
     }
841
+    MYSERIAL0.flush(); // G26 takes a long time to complete.   PronterFace can
842
+                       // over run the serial character buffer with M105's without
843
+                       // this fix
831 844
   } while (--g26_repeats && location.x_index >= 0 && location.y_index >= 0);
832 845
 
833 846
   LEAVE:

+ 1
- 2
Marlin/src/gcode/queue.cpp View File

@@ -90,8 +90,7 @@ void queue_setup() {
90 90
  * Clear the Marlin command queue
91 91
  */
92 92
 void clear_command_queue() {
93
-  cmd_queue_index_r = cmd_queue_index_w;
94
-  commands_in_queue = 0;
93
+  cmd_queue_index_r = cmd_queue_index_w = commands_in_queue = 0;
95 94
 }
96 95
 
97 96
 /**

Loading…
Cancel
Save