Browse Source

MMU2 as standard serial device (#20771)

vanilla_fb_2.0.x
Giuliano Zaro 4 years ago
committed by GitHub
parent
commit
1d5862a39b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      Marlin/Configuration_adv.h
  2. 7
      Marlin/src/HAL/AVR/HAL.h
  3. 8
      Marlin/src/HAL/DUE/HAL.h
  4. 10
      Marlin/src/HAL/LPC1768/HAL.h
  5. 10
      Marlin/src/HAL/SAMD51/HAL.h
  6. 8
      Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.cpp
  7. 10
      Marlin/src/HAL/STM32/HAL.h
  8. 4
      Marlin/src/HAL/STM32/MarlinSerial.cpp
  9. 12
      Marlin/src/HAL/STM32F1/HAL.h
  10. 16
      Marlin/src/feature/mmu/mmu2.cpp
  11. 5
      Marlin/src/inc/Conditionals_adv.h
  12. 19
      Marlin/src/inc/SanityCheck.h

3
Marlin/Configuration_adv.h

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

7
Marlin/src/HAL/AVR/HAL.h

@ -97,6 +97,13 @@ typedef int8_t pin_t;
#endif #endif
#endif #endif
#ifdef MMU2_SERIAL_PORT
#if !WITHIN(MMU2_SERIAL_PORT, -1, 3)
#error "MMU2_SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif
#define MMU2_SERIAL mmuSerial
#endif
#ifdef LCD_SERIAL_PORT #ifdef LCD_SERIAL_PORT
#if !WITHIN(LCD_SERIAL_PORT, -1, 3) #if !WITHIN(LCD_SERIAL_PORT, -1, 3)
#error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration." #error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."

8
Marlin/src/HAL/DUE/HAL.h

@ -59,6 +59,14 @@
#endif #endif
#endif #endif
#ifdef MMU2_SERIAL_PORT
#if WITHIN(MMU2_SERIAL_PORT, 0, 3)
#define MMU2_SERIAL MSERIAL(SERIAL_PORT)
#else
#error "MMU2_SERIAL_PORT must be from 0 to 3. Please update your configuration."
#endif
#endif
#ifdef LCD_SERIAL_PORT #ifdef LCD_SERIAL_PORT
#if LCD_SERIAL_PORT == -1 #if LCD_SERIAL_PORT == -1
#define LCD_SERIAL lcdSerial #define LCD_SERIAL lcdSerial

10
Marlin/src/HAL/LPC1768/HAL.h

@ -82,6 +82,16 @@ extern "C" volatile uint32_t _millis;
#endif #endif
#endif #endif
#ifdef MMU2_SERIAL_PORT
#if MMU2_SERIAL_PORT == -1
#define MMU2_SERIAL UsbSerial
#elif WITHIN(MMU2_SERIAL_PORT, 0, 3)
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
#else
#error "MMU2_SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif
#endif
#ifdef LCD_SERIAL_PORT #ifdef LCD_SERIAL_PORT
#if LCD_SERIAL_PORT == -1 #if LCD_SERIAL_PORT == -1
#define LCD_SERIAL UsbSerial #define LCD_SERIAL UsbSerial

10
Marlin/src/HAL/SAMD51/HAL.h

@ -57,6 +57,16 @@
#endif #endif
#endif #endif
#ifdef MMU2_SERIAL_PORT
#if MMU2_SERIAL_PORT == -1
#define MMU2_SERIAL Serial
#elif WITHIN(MMU2_SERIAL_PORT, 0, 3)
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
#else
#error "MMU2_SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif
#endif
#ifdef LCD_SERIAL_PORT #ifdef LCD_SERIAL_PORT
#if LCD_SERIAL_PORT == -1 #if LCD_SERIAL_PORT == -1
#define LCD_SERIAL Serial #define LCD_SERIAL Serial

8
Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.cpp

@ -21,13 +21,13 @@
#ifdef ADAFRUIT_GRAND_CENTRAL_M4 #ifdef ADAFRUIT_GRAND_CENTRAL_M4
/** /**
* Framework doesn't define some serial to save sercom resources * Framework doesn't define some serials to save sercom resources
* hence if these are used I need to define them * hence if these are used I need to define them
*/ */
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 #if USING_SERIAL_1
Uart Serial2(&sercom4, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX); Uart Serial2(&sercom4, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX);
void SERCOM4_0_Handler() { Serial2.IrqHandler(); } void SERCOM4_0_Handler() { Serial2.IrqHandler(); }
void SERCOM4_1_Handler() { Serial2.IrqHandler(); } void SERCOM4_1_Handler() { Serial2.IrqHandler(); }
@ -35,7 +35,7 @@
void SERCOM4_3_Handler() { Serial2.IrqHandler(); } void SERCOM4_3_Handler() { Serial2.IrqHandler(); }
#endif #endif
#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 #if USING_SERIAL_2
Uart Serial3(&sercom1, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX); Uart Serial3(&sercom1, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX);
void SERCOM1_0_Handler() { Serial3.IrqHandler(); } void SERCOM1_0_Handler() { Serial3.IrqHandler(); }
void SERCOM1_1_Handler() { Serial3.IrqHandler(); } void SERCOM1_1_Handler() { Serial3.IrqHandler(); }
@ -43,7 +43,7 @@
void SERCOM1_3_Handler() { Serial3.IrqHandler(); } void SERCOM1_3_Handler() { Serial3.IrqHandler(); }
#endif #endif
#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 #if USING_SERIAL_3
Uart Serial4(&sercom5, PIN_SERIAL4_RX, PIN_SERIAL4_TX, PAD_SERIAL4_RX, PAD_SERIAL4_TX); Uart Serial4(&sercom5, PIN_SERIAL4_RX, PIN_SERIAL4_TX, PAD_SERIAL4_RX, PAD_SERIAL4_TX);
void SERCOM5_0_Handler() { Serial4.IrqHandler(); } void SERCOM5_0_Handler() { Serial4.IrqHandler(); }
void SERCOM5_1_Handler() { Serial4.IrqHandler(); } void SERCOM5_1_Handler() { Serial4.IrqHandler(); }

10
Marlin/src/HAL/STM32/HAL.h

@ -65,6 +65,16 @@
#endif #endif
#endif #endif
#ifdef MMU2_SERIAL_PORT
#if MMU2_SERIAL_PORT == -1
#define MMU2_SERIAL SerialUSB
#elif WITHIN(MMU2_SERIAL_PORT, 1, 6)
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
#else
#error "MMU2_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
#endif
#endif
#ifdef LCD_SERIAL_PORT #ifdef LCD_SERIAL_PORT
#if LCD_SERIAL_PORT == -1 #if LCD_SERIAL_PORT == -1
#define LCD_SERIAL SerialUSB #define LCD_SERIAL SerialUSB

4
Marlin/src/HAL/STM32/MarlinSerial.cpp

@ -48,6 +48,10 @@
DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2) DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2)
#endif #endif
#if defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT >= 0
DECLARE_SERIAL_PORT_EXP(MMU2_SERIAL_PORT)
#endif
#if defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT >= 0 #if defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT >= 0
DECLARE_SERIAL_PORT_EXP(LCD_SERIAL_PORT) DECLARE_SERIAL_PORT_EXP(LCD_SERIAL_PORT)
#endif #endif

12
Marlin/src/HAL/STM32F1/HAL.h

@ -99,6 +99,18 @@
#endif #endif
#endif #endif
#ifdef MMU2_SERIAL_PORT
#if MMU2_SERIAL_PORT == -1
#define MMU2_SERIAL UsbSerial
#elif WITHIN(MMU2_SERIAL_PORT, 1, NUM_UARTS)
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
#elif NUM_UARTS == 5
#error "MMU2_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
#else
#error "MMU2_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
#endif
#endif
#ifdef LCD_SERIAL_PORT #ifdef LCD_SERIAL_PORT
#if LCD_SERIAL_PORT == -1 #if LCD_SERIAL_PORT == -1
#define LCD_SERIAL UsbSerial #define LCD_SERIAL UsbSerial

16
Marlin/src/feature/mmu/mmu2.cpp

@ -91,8 +91,6 @@ MMU2 mmu2;
#define MMU2_NO_TOOL 99 #define MMU2_NO_TOOL 99
#define MMU_BAUD 115200 #define MMU_BAUD 115200
#define mmuSerial MMU2_SERIAL
bool MMU2::enabled, MMU2::ready, MMU2::mmu_print_saved; bool MMU2::enabled, MMU2::ready, MMU2::mmu_print_saved;
#if HAS_PRUSA_MMU2S #if HAS_PRUSA_MMU2S
bool MMU2::mmu2s_triggered; bool MMU2::mmu2s_triggered;
@ -132,7 +130,7 @@ void MMU2::init() {
SET_OUTPUT(MMU2_RST_PIN); SET_OUTPUT(MMU2_RST_PIN);
#endif #endif
mmuSerial.begin(MMU_BAUD); MMU2_SERIAL.begin(MMU_BAUD);
extruder = MMU2_NO_TOOL; extruder = MMU2_NO_TOOL;
safe_delay(10); safe_delay(10);
@ -385,8 +383,8 @@ bool MMU2::rx_start() {
bool MMU2::rx_str_P(const char* str) { bool MMU2::rx_str_P(const char* str) {
uint8_t i = strlen(rx_buffer); uint8_t i = strlen(rx_buffer);
while (mmuSerial.available()) { while (MMU2_SERIAL.available()) {
rx_buffer[i++] = mmuSerial.read(); rx_buffer[i++] = MMU2_SERIAL.read();
rx_buffer[i] = '\0'; rx_buffer[i] = '\0';
if (i == sizeof(rx_buffer) - 1) { if (i == sizeof(rx_buffer) - 1) {
@ -417,7 +415,7 @@ bool MMU2::rx_str_P(const char* str) {
void MMU2::tx_str_P(const char* str) { void MMU2::tx_str_P(const char* str) {
clear_rx_buffer(); clear_rx_buffer();
uint8_t len = strlen_P(str); uint8_t len = strlen_P(str);
LOOP_L_N(i, len) mmuSerial.write(pgm_read_byte(str++)); LOOP_L_N(i, len) MMU2_SERIAL.write(pgm_read_byte(str++));
rx_buffer[0] = '\0'; rx_buffer[0] = '\0';
prev_request = millis(); prev_request = millis();
} }
@ -428,7 +426,7 @@ void MMU2::tx_str_P(const char* str) {
void MMU2::tx_printf_P(const char* format, int argument = -1) { void MMU2::tx_printf_P(const char* format, int argument = -1) {
clear_rx_buffer(); clear_rx_buffer();
uint8_t len = sprintf_P(tx_buffer, format, argument); uint8_t len = sprintf_P(tx_buffer, format, argument);
LOOP_L_N(i, len) mmuSerial.write(tx_buffer[i]); LOOP_L_N(i, len) MMU2_SERIAL.write(tx_buffer[i]);
rx_buffer[0] = '\0'; rx_buffer[0] = '\0';
prev_request = millis(); prev_request = millis();
} }
@ -439,7 +437,7 @@ void MMU2::tx_printf_P(const char* format, int argument = -1) {
void MMU2::tx_printf_P(const char* format, int argument1, int argument2) { void MMU2::tx_printf_P(const char* format, int argument1, int argument2) {
clear_rx_buffer(); clear_rx_buffer();
uint8_t len = sprintf_P(tx_buffer, format, argument1, argument2); uint8_t len = sprintf_P(tx_buffer, format, argument1, argument2);
LOOP_L_N(i, len) mmuSerial.write(tx_buffer[i]); LOOP_L_N(i, len) MMU2_SERIAL.write(tx_buffer[i]);
rx_buffer[0] = '\0'; rx_buffer[0] = '\0';
prev_request = millis(); prev_request = millis();
} }
@ -448,7 +446,7 @@ void MMU2::tx_printf_P(const char* format, int argument1, int argument2) {
* Empty the rx buffer * Empty the rx buffer
*/ */
void MMU2::clear_rx_buffer() { void MMU2::clear_rx_buffer() {
while (mmuSerial.available()) mmuSerial.read(); while (MMU2_SERIAL.available()) MMU2_SERIAL.read();
rx_buffer[0] = '\0'; rx_buffer[0] = '\0';
} }

5
Marlin/src/inc/Conditionals_adv.h

@ -512,7 +512,10 @@
#endif #endif
// Flag the indexed serial ports that are in use // Flag the indexed serial ports that are in use
#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)) #define ANY_SERIAL_IS(N) (defined(SERIAL_PORT) && SERIAL_PORT == (N)) || \
(defined(SERIAL_PORT_2) && SERIAL_PORT_2 == (N)) || \
(defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT == (N)) || \
(defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == (N))
#if ANY_SERIAL_IS(-1) #if ANY_SERIAL_IS(-1)
#define USING_SERIAL_DEFAULT #define USING_SERIAL_DEFAULT
#endif #endif

19
Marlin/src/inc/SanityCheck.h

@ -588,10 +588,6 @@
#error "SERIAL_PORT must be defined." #error "SERIAL_PORT must be defined."
#elif defined(SERIAL_PORT_2) && SERIAL_PORT_2 == SERIAL_PORT #elif defined(SERIAL_PORT_2) && SERIAL_PORT_2 == SERIAL_PORT
#error "SERIAL_PORT_2 cannot be the same as SERIAL_PORT." #error "SERIAL_PORT_2 cannot be the same as SERIAL_PORT."
#elif defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == SERIAL_PORT
#error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT."
#elif defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == SERIAL_PORT_2
#error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT_2."
#endif #endif
#if !(defined(__AVR__) && defined(USBCON)) #if !(defined(__AVR__) && defined(USBCON))
#if ENABLED(SERIAL_XON_XOFF) && RX_BUFFER_SIZE < 1024 #if ENABLED(SERIAL_XON_XOFF) && RX_BUFFER_SIZE < 1024
@ -2389,11 +2385,26 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
#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." #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."
#elif SERIAL_PORT_2 == -1 #elif SERIAL_PORT_2 == -1
#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." #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."
#elif MMU2_SERIAL_PORT == -1
#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."
#elif LCD_SERIAL_PORT == -1 #elif LCD_SERIAL_PORT == -1
#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." #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."
#endif #endif
#endif #endif
/**
* MMU2 require a dedicated serial port
*/
#ifdef MMU2_SERIAL_PORT
#if MMU2_SERIAL_PORT == SERIAL_PORT
#error "MMU2_SERIAL_PORT cannot be the same as SERIAL_PORT."
#elif defined(SERIAL_PORT_2) && MMU2_SERIAL_PORT == SERIAL_PORT_2
#error "MMU2_SERIAL_PORT cannot be the same as SERIAL_PORT_2."
#elif defined(LCD_SERIAL_PORT) && MMU2_SERIAL_PORT == LCD_SERIAL_PORT
#error "MMU2_SERIAL_PORT cannot be the same as LCD_SERIAL_PORT."
#endif
#endif
/** /**
* Serial displays require a dedicated serial port * Serial displays require a dedicated serial port
*/ */

Loading…
Cancel
Save