Переглянути джерело

[ESP32] Allow user to define pins for hardware Serial1 and Serial2 (#16918)

vivian-ng 4 роки тому
джерело
коміт
eeec4c27e7
Аккаунт користувача з таким Email не знайдено

+ 22
- 0
Marlin/src/HAL/HAL_ESP32/HAL.cpp Переглянути файл

@@ -27,6 +27,7 @@
27 27
 #include <rom/rtc.h>
28 28
 #include <driver/adc.h>
29 29
 #include <esp_adc_cal.h>
30
+#include <HardwareSerial.h>
30 31
 
31 32
 #include "../../inc/MarlinConfigPre.h"
32 33
 
@@ -105,6 +106,27 @@ void HAL_init_board() {
105 106
     #endif
106 107
     server.begin();
107 108
   #endif
109
+
110
+  // ESP32 uses a GPIO matrix that allows pins to be assigned to hardware serial ports.
111
+  // The following code initializes hardware Serial1 and Serial2 to use user-defined pins
112
+  // if they have been defined.
113
+  #if defined(HARDWARE_SERIAL1_RX) && defined(HARDWARE_SERIAL1_TX)
114
+    HardwareSerial Serial1(1);
115
+    #ifdef TMC_BAUD_RATE  // use TMC_BAUD_RATE for Serial1 if defined
116
+      Serial1.begin(TMC_BAUD_RATE, SERIAL_8N1, HARDWARE_SERIAL1_RX, HARDWARE_SERIAL1_TX);
117
+    #else  // use default BAUDRATE if TMC_BAUD_RATE not defined
118
+      Serial1.begin(BAUDRATE, SERIAL_8N1, HARDWARE_SERIAL1_RX, HARDWARE_SERIAL1_TX);
119
+    #endif
120
+  #endif
121
+  #if defined(HARDWARE_SERIAL2_RX) && defined(HARDWARE_SERIAL2_TX)
122
+    HardwareSerial Serial2(2);
123
+    #ifdef TMC_BAUD_RATE  // use TMC_BAUD_RATE for Serial1 if defined
124
+      Serial2.begin(TMC_BAUD_RATE, SERIAL_8N1, HARDWARE_SERIAL2_RX, HARDWARE_SERIAL2_TX);
125
+    #else  // use default BAUDRATE if TMC_BAUD_RATE not defined
126
+      Serial2.begin(BAUDRATE, SERIAL_8N1, HARDWARE_SERIAL2_RX, HARDWARE_SERIAL2_TX);
127
+    #endif
128
+  #endif
129
+
108 130
 }
109 131
 
110 132
 void HAL_idletask() {

+ 7
- 0
Marlin/src/pins/esp32/pins_MRR_ESPA.h Переглянути файл

@@ -101,3 +101,10 @@
101 101
 #define SDSS                5
102 102
 #define USES_SHARED_SPI  // SPI is shared by SD card with TMC SPI drivers
103 103
 
104
+// Hardware serial pins
105
+// Add the following to Configuration.h or Configuration_adv.h to assign
106
+// specific pins to hardware Serial1.
107
+// Note: Serial2 can be defined using HARDWARE_SERIAL2_RX and HARDWARE_SERIAL2_TX but
108
+// MRR ESPA does not have enough spare pins for such reassignment.
109
+//#define HARDWARE_SERIAL1_RX 21
110
+//#define HARDWARE_SERIAL1_TX 22

+ 11
- 1
Marlin/src/pins/esp32/pins_MRR_ESPE.h Переглянути файл

@@ -139,7 +139,7 @@
139 139
     #define BEEPER_PIN      151
140 140
 
141 141
     //#define LCD_PINS_D5     150
142
-    //#define LCD_PINS_D6     151
142
+    //#define LCD_PINS_D6     152
143 143
     //#define LCD_PINS_D7     153
144 144
 
145 145
   #else
@@ -153,3 +153,13 @@
153 153
   #define BTN_ENC            14
154 154
 
155 155
 #endif // HAS_GRAPHICAL_LCD
156
+
157
+// Hardware serial pins
158
+// Add the following to Configuration.h or Configuration_adv.h to assign
159
+// specific pins to hardware Serial1 and Serial2.
160
+// Note: Serial2 can be defined using HARDWARE_SERIAL2_RX and HARDWARE_SERIAL2_TX but
161
+// MRR ESPA does not have enough spare pins for such reassignment.
162
+//#define HARDWARE_SERIAL1_RX 21
163
+//#define HARDWARE_SERIAL1_TX 22
164
+//#define HARDWARE_SERIAL2_RX  2
165
+//#define HARDWARE_SERIAL2_TX  4

Завантаження…
Відмінити
Зберегти