Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Feb 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Marlin/src/HAL/HAL_ESP32/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <rom/rtc.h>
#include <driver/adc.h>
#include <esp_adc_cal.h>
#include <HardwareSerial.h>

#include "../../inc/MarlinConfigPre.h"

Expand Down Expand Up @@ -105,6 +106,27 @@ void HAL_init_board() {
#endif
server.begin();
#endif

// ESP32 uses a GPIO matrix that allows pins to be assigned to hardware serial ports.
// The following code initializes hardware Serial1 and Serial2 to use user-defined pins
// if they have been defined.
#if defined(HARDWARE_SERIAL1_RX) && defined(HARDWARE_SERIAL1_TX)
HardwareSerial Serial1(1);
#ifdef TMC_BAUD_RATE // use TMC_BAUD_RATE for Serial1 if defined
Serial1.begin(TMC_BAUD_RATE, SERIAL_8N1, HARDWARE_SERIAL1_RX, HARDWARE_SERIAL1_TX);
#else // use default BAUDRATE if TMC_BAUD_RATE not defined
Serial1.begin(BAUDRATE, SERIAL_8N1, HARDWARE_SERIAL1_RX, HARDWARE_SERIAL1_TX);
#endif
#endif
#if defined(HARDWARE_SERIAL2_RX) && defined(HARDWARE_SERIAL2_TX)
HardwareSerial Serial2(2);
#ifdef TMC_BAUD_RATE // use TMC_BAUD_RATE for Serial1 if defined
Serial2.begin(TMC_BAUD_RATE, SERIAL_8N1, HARDWARE_SERIAL2_RX, HARDWARE_SERIAL2_TX);
#else // use default BAUDRATE if TMC_BAUD_RATE not defined
Serial2.begin(BAUDRATE, SERIAL_8N1, HARDWARE_SERIAL2_RX, HARDWARE_SERIAL2_TX);
#endif
#endif

}

void HAL_idletask() {
Expand Down
7 changes: 7 additions & 0 deletions Marlin/src/pins/esp32/pins_MRR_ESPA.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,10 @@
#define SDSS 5
#define USES_SHARED_SPI // SPI is shared by SD card with TMC SPI drivers

// Hardware serial pins
// Add the following to Configuration.h or Configuration_adv.h to assign
// specific pins to hardware Serial1.
// Note: Serial2 can be defined using HARDWARE_SERIAL2_RX and HARDWARE_SERIAL2_TX but
// MRR ESPA does not have enough spare pins for such reassignment.
//#define HARDWARE_SERIAL1_RX 21
//#define HARDWARE_SERIAL1_TX 22
12 changes: 11 additions & 1 deletion Marlin/src/pins/esp32/pins_MRR_ESPE.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
#define BEEPER_PIN 151

//#define LCD_PINS_D5 150
//#define LCD_PINS_D6 151
//#define LCD_PINS_D6 152
//#define LCD_PINS_D7 153

#else
Expand All @@ -153,3 +153,13 @@
#define BTN_ENC 14

#endif // HAS_GRAPHICAL_LCD

// Hardware serial pins
// Add the following to Configuration.h or Configuration_adv.h to assign
// specific pins to hardware Serial1 and Serial2.
// Note: Serial2 can be defined using HARDWARE_SERIAL2_RX and HARDWARE_SERIAL2_TX but
// MRR ESPA does not have enough spare pins for such reassignment.
//#define HARDWARE_SERIAL1_RX 21
//#define HARDWARE_SERIAL1_TX 22
//#define HARDWARE_SERIAL2_RX 2
//#define HARDWARE_SERIAL2_TX 4