Fix and improve STM32F1 serial (#19464)
This commit is contained in:
@ -96,19 +96,14 @@ typedef int8_t pin_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DGUS_SERIAL_PORT
|
||||
#if !WITHIN(DGUS_SERIAL_PORT, -1, 3)
|
||||
#error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration."
|
||||
#ifdef LCD_SERIAL_PORT
|
||||
#if !WITHIN(LCD_SERIAL_PORT, -1, 3)
|
||||
#error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
|
||||
#endif
|
||||
#define DGUS_SERIAL internalDgusSerial
|
||||
#define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.get_tx_buffer_free
|
||||
#endif
|
||||
|
||||
#ifdef ANYCUBIC_LCD_SERIAL_PORT
|
||||
#if !WITHIN(ANYCUBIC_LCD_SERIAL_PORT, -1, 3)
|
||||
#error "ANYCUBIC_LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
|
||||
#define LCD_SERIAL lcdSerial
|
||||
#if HAS_DGUS_LCD
|
||||
#define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.get_tx_buffer_free()
|
||||
#endif
|
||||
#define ANYCUBIC_LCD_SERIAL anycubicLcdSerial
|
||||
#endif
|
||||
|
||||
// ------------------------
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -217,10 +217,12 @@
|
||||
static ring_buffer_pos_t available();
|
||||
static void write(const uint8_t c);
|
||||
static void flushTX();
|
||||
#ifdef DGUS_SERIAL_PORT
|
||||
#if HAS_DGUS_LCD
|
||||
static ring_buffer_pos_t get_tx_buffer_free();
|
||||
#endif
|
||||
|
||||
static inline bool emergency_parser_enabled() { return Cfg::EMERGENCYPARSER; }
|
||||
|
||||
FORCE_INLINE static uint8_t dropped() { return Cfg::DROPPED_RX ? rx_dropped_bytes : 0; }
|
||||
FORCE_INLINE static uint8_t buffer_overruns() { return Cfg::RX_OVERRUNS ? rx_buffer_overruns : 0; }
|
||||
FORCE_INLINE static uint8_t framing_errors() { return Cfg::RX_FRAMING_ERRORS ? rx_framing_errors : 0; }
|
||||
@ -278,55 +280,50 @@
|
||||
|
||||
#endif // !USBCON
|
||||
|
||||
#ifdef INTERNAL_SERIAL_PORT
|
||||
#ifdef MMU2_SERIAL_PORT
|
||||
template <uint8_t serial>
|
||||
struct MarlinInternalSerialCfg {
|
||||
struct MMU2SerialCfg {
|
||||
static constexpr int PORT = serial;
|
||||
static constexpr bool XONOFF = false;
|
||||
static constexpr bool EMERGENCYPARSER = false;
|
||||
static constexpr bool DROPPED_RX = false;
|
||||
static constexpr bool RX_FRAMING_ERRORS = false;
|
||||
static constexpr bool MAX_RX_QUEUED = false;
|
||||
static constexpr unsigned int RX_SIZE = 32;
|
||||
static constexpr unsigned int TX_SIZE = 32;
|
||||
static constexpr bool XONOFF = false;
|
||||
static constexpr bool EMERGENCYPARSER = false;
|
||||
static constexpr bool DROPPED_RX = false;
|
||||
static constexpr bool RX_OVERRUNS = false;
|
||||
static constexpr bool RX_FRAMING_ERRORS = false;
|
||||
static constexpr bool MAX_RX_QUEUED = false;
|
||||
};
|
||||
|
||||
extern MarlinSerial<MarlinInternalSerialCfg<INTERNAL_SERIAL_PORT>> internalSerial;
|
||||
extern MarlinSerial<MMU2SerialCfg<MMU2_SERIAL_PORT>> mmuSerial;
|
||||
#endif
|
||||
|
||||
#ifdef DGUS_SERIAL_PORT
|
||||
#ifdef LCD_SERIAL_PORT
|
||||
|
||||
template <uint8_t serial>
|
||||
struct MarlinInternalSerialCfg {
|
||||
static constexpr int PORT = serial;
|
||||
static constexpr unsigned int RX_SIZE = DGUS_RX_BUFFER_SIZE;
|
||||
static constexpr unsigned int TX_SIZE = DGUS_TX_BUFFER_SIZE;
|
||||
static constexpr bool XONOFF = false;
|
||||
static constexpr bool EMERGENCYPARSER = false;
|
||||
static constexpr bool DROPPED_RX = false;
|
||||
static constexpr bool RX_OVERRUNS = BOTH(HAS_DGUS_LCD, DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS);
|
||||
static constexpr bool RX_FRAMING_ERRORS = false;
|
||||
static constexpr bool MAX_RX_QUEUED = false;
|
||||
struct LCDSerialCfg {
|
||||
static constexpr int PORT = serial;
|
||||
static constexpr bool XONOFF = false;
|
||||
static constexpr bool EMERGENCYPARSER = ENABLED(EMERGENCY_PARSER);
|
||||
static constexpr bool DROPPED_RX = false;
|
||||
static constexpr bool RX_FRAMING_ERRORS = false;
|
||||
static constexpr bool MAX_RX_QUEUED = false;
|
||||
#if HAS_DGUS_LCD
|
||||
static constexpr unsigned int RX_SIZE = DGUS_RX_BUFFER_SIZE;
|
||||
static constexpr unsigned int TX_SIZE = DGUS_TX_BUFFER_SIZE;
|
||||
static constexpr bool RX_OVERRUNS = ENABLED(DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS);
|
||||
#elif EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
|
||||
static constexpr unsigned int RX_SIZE = 64;
|
||||
static constexpr unsigned int TX_SIZE = 128;
|
||||
static constexpr bool RX_OVERRUNS = false;
|
||||
#else
|
||||
static constexpr unsigned int RX_SIZE = 64;
|
||||
static constexpr unsigned int TX_SIZE = 128;
|
||||
static constexpr bool RX_OVERRUNS = false
|
||||
#endif
|
||||
};
|
||||
|
||||
extern MarlinSerial<MarlinInternalSerialCfg<DGUS_SERIAL_PORT>> internalDgusSerial;
|
||||
#endif
|
||||
extern MarlinSerial<LCDSerialCfg<LCD_SERIAL_PORT>> lcdSerial;
|
||||
|
||||
#ifdef ANYCUBIC_LCD_SERIAL_PORT
|
||||
template <uint8_t serial>
|
||||
struct AnycubicLcdSerialCfg {
|
||||
static constexpr int PORT = serial;
|
||||
static constexpr unsigned int RX_SIZE = 64;
|
||||
static constexpr unsigned int TX_SIZE = 128;
|
||||
static constexpr bool XONOFF = false;
|
||||
static constexpr bool EMERGENCYPARSER = false;
|
||||
static constexpr bool DROPPED_RX = false;
|
||||
static constexpr bool RX_OVERRUNS = false;
|
||||
static constexpr bool RX_FRAMING_ERRORS = false;
|
||||
static constexpr bool MAX_RX_QUEUED = false;
|
||||
};
|
||||
|
||||
extern MarlinSerial<AnycubicLcdSerialCfg<ANYCUBIC_LCD_SERIAL_PORT>> anycubicLcdSerial;
|
||||
#endif
|
||||
|
||||
// Use the UART for Bluetooth in AT90USB configurations
|
||||
|
@ -61,13 +61,13 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DGUS_SERIAL_PORT
|
||||
#if DGUS_SERIAL_PORT == -1
|
||||
#define DGUS_SERIAL internalDgusSerial
|
||||
#elif WITHIN(DGUS_SERIAL_PORT, 0, 3)
|
||||
#define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
|
||||
#ifdef LCD_SERIAL_PORT
|
||||
#if LCD_SERIAL_PORT == -1
|
||||
#define LCD_SERIAL lcdSerial
|
||||
#elif WITHIN(LCD_SERIAL_PORT, 0, 3)
|
||||
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
|
||||
#else
|
||||
#error "DGUS_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."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -122,6 +122,8 @@ public:
|
||||
static void write(const uint8_t c);
|
||||
static void flushTX();
|
||||
|
||||
static inline bool emergency_parser_enabled() { return Cfg::EMERGENCYPARSER; }
|
||||
|
||||
FORCE_INLINE static uint8_t dropped() { return Cfg::DROPPED_RX ? rx_dropped_bytes : 0; }
|
||||
FORCE_INLINE static uint8_t buffer_overruns() { return Cfg::RX_OVERRUNS ? rx_buffer_overruns : 0; }
|
||||
FORCE_INLINE static uint8_t framing_errors() { return Cfg::RX_FRAMING_ERRORS ? rx_framing_errors : 0; }
|
||||
|
@ -79,6 +79,7 @@ public:
|
||||
|
||||
#if ENABLED(EMERGENCY_PARSER)
|
||||
EmergencyParser::State emergency_state;
|
||||
static inline bool emergency_parser_enabled() { return true; }
|
||||
#endif
|
||||
|
||||
HalSerial() { host_connected = true; }
|
||||
|
@ -85,13 +85,13 @@ extern "C" volatile uint32_t _millis;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DGUS_SERIAL_PORT
|
||||
#if DGUS_SERIAL_PORT == -1
|
||||
#define DGUS_SERIAL UsbSerial
|
||||
#elif WITHIN(DGUS_SERIAL_PORT, 0, 3)
|
||||
#define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
|
||||
#ifdef LCD_SERIAL_PORT
|
||||
#if LCD_SERIAL_PORT == -1
|
||||
#define LCD_SERIAL UsbSerial
|
||||
#elif WITHIN(LCD_SERIAL_PORT, 0, 3)
|
||||
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
|
||||
#else
|
||||
#error "DGUS_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."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -24,28 +24,28 @@
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
#include "MarlinSerial.h"
|
||||
|
||||
#if (defined(SERIAL_PORT) && SERIAL_PORT == 0) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == 0) || (defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT == 0)
|
||||
#if USING_SERIAL_0
|
||||
MarlinSerial MSerial(LPC_UART0);
|
||||
extern "C" void UART0_IRQHandler() {
|
||||
MSerial.IRQHandler();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 || DGUS_SERIAL_PORT == 1
|
||||
#if USING_SERIAL_1
|
||||
MarlinSerial MSerial1((LPC_UART_TypeDef *) LPC_UART1);
|
||||
extern "C" void UART1_IRQHandler() {
|
||||
MSerial1.IRQHandler();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2
|
||||
#if USING_SERIAL_2
|
||||
MarlinSerial MSerial2(LPC_UART2);
|
||||
extern "C" void UART2_IRQHandler() {
|
||||
MSerial2.IRQHandler();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3
|
||||
#if USING_SERIAL_3
|
||||
MarlinSerial MSerial3(LPC_UART3);
|
||||
extern "C" void UART3_IRQHandler() {
|
||||
MSerial3.IRQHandler();
|
||||
|
@ -57,6 +57,7 @@ public:
|
||||
}
|
||||
|
||||
EmergencyParser::State emergency_state;
|
||||
static inline bool emergency_parser_enabled() { return true; }
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -92,7 +92,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
|
||||
#define ANY_TX(N,V...) DO(IS_TX##N,||,V)
|
||||
#define ANY_RX(N,V...) DO(IS_RX##N,||,V)
|
||||
|
||||
#if (defined(SERIAL_PORT) && SERIAL_PORT == 0) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == 0) || (defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT == 0)
|
||||
#if USING_SERIAL_0
|
||||
#define IS_TX0(P) (P == P0_02)
|
||||
#define IS_RX0(P) (P == P0_03)
|
||||
#if IS_TX0(TMC_SW_MISO) || IS_RX0(TMC_SW_MOSI)
|
||||
@ -106,7 +106,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
|
||||
#undef IS_RX0
|
||||
#endif
|
||||
|
||||
#if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 || DGUS_SERIAL_PORT == 1
|
||||
#if USING_SERIAL_1
|
||||
#define IS_TX1(P) (P == P0_15)
|
||||
#define IS_RX1(P) (P == P0_16)
|
||||
#define _IS_TX1_1 IS_TX1
|
||||
@ -127,7 +127,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
|
||||
#undef _IS_RX1_1
|
||||
#endif
|
||||
|
||||
#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2
|
||||
#if USING_SERIAL_2
|
||||
#define IS_TX2(P) (P == P0_10)
|
||||
#define IS_RX2(P) (P == P0_11)
|
||||
#define _IS_TX2_1 IS_TX2
|
||||
@ -161,7 +161,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
|
||||
#undef _IS_RX2_1
|
||||
#endif
|
||||
|
||||
#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3
|
||||
#if USING_SERIAL_3
|
||||
#define PIN_IS_TX3(P) (PIN_EXISTS(P) && P##_PIN == P0_00)
|
||||
#define PIN_IS_RX3(P) (P##_PIN == P0_01)
|
||||
#if PIN_IS_TX3(X_MIN) || PIN_IS_RX3(X_MAX)
|
||||
|
@ -26,7 +26,9 @@
|
||||
#if ENABLED(EMERGENCY_PARSER)
|
||||
|
||||
#include "../../feature/e_parser.h"
|
||||
|
||||
EmergencyParser::State emergency_state;
|
||||
|
||||
bool CDC_RecvCallback(const char buffer) {
|
||||
emergency_parser.update(emergency_state, buffer);
|
||||
return true;
|
||||
|
@ -56,13 +56,13 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DGUS_SERIAL_PORT
|
||||
#if DGUS_SERIAL_PORT == -1
|
||||
#define DGUS_SERIAL Serial
|
||||
#elif WITHIN(DGUS_SERIAL_PORT, 0, 3)
|
||||
#define MYSERIAL0 MSERIAL(DGUS_SERIAL_PORT)
|
||||
#ifdef LCD_SERIAL_PORT
|
||||
#if LCD_SERIAL_PORT == -1
|
||||
#define LCD_SERIAL Serial
|
||||
#elif WITHIN(LCD_SERIAL_PORT, 0, 3)
|
||||
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
|
||||
#else
|
||||
#error "DGUS_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."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -64,18 +64,7 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if HAS_DGUS_LCD
|
||||
#if DGUS_SERIAL_PORT == -1
|
||||
#define DGUS_SERIAL SerialUSB
|
||||
#elif WITHIN(DGUS_SERIAL_PORT, 1, 6)
|
||||
#define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
|
||||
#else
|
||||
#error "DGUS_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
|
||||
#endif
|
||||
#define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.availableForWrite
|
||||
#endif
|
||||
|
||||
#if ENABLED(MALYAN_LCD)
|
||||
#ifdef LCD_SERIAL_PORT
|
||||
#if LCD_SERIAL_PORT == -1
|
||||
#define LCD_SERIAL SerialUSB
|
||||
#elif WITHIN(LCD_SERIAL_PORT, 1, 6)
|
||||
@ -83,6 +72,9 @@
|
||||
#else
|
||||
#error "LCD_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
|
||||
#endif
|
||||
#if HAS_DGUS_LCD
|
||||
#define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -49,8 +49,8 @@
|
||||
DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2)
|
||||
#endif
|
||||
|
||||
#if defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT >= 0
|
||||
DECLARE_SERIAL_PORT_EXP(DGUS_SERIAL_PORT)
|
||||
#if defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT >= 0
|
||||
DECLARE_SERIAL_PORT_EXP(LCD_SERIAL_PORT)
|
||||
#endif
|
||||
|
||||
void MarlinSerial::begin(unsigned long baud, uint8_t config) {
|
||||
|
@ -35,6 +35,10 @@ public:
|
||||
#endif
|
||||
{ }
|
||||
|
||||
#if ENABLED(EMERGENCY_PARSER)
|
||||
static inline bool emergency_parser_enabled() { return true; }
|
||||
#endif
|
||||
|
||||
void begin(unsigned long baud, uint8_t config);
|
||||
inline void begin(unsigned long baud) { begin(baud, SERIAL_8N1); }
|
||||
|
||||
|
@ -68,71 +68,49 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if SERIAL_PORT == 0
|
||||
#error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
|
||||
#elif SERIAL_PORT == -1
|
||||
#define MYSERIAL0 UsbSerial
|
||||
#elif SERIAL_PORT == 1
|
||||
#define MYSERIAL0 MSerial1
|
||||
#elif SERIAL_PORT == 2
|
||||
#define MYSERIAL0 MSerial2
|
||||
#elif SERIAL_PORT == 3
|
||||
#define MYSERIAL0 MSerial3
|
||||
#elif SERIAL_PORT == 4
|
||||
#define MYSERIAL0 MSerial4
|
||||
#elif SERIAL_PORT == 5
|
||||
#define MYSERIAL0 MSerial5
|
||||
#define _MSERIAL(X) MSerial##X
|
||||
#define MSERIAL(X) _MSERIAL(X)
|
||||
|
||||
#if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY)
|
||||
#define NUM_UARTS 5
|
||||
#else
|
||||
#error "SERIAL_PORT must be from -1 to 5. Please update your configuration."
|
||||
#define NUM_UARTS 3
|
||||
#endif
|
||||
|
||||
#if SERIAL_PORT == -1
|
||||
#define MYSERIAL0 UsbSerial
|
||||
#elif WITHIN(SERIAL_PORT, 1, NUM_UARTS)
|
||||
#define MYSERIAL0 MSERIAL(SERIAL_PORT)
|
||||
#elif NUM_UARTS == 5
|
||||
#error "SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
|
||||
#else
|
||||
#error "SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
|
||||
#endif
|
||||
|
||||
#ifdef SERIAL_PORT_2
|
||||
#if SERIAL_PORT_2 == 0
|
||||
#error "SERIAL_PORT_2 cannot be 0. (Port 0 does not exist.) Please update your configuration."
|
||||
#elif SERIAL_PORT_2 == SERIAL_PORT
|
||||
#error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration."
|
||||
#elif SERIAL_PORT_2 == -1
|
||||
#if SERIAL_PORT_2 == -1
|
||||
#define MYSERIAL1 UsbSerial
|
||||
#elif SERIAL_PORT_2 == 1
|
||||
#define MYSERIAL1 MSerial1
|
||||
#elif SERIAL_PORT_2 == 2
|
||||
#define MYSERIAL1 MSerial2
|
||||
#elif SERIAL_PORT_2 == 3
|
||||
#define MYSERIAL1 MSerial3
|
||||
#elif SERIAL_PORT_2 == 4
|
||||
#define MYSERIAL1 MSerial4
|
||||
#elif SERIAL_PORT_2 == 5
|
||||
#define MYSERIAL1 MSerial5
|
||||
#elif WITHIN(SERIAL_PORT_2, 1, NUM_UARTS)
|
||||
#define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
|
||||
#elif NUM_UARTS == 5
|
||||
#error "SERIAL_PORT_2 must be -1 or from 1 to 5. Please update your configuration."
|
||||
#else
|
||||
#error "SERIAL_PORT_2 must be from -1 to 5. Please update your configuration."
|
||||
#error "SERIAL_PORT_2 must be -1 or from 1 to 3. Please update your configuration."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DGUS_SERIAL_PORT
|
||||
#if DGUS_SERIAL_PORT == 0
|
||||
#error "DGUS_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
|
||||
#elif DGUS_SERIAL_PORT == SERIAL_PORT
|
||||
#error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration."
|
||||
#elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2
|
||||
#error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
|
||||
#elif DGUS_SERIAL_PORT == -1
|
||||
#define DGUS_SERIAL UsbSerial
|
||||
#elif DGUS_SERIAL_PORT == 1
|
||||
#define DGUS_SERIAL MSerial1
|
||||
#elif DGUS_SERIAL_PORT == 2
|
||||
#define DGUS_SERIAL MSerial2
|
||||
#elif DGUS_SERIAL_PORT == 3
|
||||
#define DGUS_SERIAL MSerial3
|
||||
#elif DGUS_SERIAL_PORT == 4
|
||||
#define DGUS_SERIAL MSerial4
|
||||
#elif DGUS_SERIAL_PORT == 5
|
||||
#define DGUS_SERIAL MSerial5
|
||||
#ifdef LCD_SERIAL_PORT
|
||||
#if LCD_SERIAL_PORT == -1
|
||||
#define LCD_SERIAL UsbSerial
|
||||
#elif WITHIN(LCD_SERIAL_PORT, 1, NUM_UARTS)
|
||||
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
|
||||
#elif NUM_UARTS == 5
|
||||
#error "LCD_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
|
||||
#else
|
||||
#error "DGUS_SERIAL_PORT must be from -1 to 5. Please update your configuration."
|
||||
#error "LCD_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// Set interrupt grouping for this MCU
|
||||
void HAL_init();
|
||||
#define HAL_IDLETASK 1
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#ifdef __STM32F1__
|
||||
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "MarlinSerial.h"
|
||||
#include <libmaple/usart.h>
|
||||
|
||||
@ -53,7 +53,8 @@ static inline __always_inline void my_usart_irq(ring_buffer *rb, ring_buffer *wb
|
||||
rb_push_insert(rb, c);
|
||||
#endif
|
||||
#if ENABLED(EMERGENCY_PARSER)
|
||||
emergency_parser.update(serial.emergency_state, c);
|
||||
if (serial.emergency_parser_enabled())
|
||||
emergency_parser.update(serial.emergency_state, c);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -73,40 +74,120 @@ static inline __always_inline void my_usart_irq(ring_buffer *rb, ring_buffer *wb
|
||||
}
|
||||
}
|
||||
|
||||
#define DEFINE_HWSERIAL_MARLIN(name, n) \
|
||||
MarlinSerial name(USART##n, \
|
||||
BOARD_USART##n##_TX_PIN, \
|
||||
BOARD_USART##n##_RX_PIN); \
|
||||
extern "C" void __irq_usart##n(void) { \
|
||||
// Not every MarlinSerial port should handle emergency parsing.
|
||||
// It would not make sense to parse GCode from TMC responses, for example.
|
||||
constexpr bool serial_handles_emergency(int port) {
|
||||
return false
|
||||
#ifdef SERIAL_PORT
|
||||
|| (SERIAL_PORT) == port
|
||||
#endif
|
||||
#ifdef SERIAL_PORT_2
|
||||
|| (SERIAL_PORT_2) == port
|
||||
#endif
|
||||
#ifdef LCD_SERIAL_PORT
|
||||
|| (LCD_SERIAL_PORT) == port
|
||||
#endif
|
||||
;
|
||||
}
|
||||
|
||||
#define DEFINE_HWSERIAL_MARLIN(name, n) \
|
||||
MarlinSerial name(USART##n, \
|
||||
BOARD_USART##n##_TX_PIN, \
|
||||
BOARD_USART##n##_RX_PIN, \
|
||||
serial_handles_emergency(n)); \
|
||||
extern "C" void __irq_usart##n(void) { \
|
||||
my_usart_irq(USART##n->rb, USART##n->wb, USART##n##_BASE, MSerial##n); \
|
||||
}
|
||||
|
||||
#define DEFINE_HWSERIAL_UART_MARLIN(name, n) \
|
||||
MarlinSerial name(UART##n, \
|
||||
BOARD_USART##n##_TX_PIN, \
|
||||
BOARD_USART##n##_RX_PIN); \
|
||||
BOARD_USART##n##_TX_PIN, \
|
||||
BOARD_USART##n##_RX_PIN, \
|
||||
serial_handles_emergency(n)); \
|
||||
extern "C" void __irq_usart##n(void) { \
|
||||
my_usart_irq(USART##n->rb, USART##n->wb, USART##n##_BASE, MSerial##n); \
|
||||
my_usart_irq(UART##n->rb, UART##n->wb, UART##n##_BASE, MSerial##n); \
|
||||
}
|
||||
|
||||
#if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 || DGUS_SERIAL_PORT == 1
|
||||
DEFINE_HWSERIAL_MARLIN(MSerial1, 1);
|
||||
#endif
|
||||
|
||||
#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2
|
||||
DEFINE_HWSERIAL_MARLIN(MSerial2, 2);
|
||||
#endif
|
||||
|
||||
#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3
|
||||
DEFINE_HWSERIAL_MARLIN(MSerial3, 3);
|
||||
#endif
|
||||
|
||||
#if SERIAL_PORT == 4 || SERIAL_PORT_2 == 4 || DGUS_SERIAL_PORT == 4
|
||||
// Instantiate all UARTs even if they are not needed
|
||||
// This avoids a bunch of logic to figure out every serial
|
||||
// port which may be in use on the system.
|
||||
DEFINE_HWSERIAL_MARLIN(MSerial1, 1);
|
||||
DEFINE_HWSERIAL_MARLIN(MSerial2, 2);
|
||||
DEFINE_HWSERIAL_MARLIN(MSerial3, 3);
|
||||
#if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY)
|
||||
DEFINE_HWSERIAL_UART_MARLIN(MSerial4, 4);
|
||||
#endif
|
||||
|
||||
#if SERIAL_PORT == 5 || SERIAL_PORT_2 == 5 || DGUS_SERIAL_PORT == 5
|
||||
DEFINE_HWSERIAL_UART_MARLIN(MSerial5, 5);
|
||||
#endif
|
||||
|
||||
// Check the type of each serial port by passing it to a template function.
|
||||
// HardwareSerial is known to sometimes hang the controller when an error occurs,
|
||||
// so this case will fail the static assert. All other classes are assumed to be ok.
|
||||
template <typename T>
|
||||
constexpr bool IsSerialClassAllowed(const T&) { return true; }
|
||||
constexpr bool IsSerialClassAllowed(const HardwareSerial&) { return false; }
|
||||
|
||||
#define CHECK_CFG_SERIAL(A) static_assert(IsSerialClassAllowed(A), STRINGIFY(A) " is defined incorrectly");
|
||||
#define CHECK_AXIS_SERIAL(A) static_assert(IsSerialClassAllowed(A##_HARDWARE_SERIAL), STRINGIFY(A) "_HARDWARE_SERIAL must be defined in the form MSerial1, rather than Serial1");
|
||||
|
||||
// If you encounter this error, replace SerialX with MSerialX, for example MSerial3.
|
||||
|
||||
// Non-TMC ports were already validated in HAL.h, so do not require verbose error messages.
|
||||
#ifdef MYSERIAL0
|
||||
CHECK_CFG_SERIAL(MYSERIAL0);
|
||||
#endif
|
||||
#ifdef MYSERIAL1
|
||||
CHECK_CFG_SERIAL(MYSERIAL1);
|
||||
#endif
|
||||
#ifdef LCD_SERIAL
|
||||
CHECK_CFG_SERIAL(LCD_SERIAL);
|
||||
#endif
|
||||
#if AXIS_HAS_HW_SERIAL(X)
|
||||
CHECK_AXIS_SERIAL(X);
|
||||
#endif
|
||||
#if AXIS_HAS_HW_SERIAL(X2)
|
||||
CHECK_AXIS_SERIAL(X2);
|
||||
#endif
|
||||
#if AXIS_HAS_HW_SERIAL(Y)
|
||||
CHECK_AXIS_SERIAL(Y);
|
||||
#endif
|
||||
#if AXIS_HAS_HW_SERIAL(Y2)
|
||||
CHECK_AXIS_SERIAL(Y2);
|
||||
#endif
|
||||
#if AXIS_HAS_HW_SERIAL(Z)
|
||||
CHECK_AXIS_SERIAL(Z);
|
||||
#endif
|
||||
#if AXIS_HAS_HW_SERIAL(Z2)
|
||||
CHECK_AXIS_SERIAL(Z2);
|
||||
#endif
|
||||
#if AXIS_HAS_HW_SERIAL(Z3)
|
||||
CHECK_AXIS_SERIAL(Z3);
|
||||
#endif
|
||||
#if AXIS_HAS_HW_SERIAL(Z4)
|
||||
CHECK_AXIS_SERIAL(Z4);
|
||||
#endif
|
||||
#if AXIS_HAS_HW_SERIAL(E0)
|
||||
CHECK_AXIS_SERIAL(E0);
|
||||
#endif
|
||||
#if AXIS_HAS_HW_SERIAL(E1)
|
||||
CHECK_AXIS_SERIAL(E1);
|
||||
#endif
|
||||
#if AXIS_HAS_HW_SERIAL(E2)
|
||||
CHECK_AXIS_SERIAL(E2);
|
||||
#endif
|
||||
#if AXIS_HAS_HW_SERIAL(E3)
|
||||
CHECK_AXIS_SERIAL(E3);
|
||||
#endif
|
||||
#if AXIS_HAS_HW_SERIAL(E4)
|
||||
CHECK_AXIS_SERIAL(E4);
|
||||
#endif
|
||||
#if AXIS_HAS_HW_SERIAL(E5)
|
||||
CHECK_AXIS_SERIAL(E5);
|
||||
#endif
|
||||
#if AXIS_HAS_HW_SERIAL(E6)
|
||||
CHECK_AXIS_SERIAL(E6);
|
||||
#endif
|
||||
#if AXIS_HAS_HW_SERIAL(E7)
|
||||
CHECK_AXIS_SERIAL(E7);
|
||||
#endif
|
||||
|
||||
#endif // __STM32F1__
|
||||
|
@ -35,15 +35,22 @@
|
||||
|
||||
class MarlinSerial : public HardwareSerial {
|
||||
public:
|
||||
MarlinSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin) :
|
||||
#if ENABLED(EMERGENCY_PARSER)
|
||||
const bool ep_enabled;
|
||||
EmergencyParser::State emergency_state;
|
||||
inline bool emergency_parser_enabled() { return ep_enabled; }
|
||||
#endif
|
||||
|
||||
MarlinSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin, bool TERN_(EMERGENCY_PARSER, ep_capable)) :
|
||||
HardwareSerial(usart_device, tx_pin, rx_pin)
|
||||
#if ENABLED(EMERGENCY_PARSER)
|
||||
, ep_enabled(ep_capable)
|
||||
, emergency_state(EmergencyParser::State::EP_RESET)
|
||||
#endif
|
||||
{ }
|
||||
|
||||
#ifdef UART_IRQ_PRIO
|
||||
// shadow the parent methods to set irq priority after the begin
|
||||
// Shadow the parent methods to set IRQ priority after begin()
|
||||
void begin(uint32 baud) {
|
||||
MarlinSerial::begin(baud, SERIAL_8N1);
|
||||
}
|
||||
@ -53,14 +60,12 @@ public:
|
||||
nvic_irq_set_priority(c_dev()->irq_num, UART_IRQ_PRIO);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLED(EMERGENCY_PARSER)
|
||||
EmergencyParser::State emergency_state;
|
||||
#endif
|
||||
};
|
||||
|
||||
extern MarlinSerial MSerial1;
|
||||
extern MarlinSerial MSerial2;
|
||||
extern MarlinSerial MSerial3;
|
||||
extern MarlinSerial MSerial4;
|
||||
extern MarlinSerial MSerial5;
|
||||
#if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY)
|
||||
extern MarlinSerial MSerial4;
|
||||
extern MarlinSerial MSerial5;
|
||||
#endif
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
|
||||
#if ENABLED(EMERGENCY_PARSER)
|
||||
EmergencyParser::State emergency_state;
|
||||
inline bool emergency_parser_enabled() { return true; }
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -72,15 +72,15 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DGUS_SERIAL_PORT
|
||||
#if defined(STM32F4) && DGUS_SERIAL_PORT == 0
|
||||
#error "DGUS_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
|
||||
#elif DGUS_SERIAL_PORT == -1
|
||||
#define DGUS_SERIAL SerialUSB
|
||||
#elif WITHIN(DGUS_SERIAL_PORT, 0, 6)
|
||||
#define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
|
||||
#ifdef LCD_SERIAL_PORT
|
||||
#if defined(STM32F4) && LCD_SERIAL_PORT == 0
|
||||
#error "LCD_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
|
||||
#elif LCD_SERIAL_PORT == -1
|
||||
#define LCD_SERIAL SerialUSB
|
||||
#elif WITHIN(LCD_SERIAL_PORT, 0, 6)
|
||||
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
|
||||
#else
|
||||
#error "DGUS_SERIAL_PORT must be from -1 to 6. Please update your configuration."
|
||||
#error "LCD_SERIAL_PORT must be from -1 to 6. Please update your configuration."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user