|
@@ -0,0 +1,93 @@
|
|
1
|
+/**
|
|
2
|
+ * Marlin 3D Printer Firmware
|
|
3
|
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
4
|
+ *
|
|
5
|
+ * Based on Sprinter and grbl.
|
|
6
|
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
7
|
+ *
|
|
8
|
+ * This program is free software: you can redistribute it and/or modify
|
|
9
|
+ * it under the terms of the GNU General Public License as published by
|
|
10
|
+ * the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+ * (at your option) any later version.
|
|
12
|
+ *
|
|
13
|
+ * This program is distributed in the hope that it will be useful,
|
|
14
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+ * GNU General Public License for more details.
|
|
17
|
+ *
|
|
18
|
+ * You should have received a copy of the GNU General Public License
|
|
19
|
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
|
+ *
|
|
21
|
+ */
|
|
22
|
+
|
|
23
|
+#include "../../inc/MarlinConfigPre.h"
|
|
24
|
+#include "MarlinSerial.h"
|
|
25
|
+#include <libmaple/usart.h>
|
|
26
|
+
|
|
27
|
+// Copied from ~/.platformio/packages/framework-arduinoststm32-maple/STM32F1/system/libmaple/usart_private.h
|
|
28
|
+// Changed to handle Emergency Parser
|
|
29
|
+static inline __always_inline void my_usart_irq(ring_buffer *rb, ring_buffer *wb, usart_reg_map *regs, MarlinSerial &serial) {
|
|
30
|
+ /* Handle RXNEIE and TXEIE interrupts.
|
|
31
|
+ * RXNE signifies availability of a byte in DR.
|
|
32
|
+ *
|
|
33
|
+ * See table 198 (sec 27.4, p809) in STM document RM0008 rev 15.
|
|
34
|
+ * We enable RXNEIE.
|
|
35
|
+ */
|
|
36
|
+ if ((regs->CR1 & USART_CR1_RXNEIE) && (regs->SR & USART_SR_RXNE)) {
|
|
37
|
+ uint8_t c = (uint8)regs->DR;
|
|
38
|
+ #ifdef USART_SAFE_INSERT
|
|
39
|
+ // If the buffer is full and the user defines USART_SAFE_INSERT,
|
|
40
|
+ // ignore new bytes.
|
|
41
|
+ rb_safe_insert(rb, c);
|
|
42
|
+ #else
|
|
43
|
+ // By default, push bytes around in the ring buffer.
|
|
44
|
+ rb_push_insert(rb, c);
|
|
45
|
+ #endif
|
|
46
|
+ #if ENABLED(EMERGENCY_PARSER)
|
|
47
|
+ emergency_parser.update(serial.emergency_state, c);
|
|
48
|
+ #endif
|
|
49
|
+ }
|
|
50
|
+ // TXE signifies readiness to send a byte to DR.
|
|
51
|
+ if ((regs->CR1 & USART_CR1_TXEIE) && (regs->SR & USART_SR_TXE)) {
|
|
52
|
+ if (!rb_is_empty(wb))
|
|
53
|
+ regs->DR=rb_remove(wb);
|
|
54
|
+ else
|
|
55
|
+ regs->CR1 &= ~((uint32)USART_CR1_TXEIE); // disable TXEIE
|
|
56
|
+ }
|
|
57
|
+}
|
|
58
|
+
|
|
59
|
+#define DEFINE_HWSERIAL_MARLIN(name, n) \
|
|
60
|
+ MarlinSerial name(USART##n, \
|
|
61
|
+ BOARD_USART##n##_TX_PIN, \
|
|
62
|
+ BOARD_USART##n##_RX_PIN); \
|
|
63
|
+ extern "C" void __irq_usart##n(void) { \
|
|
64
|
+ my_usart_irq(USART##n->rb, USART##n->wb, USART##n##_BASE, MSerial##n); \
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+#define DEFINE_HWSERIAL_UART_MARLIN(name, n) \
|
|
68
|
+ MarlinSerial name(UART##n, \
|
|
69
|
+ BOARD_USART##n##_TX_PIN, \
|
|
70
|
+ BOARD_USART##n##_RX_PIN); \
|
|
71
|
+ extern "C" void __irq_usart##n(void) { \
|
|
72
|
+ my_usart_irq(USART##n->rb, USART##n->wb, USART##n##_BASE, MSerial##n); \
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+#if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 || DGUS_SERIAL_PORT == 1
|
|
76
|
+ DEFINE_HWSERIAL_MARLIN(MSerial1, 1);
|
|
77
|
+#endif
|
|
78
|
+
|
|
79
|
+#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2
|
|
80
|
+ DEFINE_HWSERIAL_MARLIN(MSerial2, 2);
|
|
81
|
+#endif
|
|
82
|
+
|
|
83
|
+#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3
|
|
84
|
+ DEFINE_HWSERIAL_MARLIN(MSerial3, 3);
|
|
85
|
+#endif
|
|
86
|
+
|
|
87
|
+#if SERIAL_PORT == 4 || SERIAL_PORT_2 == 4 || DGUS_SERIAL_PORT == 4
|
|
88
|
+ DEFINE_HWSERIAL_UART_MARLIN(MSerial4, 4);
|
|
89
|
+#endif
|
|
90
|
+
|
|
91
|
+#if SERIAL_PORT == 5 || SERIAL_PORT_2 == 5 || DGUS_SERIAL_PORT == 5
|
|
92
|
+ DEFINE_HWSERIAL_UART_MARLIN(MSerial5, 5);
|
|
93
|
+#endif
|