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

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

555
  * Override with M203
555
  * Override with M203
556
  *                                      X, Y, Z, E0 [, E1[, E2[, E3[, E4]]]]
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
  * Default Max Acceleration (change/s) change = mm/s
561
  * Default Max Acceleration (change/s) change = mm/s
587
  */
587
  */
588
 #define DEFAULT_XJERK                  8.5
588
 #define DEFAULT_XJERK                  8.5
589
 #define DEFAULT_YJERK                  8.5
589
 #define DEFAULT_YJERK                  8.5
590
-#define DEFAULT_ZJERK                  0.3
590
+#define DEFAULT_ZJERK                  0.75
591
 #define DEFAULT_EJERK                  4.0
591
 #define DEFAULT_EJERK                  4.0
592
 
592
 
593
 //===========================================================================
593
 //===========================================================================
916
   /**
916
   /**
917
    * Enable the G26 Mesh Validation Pattern tool.
917
    * Enable the G26 Mesh Validation Pattern tool.
918
    */
918
    */
919
-  //#define G26_MESH_VALIDATION
919
+  #define G26_MESH_VALIDATION
920
   #if ENABLED(G26_MESH_VALIDATION)
920
   #if ENABLED(G26_MESH_VALIDATION)
921
     #define MESH_TEST_NOZZLE_SIZE    0.4  // (mm) Diameter of primary nozzle.
921
     #define MESH_TEST_NOZZLE_SIZE    0.4  // (mm) Diameter of primary nozzle.
922
     #define MESH_TEST_LAYER_HEIGHT   0.2  // (mm) Default layer height for the G26 Mesh Validation Tool.
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
  * Fully assembled MAX7219 boards can be found on the internet for under $2(US).
1562
  * Fully assembled MAX7219 boards can be found on the internet for under $2(US).
1563
  * For example, see https://www.ebay.com/sch/i.html?_nkw=332349290049
1563
  * For example, see https://www.ebay.com/sch/i.html?_nkw=332349290049
1564
  */
1564
  */
1565
-//#define MAX7219_DEBUG
1565
+#define MAX7219_DEBUG
1566
 #if ENABLED(MAX7219_DEBUG)
1566
 #if ENABLED(MAX7219_DEBUG)
1567
 //#define MAX7219_CLK_PIN   64  // on RAMPS       // Configuration of the 3 pins to control the display
1567
 //#define MAX7219_CLK_PIN   64  // on RAMPS       // Configuration of the 3 pins to control the display
1568
 //#define MAX7219_DIN_PIN   57  // on RAMPS
1568
 //#define MAX7219_DIN_PIN   57  // on RAMPS

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

93
     static bool g29_parameter_parsing();
93
     static bool g29_parameter_parsing();
94
     static void find_mean_mesh_height();
94
     static void find_mean_mesh_height();
95
     static void shift_mesh_height();
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
     static void tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3);
97
     static void tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3);
98
     static void tilt_mesh_based_on_probed_grid(const bool do_ubl_mesh_map);
98
     static void tilt_mesh_based_on_probed_grid(const bool do_ubl_mesh_map);
99
     static void g29_what_command();
99
     static void g29_what_command();
117
     static void save_ubl_active_state_and_disable();
117
     static void save_ubl_active_state_and_disable();
118
     static void restore_ubl_active_state_and_leave();
118
     static void restore_ubl_active_state_and_leave();
119
     static void display_map(const int);
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
     static void reset();
122
     static void reset();
123
     static void invalidate();
123
     static void invalidate();
124
     static void set_all_mesh_points_to_value(const float);
124
     static void set_all_mesh_points_to_value(const float);

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

36
   #include "../../../module/planner.h"
36
   #include "../../../module/planner.h"
37
   #include "../../../module/probe.h"
37
   #include "../../../module/probe.h"
38
   #include "../../../gcode/gcode.h"
38
   #include "../../../gcode/gcode.h"
39
+  #include "../../../core/serial.h"
39
   #include "../../../gcode/parser.h"
40
   #include "../../../gcode/parser.h"
40
   #include "../../../feature/bedlevel/bedlevel.h"
41
   #include "../../../feature/bedlevel/bedlevel.h"
41
   #include "../../../libs/least_squares_fit.h"
42
   #include "../../../libs/least_squares_fit.h"
59
 
60
 
60
   extern float meshedit_done;
61
   extern float meshedit_done;
61
   extern long babysteps_done;
62
   extern long babysteps_done;
62
-  //extern bool set_probe_deployed(bool);
63
-  //extern void set_bed_leveling_enabled(bool);
64
 
63
 
65
   #define SIZE_OF_LITTLE_RAISE 1
64
   #define SIZE_OF_LITTLE_RAISE 1
66
   #define BIG_RAISE_NOT_NEEDED 0
65
   #define BIG_RAISE_NOT_NEEDED 0
720
           }
719
           }
721
         }
720
         }
722
       }
721
       }
723
-      safe_delay(5);
722
+      safe_delay(15);
724
       return false;
723
       return false;
725
     }
724
     }
726
 
725
 
754
             while (is_lcd_clicked()) idle();
753
             while (is_lcd_clicked()) idle();
755
             lcd_external_control = false;
754
             lcd_external_control = false;
756
             restore_ubl_active_state_and_leave();
755
             restore_ubl_active_state_and_leave();
756
+            lcd_quick_feedback(true);
757
             safe_delay(50);  // Debounce the Encoder wheel
757
             safe_delay(50);  // Debounce the Encoder wheel
758
             return;
758
             return;
759
           }
759
           }
771
           const float measured_z = probe_pt(rawx, rawy, stow_probe, g29_verbose_level); // TODO: Needs error handling
771
           const float measured_z = probe_pt(rawx, rawy, stow_probe, g29_verbose_level); // TODO: Needs error handling
772
           z_values[location.x_index][location.y_index] = measured_z;
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
       } while (location.x_index >= 0 && --max_iterations);
778
       } while (location.x_index >= 0 && --max_iterations);
776
 
779
 
853
       do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
856
       do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
854
       lcd_external_control = false;
857
       lcd_external_control = false;
855
       KEEPALIVE_STATE(IN_HANDLER);
858
       KEEPALIVE_STATE(IN_HANDLER);
859
+      lcd_quick_feedback(true);
856
       ubl.restore_ubl_active_state_and_leave();
860
       ubl.restore_ubl_active_state_and_leave();
857
     }
861
     }
858
 
862
 
908
           SERIAL_PROTOCOL_F(z_values[location.x_index][location.y_index], 6);
912
           SERIAL_PROTOCOL_F(z_values[location.x_index][location.y_index], 6);
909
           SERIAL_EOL();
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
       } while (location.x_index >= 0 && location.y_index >= 0);
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
       restore_ubl_active_state_and_leave();
922
       restore_ubl_active_state_and_leave();
916
       KEEPALIVE_STATE(IN_HANDLER);
923
       KEEPALIVE_STATE(IN_HANDLER);
1035
 
1042
 
1036
   static uint8_t ubl_state_at_invocation = 0;
1043
   static uint8_t ubl_state_at_invocation = 0;
1037
 
1044
 
1038
-  #ifdef UBL_DEVEL_DEBUGGING
1045
+  #if ENABLED(UBL_DEVEL_DEBUGGING)
1039
     static uint8_t ubl_state_recursion_chk = 0;
1046
     static uint8_t ubl_state_recursion_chk = 0;
1040
   #endif
1047
   #endif
1041
 
1048
 
1042
   void unified_bed_leveling::save_ubl_active_state_and_disable() {
1049
   void unified_bed_leveling::save_ubl_active_state_and_disable() {
1043
-    #ifdef UBL_DEVEL_DEBUGGING
1050
+    #if ENABLED(UBL_DEVEL_DEBUGGING)
1044
       ubl_state_recursion_chk++;
1051
       ubl_state_recursion_chk++;
1045
       if (ubl_state_recursion_chk != 1) {
1052
       if (ubl_state_recursion_chk != 1) {
1046
         SERIAL_ECHOLNPGM("save_ubl_active_state_and_disabled() called multiple times in a row.");
1053
         SERIAL_ECHOLNPGM("save_ubl_active_state_and_disabled() called multiple times in a row.");
1056
   }
1063
   }
1057
 
1064
 
1058
   void unified_bed_leveling::restore_ubl_active_state_and_leave() {
1065
   void unified_bed_leveling::restore_ubl_active_state_and_leave() {
1059
-    #ifdef UBL_DEVEL_DEBUGGING
1066
+    #if ENABLED(UBL_DEVEL_DEBUGGING)
1060
       if (--ubl_state_recursion_chk) {
1067
       if (--ubl_state_recursion_chk) {
1061
         SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times.");
1068
         SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times.");
1062
         #if ENABLED(NEWPANEL)
1069
         #if ENABLED(NEWPANEL)
1110
     SERIAL_ECHOLNPAIR("MESH_MAX_Y  " STRINGIFY(MESH_MAX_Y) "=", MESH_MAX_Y);
1117
     SERIAL_ECHOLNPAIR("MESH_MAX_Y  " STRINGIFY(MESH_MAX_Y) "=", MESH_MAX_Y);
1111
     safe_delay(50);
1118
     safe_delay(50);
1112
     SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_X  ", GRID_MAX_POINTS_X);
1119
     SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_X  ", GRID_MAX_POINTS_X);
1120
+    safe_delay(50);
1113
     SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_Y  ", GRID_MAX_POINTS_Y);
1121
     SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_Y  ", GRID_MAX_POINTS_Y);
1114
-    safe_delay(25);
1122
+    safe_delay(50);
1115
     SERIAL_ECHOLNPAIR("MESH_X_DIST  ", MESH_X_DIST);
1123
     SERIAL_ECHOLNPAIR("MESH_X_DIST  ", MESH_X_DIST);
1116
     SERIAL_ECHOLNPAIR("MESH_Y_DIST  ", MESH_Y_DIST);
1124
     SERIAL_ECHOLNPAIR("MESH_Y_DIST  ", MESH_Y_DIST);
1117
-    safe_delay(25);
1125
+    safe_delay(50);
1118
 
1126
 
1119
     SERIAL_PROTOCOLPGM("X-Axis Mesh Points at: ");
1127
     SERIAL_PROTOCOLPGM("X-Axis Mesh Points at: ");
1120
     for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1128
     for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1139
     SERIAL_EOL();
1147
     SERIAL_EOL();
1140
     safe_delay(50);
1148
     safe_delay(50);
1141
 
1149
 
1142
-    #ifdef UBL_DEVEL_DEBUGGING
1150
+    #if ENABLED(UBL_DEVEL_DEBUGGING)
1143
       SERIAL_PROTOCOLLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation);
1151
       SERIAL_PROTOCOLLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation);
1144
       SERIAL_EOL();
1152
       SERIAL_EOL();
1145
       SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
1153
       SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
1352
       lcd_return_to_status();
1360
       lcd_return_to_status();
1353
       do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
1361
       do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
1354
       LCD_MESSAGEPGM(MSG_EDITING_STOPPED);
1362
       LCD_MESSAGEPGM(MSG_EDITING_STOPPED);
1363
+      lcd_quick_feedback(true);
1355
     }
1364
     }
1356
 
1365
 
1357
     void unified_bed_leveling::fine_tune_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map) {
1366
     void unified_bed_leveling::fine_tune_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map) {
1417
             do_blocking_move_to_z(h_offset + new_z); // Move the nozzle as the point is edited
1426
             do_blocking_move_to_z(h_offset + new_z); // Move the nozzle as the point is edited
1418
           #endif
1427
           #endif
1419
           idle();
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
         } while (!is_lcd_clicked());
1432
         } while (!is_lcd_clicked());
1421
 
1433
 
1422
         if (!lcd_map_control) lcd_return_to_status();
1434
         if (!lcd_map_control) lcd_return_to_status();
1426
         // Let's work on specifying a proper API for the LCD ASAP, OK?
1438
         // Let's work on specifying a proper API for the LCD ASAP, OK?
1427
         lcd_external_control = true;
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
         if (click_and_hold(abort_fine_tune))
1441
         if (click_and_hold(abort_fine_tune))
1433
           goto FINE_TUNE_EXIT;
1442
           goto FINE_TUNE_EXIT;
1434
 
1443
 

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

437
             SERIAL_EOL();
437
             SERIAL_EOL();
438
           }
438
           }
439
           idle();
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
     #if ENABLED(ULTRA_LCD)
444
     #if ENABLED(ULTRA_LCD)
442
       }
445
       }
459
       SERIAL_EOL();
462
       SERIAL_EOL();
460
     }
463
     }
461
     idle();
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
   #if ENABLED(ULTRA_LCD)
471
   #if ENABLED(ULTRA_LCD)
680
   set_bed_leveling_enabled(!parser.seen('D'));
687
   set_bed_leveling_enabled(!parser.seen('D'));
681
 
688
 
682
   if (current_position[Z_AXIS] < Z_CLEARANCE_BETWEEN_PROBES) {
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
     do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
692
     do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
686
     stepper.synchronize();
693
     stepper.synchronize();
687
     set_current_from_destination();
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
   if (turn_on_heaters() != G26_OK) goto LEAVE;
698
   if (turn_on_heaters() != G26_OK) goto LEAVE;
711
 
718
 
712
   // Move nozzle to the specified height for the first layer
719
   // Move nozzle to the specified height for the first layer
713
   set_destination_from_current();
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
   destination[Z_AXIS] = g26_layer_height;
724
   destination[Z_AXIS] = g26_layer_height;
718
   move_to(destination, 0.0);
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
   move_to(destination, g26_ooze_amount);
729
   move_to(destination, g26_ooze_amount);
723
 
730
 
724
   #if ENABLED(ULTRA_LCD)
731
   #if ENABLED(ULTRA_LCD)
823
         //}
830
         //}
824
 
831
 
825
         print_line_from_here_to_there(rx, ry, g26_layer_height, xe, ye, g26_layer_height);
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
       if (look_for_lines_to_connect())
838
       if (look_for_lines_to_connect())
829
         goto LEAVE;
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
   } while (--g26_repeats && location.x_index >= 0 && location.y_index >= 0);
844
   } while (--g26_repeats && location.x_index >= 0 && location.y_index >= 0);
832
 
845
 
833
   LEAVE:
846
   LEAVE:

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

90
  * Clear the Marlin command queue
90
  * Clear the Marlin command queue
91
  */
91
  */
92
 void clear_command_queue() {
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