@ -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 ) ;
// 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 ) ;
DEFINE_HWSERIAL_UART_MARLIN ( MSerial5 , 5 ) ;
# endif
# if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2
DEFINE_HWSERIAL_MARLIN ( MSerial2 , 2 ) ;
# 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 ; }
# if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3
DEFINE_HWSERIAL_MARLIN ( MSerial3 , 3 ) ;
# endif
# 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 SERIAL_PORT == 4 || SERIAL_PORT_2 == 4 || DGUS_SERIAL_PORT == 4
DEFINE_HWSERIAL_UART_MARLIN ( MSerial4 , 4 ) ;
# endif
// If you encounter this error, replace SerialX with MSerialX, for example MSerial3.
# if SERIAL_PORT == 5 || SERIAL_PORT_2 == 5 || DGUS_SERIAL_PORT == 5
DEFINE_HWSERIAL_UART_MARLIN ( MSerial5 , 5 ) ;
// 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__