Browse Source

MMU2 as standard serial device (#20771)

Giuliano Zaro 3 years ago
parent
commit
1d5862a39b
No account linked to committer's email address

+ 0
- 3
Marlin/Configuration_adv.h View File

@@ -3601,10 +3601,7 @@
3601 3601
   //#define E_MUX2_PIN 44  // Needed for 5 to 8 inputs
3602 3602
 #elif HAS_PRUSA_MMU2
3603 3603
   // Serial port used for communication with MMU2.
3604
-  // For AVR enable the UART port used for the MMU. (e.g., mmuSerial)
3605
-  // For 32-bit boards check your HAL for available serial ports. (e.g., Serial2)
3606 3604
   #define MMU2_SERIAL_PORT 2
3607
-  #define MMU2_SERIAL mmuSerial
3608 3605
 
3609 3606
   // Use hardware reset for MMU if a pin is defined for it
3610 3607
   //#define MMU2_RST_PIN 23

+ 7
- 0
Marlin/src/HAL/AVR/HAL.h View File

@@ -97,6 +97,13 @@ typedef int8_t pin_t;
97 97
   #endif
98 98
 #endif
99 99
 
100
+#ifdef MMU2_SERIAL_PORT
101
+  #if !WITHIN(MMU2_SERIAL_PORT, -1, 3)
102
+    #error "MMU2_SERIAL_PORT must be from -1 to 3. Please update your configuration."
103
+  #endif
104
+  #define MMU2_SERIAL mmuSerial
105
+#endif
106
+
100 107
 #ifdef LCD_SERIAL_PORT
101 108
   #if !WITHIN(LCD_SERIAL_PORT, -1, 3)
102 109
     #error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."

+ 8
- 0
Marlin/src/HAL/DUE/HAL.h View File

@@ -59,6 +59,14 @@
59 59
   #endif
60 60
 #endif
61 61
 
62
+#ifdef MMU2_SERIAL_PORT
63
+  #if WITHIN(MMU2_SERIAL_PORT, 0, 3)
64
+    #define MMU2_SERIAL MSERIAL(SERIAL_PORT)
65
+  #else
66
+    #error "MMU2_SERIAL_PORT must be from 0 to 3. Please update your configuration."
67
+  #endif
68
+#endif
69
+
62 70
 #ifdef LCD_SERIAL_PORT
63 71
   #if LCD_SERIAL_PORT == -1
64 72
     #define LCD_SERIAL lcdSerial

+ 10
- 0
Marlin/src/HAL/LPC1768/HAL.h View File

@@ -82,6 +82,16 @@ extern "C" volatile uint32_t _millis;
82 82
   #endif
83 83
 #endif
84 84
 
85
+#ifdef MMU2_SERIAL_PORT
86
+  #if MMU2_SERIAL_PORT == -1
87
+    #define MMU2_SERIAL UsbSerial
88
+  #elif WITHIN(MMU2_SERIAL_PORT, 0, 3)
89
+    #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
90
+  #else
91
+    #error "MMU2_SERIAL_PORT must be from -1 to 3. Please update your configuration."
92
+  #endif
93
+#endif
94
+
85 95
 #ifdef LCD_SERIAL_PORT
86 96
   #if LCD_SERIAL_PORT == -1
87 97
     #define LCD_SERIAL UsbSerial

+ 10
- 0
Marlin/src/HAL/SAMD51/HAL.h View File

@@ -57,6 +57,16 @@
57 57
     #endif
58 58
   #endif
59 59
 
60
+  #ifdef MMU2_SERIAL_PORT
61
+    #if MMU2_SERIAL_PORT == -1
62
+      #define MMU2_SERIAL Serial
63
+    #elif WITHIN(MMU2_SERIAL_PORT, 0, 3)
64
+      #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
65
+    #else
66
+      #error "MMU2_SERIAL_PORT must be from -1 to 3. Please update your configuration."
67
+    #endif
68
+  #endif
69
+
60 70
   #ifdef LCD_SERIAL_PORT
61 71
     #if LCD_SERIAL_PORT == -1
62 72
       #define LCD_SERIAL Serial

+ 4
- 4
Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.cpp View File

@@ -21,13 +21,13 @@
21 21
 #ifdef ADAFRUIT_GRAND_CENTRAL_M4
22 22
 
23 23
 /**
24
- * Framework doesn't define some serial to save sercom resources
24
+ * Framework doesn't define some serials to save sercom resources
25 25
  * hence if these are used I need to define them
26 26
  */
27 27
 
28 28
 #include "../../inc/MarlinConfig.h"
29 29
 
30
-#if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1
30
+#if USING_SERIAL_1
31 31
   Uart Serial2(&sercom4, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX);
32 32
   void SERCOM4_0_Handler() { Serial2.IrqHandler(); }
33 33
   void SERCOM4_1_Handler() { Serial2.IrqHandler(); }
@@ -35,7 +35,7 @@
35 35
   void SERCOM4_3_Handler() { Serial2.IrqHandler(); }
36 36
 #endif
37 37
 
38
-#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2
38
+#if USING_SERIAL_2
39 39
   Uart Serial3(&sercom1, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX);
40 40
   void SERCOM1_0_Handler() { Serial3.IrqHandler(); }
41 41
   void SERCOM1_1_Handler() { Serial3.IrqHandler(); }
@@ -43,7 +43,7 @@
43 43
   void SERCOM1_3_Handler() { Serial3.IrqHandler(); }
44 44
 #endif
45 45
 
46
-#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3
46
+#if USING_SERIAL_3
47 47
   Uart Serial4(&sercom5, PIN_SERIAL4_RX, PIN_SERIAL4_TX, PAD_SERIAL4_RX, PAD_SERIAL4_TX);
48 48
   void SERCOM5_0_Handler() { Serial4.IrqHandler(); }
49 49
   void SERCOM5_1_Handler() { Serial4.IrqHandler(); }

+ 10
- 0
Marlin/src/HAL/STM32/HAL.h View File

@@ -65,6 +65,16 @@
65 65
   #endif
66 66
 #endif
67 67
 
68
+#ifdef MMU2_SERIAL_PORT
69
+  #if MMU2_SERIAL_PORT == -1
70
+    #define MMU2_SERIAL SerialUSB
71
+  #elif WITHIN(MMU2_SERIAL_PORT, 1, 6)
72
+    #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
73
+  #else
74
+    #error "MMU2_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
75
+  #endif
76
+#endif
77
+
68 78
 #ifdef LCD_SERIAL_PORT
69 79
   #if LCD_SERIAL_PORT == -1
70 80
     #define LCD_SERIAL SerialUSB

+ 4
- 0
Marlin/src/HAL/STM32/MarlinSerial.cpp View File

@@ -48,6 +48,10 @@
48 48
   DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2)
49 49
 #endif
50 50
 
51
+#if defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT >= 0
52
+  DECLARE_SERIAL_PORT_EXP(MMU2_SERIAL_PORT)
53
+#endif
54
+
51 55
 #if defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT >= 0
52 56
   DECLARE_SERIAL_PORT_EXP(LCD_SERIAL_PORT)
53 57
 #endif

+ 12
- 0
Marlin/src/HAL/STM32F1/HAL.h View File

@@ -99,6 +99,18 @@
99 99
   #endif
100 100
 #endif
101 101
 
102
+#ifdef MMU2_SERIAL_PORT
103
+  #if MMU2_SERIAL_PORT == -1
104
+    #define MMU2_SERIAL UsbSerial
105
+  #elif WITHIN(MMU2_SERIAL_PORT, 1, NUM_UARTS)
106
+    #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
107
+  #elif NUM_UARTS == 5
108
+    #error "MMU2_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
109
+  #else
110
+    #error "MMU2_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
111
+  #endif
112
+#endif
113
+
102 114
 #ifdef LCD_SERIAL_PORT
103 115
   #if LCD_SERIAL_PORT == -1
104 116
     #define LCD_SERIAL UsbSerial

+ 7
- 9
Marlin/src/feature/mmu/mmu2.cpp View File

@@ -91,8 +91,6 @@ MMU2 mmu2;
91 91
 #define MMU2_NO_TOOL 99
92 92
 #define MMU_BAUD    115200
93 93
 
94
-#define mmuSerial   MMU2_SERIAL
95
-
96 94
 bool MMU2::enabled, MMU2::ready, MMU2::mmu_print_saved;
97 95
 #if HAS_PRUSA_MMU2S
98 96
   bool MMU2::mmu2s_triggered;
@@ -132,7 +130,7 @@ void MMU2::init() {
132 130
     SET_OUTPUT(MMU2_RST_PIN);
133 131
   #endif
134 132
 
135
-  mmuSerial.begin(MMU_BAUD);
133
+  MMU2_SERIAL.begin(MMU_BAUD);
136 134
   extruder = MMU2_NO_TOOL;
137 135
 
138 136
   safe_delay(10);
@@ -385,8 +383,8 @@ bool MMU2::rx_start() {
385 383
 bool MMU2::rx_str_P(const char* str) {
386 384
   uint8_t i = strlen(rx_buffer);
387 385
 
388
-  while (mmuSerial.available()) {
389
-    rx_buffer[i++] = mmuSerial.read();
386
+  while (MMU2_SERIAL.available()) {
387
+    rx_buffer[i++] = MMU2_SERIAL.read();
390 388
     rx_buffer[i] = '\0';
391 389
 
392 390
     if (i == sizeof(rx_buffer) - 1) {
@@ -417,7 +415,7 @@ bool MMU2::rx_str_P(const char* str) {
417 415
 void MMU2::tx_str_P(const char* str) {
418 416
   clear_rx_buffer();
419 417
   uint8_t len = strlen_P(str);
420
-  LOOP_L_N(i, len) mmuSerial.write(pgm_read_byte(str++));
418
+  LOOP_L_N(i, len) MMU2_SERIAL.write(pgm_read_byte(str++));
421 419
   rx_buffer[0] = '\0';
422 420
   prev_request = millis();
423 421
 }
@@ -428,7 +426,7 @@ void MMU2::tx_str_P(const char* str) {
428 426
 void MMU2::tx_printf_P(const char* format, int argument = -1) {
429 427
   clear_rx_buffer();
430 428
   uint8_t len = sprintf_P(tx_buffer, format, argument);
431
-  LOOP_L_N(i, len) mmuSerial.write(tx_buffer[i]);
429
+  LOOP_L_N(i, len) MMU2_SERIAL.write(tx_buffer[i]);
432 430
   rx_buffer[0] = '\0';
433 431
   prev_request = millis();
434 432
 }
@@ -439,7 +437,7 @@ void MMU2::tx_printf_P(const char* format, int argument = -1) {
439 437
 void MMU2::tx_printf_P(const char* format, int argument1, int argument2) {
440 438
   clear_rx_buffer();
441 439
   uint8_t len = sprintf_P(tx_buffer, format, argument1, argument2);
442
-  LOOP_L_N(i, len) mmuSerial.write(tx_buffer[i]);
440
+  LOOP_L_N(i, len) MMU2_SERIAL.write(tx_buffer[i]);
443 441
   rx_buffer[0] = '\0';
444 442
   prev_request = millis();
445 443
 }
@@ -448,7 +446,7 @@ void MMU2::tx_printf_P(const char* format, int argument1, int argument2) {
448 446
  * Empty the rx buffer
449 447
  */
450 448
 void MMU2::clear_rx_buffer() {
451
-  while (mmuSerial.available()) mmuSerial.read();
449
+  while (MMU2_SERIAL.available()) MMU2_SERIAL.read();
452 450
   rx_buffer[0] = '\0';
453 451
 }
454 452
 

+ 4
- 1
Marlin/src/inc/Conditionals_adv.h View File

@@ -512,7 +512,10 @@
512 512
 #endif
513 513
 
514 514
 // Flag the indexed serial ports that are in use
515
-#define ANY_SERIAL_IS(N) (defined(SERIAL_PORT) && SERIAL_PORT == (N)) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == (N)) || (defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == (N))
515
+#define ANY_SERIAL_IS(N) (defined(SERIAL_PORT) && SERIAL_PORT == (N)) || \
516
+                         (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == (N)) || \
517
+                         (defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT == (N)) || \
518
+                         (defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == (N))
516 519
 #if ANY_SERIAL_IS(-1)
517 520
   #define USING_SERIAL_DEFAULT
518 521
 #endif

+ 15
- 4
Marlin/src/inc/SanityCheck.h View File

@@ -588,10 +588,6 @@
588 588
   #error "SERIAL_PORT must be defined."
589 589
 #elif defined(SERIAL_PORT_2) && SERIAL_PORT_2 == SERIAL_PORT
590 590
   #error "SERIAL_PORT_2 cannot be the same as SERIAL_PORT."
591
-#elif defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == SERIAL_PORT
592
-  #error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT."
593
-#elif defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == SERIAL_PORT_2
594
-  #error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT_2."
595 591
 #endif
596 592
 #if !(defined(__AVR__) && defined(USBCON))
597 593
   #if ENABLED(SERIAL_XON_XOFF) && RX_BUFFER_SIZE < 1024
@@ -2389,12 +2385,27 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
2389 2385
     #error "SERIAL_PORT is set to -1, but the MOTHERBOARD has no native USB support. Set SERIAL_PORT to a valid value for your board."
2390 2386
   #elif SERIAL_PORT_2 == -1
2391 2387
     #error "SERIAL_PORT_2 is set to -1, but the MOTHERBOARD has no native USB support. Set SERIAL_PORT_2 to a valid value for your board."
2388
+  #elif MMU2_SERIAL_PORT == -1
2389
+    #error "MMU2_SERIAL_PORT is set to -1, but the MOTHERBOARD has no native USB support. Set MMU2_SERIAL_PORT to a valid value for your board."
2392 2390
   #elif LCD_SERIAL_PORT == -1
2393 2391
     #error "LCD_SERIAL_PORT is set to -1, but the MOTHERBOARD has no native USB support. Set LCD_SERIAL_PORT to a valid value for your board."
2394 2392
   #endif
2395 2393
 #endif
2396 2394
 
2397 2395
 /**
2396
+ * MMU2 require a dedicated serial port
2397
+ */
2398
+#ifdef MMU2_SERIAL_PORT
2399
+  #if MMU2_SERIAL_PORT == SERIAL_PORT
2400
+    #error "MMU2_SERIAL_PORT cannot be the same as SERIAL_PORT."
2401
+  #elif defined(SERIAL_PORT_2) && MMU2_SERIAL_PORT == SERIAL_PORT_2
2402
+    #error "MMU2_SERIAL_PORT cannot be the same as SERIAL_PORT_2."
2403
+  #elif defined(LCD_SERIAL_PORT) && MMU2_SERIAL_PORT == LCD_SERIAL_PORT
2404
+    #error "MMU2_SERIAL_PORT cannot be the same as LCD_SERIAL_PORT."
2405
+  #endif
2406
+#endif
2407
+
2408
+/**
2398 2409
  * Serial displays require a dedicated serial port
2399 2410
  */
2400 2411
 #ifdef LCD_SERIAL_PORT

Loading…
Cancel
Save