Skip to content

Commit 31f7bb3

Browse files
committed
Clarification of pin definitions
Clarification of pin definitions and addition of ESP32 pins that should have been out of scope
1 parent b3eeb0b commit 31f7bb3

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ongoing, there will be some inexactness in interrupt timings. This may
2727
lead to inevitable, but few, bit errors when having heavy data traffic
2828
at high baud rates.
2929

30-
This library supports ESP8266, ESP32, ESP32-S2 and ESP32-C3 devices
30+
This library supports ESP8266, ESP32, ESP32-S2 and ESP32-C3 devices.
3131

3232
## Resource optimization
3333

@@ -127,10 +127,13 @@ SoftwareSerial myPort;
127127
128128
Serial.begin(115200); // Standard hardware serial port
129129
130-
myPort.begin(38400, SWSERIAL_8N1, MYPORT_RX, MYPORT_TX, false, 256, 256);
131-
if (!myPort) {
132-
Serial.println("Invalid pin configuration, check config");
133-
while (1) ;
130+
myPort.begin(38400, SWSERIAL_8N1, MYPORT_RX, MYPORT_TX, false);
131+
if (!myPort) { // If the object did not initilaise, then its configuration is invalid
132+
Serial.println("Invalid SoftwareSerial pin configuration, check config");
133+
while (1) { // Can't continue with invalid configuration
134+
yield();
135+
delay (1000);
136+
}
134137
}
135138
136139
....

src/SoftwareSerial.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ SoftwareSerial::~SoftwareSerial() {
4949
bool SoftwareSerial::isValidGPIOpin(int8_t pin) {
5050
#if defined(ESP8266)
5151
return (pin >= 0 && pin <= 16) && !isFlashInterfacePin(pin);
52-
#elif defined(ESP32)
5352

53+
#elif defined(ESP32)
54+
// Remove the strapping pins as defined in the datasheets, they affect bootup and other critical operations
55+
// Remmove the flash memory pins on related devices, since using these causes memory access issues.
5456
#ifdef CONFIG_IDF_TARGET_ESP32
5557
// Datasheet https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf,
56-
// Pinout https://docs.espressif.com/projects/esp-idf/en/latest/esp32/_images/esp32-devkitC-v4-pinout.jpg
57-
return (pin >= 0 && pin <= 5) || (pin >= 12 && pin <= 19) ||
58-
(pin >= 21 && pin <= 23) || (pin >= 25 && pin <= 27) || (pin >= 32 && pin <= 39);
58+
// Pinout https://docs.espressif.com/projects/esp-idf/en/latest/esp32/_images/esp32-devkitC-v4-pinout.jpg
59+
return (pin >= 1 && pin <= 1) || (pin >= 3 && pin <= 4) || (pin >= 13 && pin <= 14) ||
60+
(pin >= 16 && pin <= 19) || (pin >= 21 && pin <= 23) || (pin >= 25 && pin <= 27) ||
61+
(pin >= 32 && pin <= 39);
5962

6063
#elif CONFIG_IDF_TARGET_ESP32S2
6164
// Datasheet https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf,
@@ -88,10 +91,10 @@ bool SoftwareSerial::isValidTxGPIOpin(int8_t pin) {
8891
return isValidGPIOpin(pin)
8992
#if defined(ESP32)
9093
#ifdef CONFIG_IDF_TARGET_ESP32
91-
&& (pin < 34)
94+
&& (pin < 34) // GPIO34 and above are input only, so cannot transmit
9295

9396
#elif CONFIG_IDF_TARGET_ESP32S2
94-
&& (pin < 45)
97+
&& (pin < 46) // GPIO46 is an input only, so cannot transmit
9598

9699
#elif CONFIG_IDF_TARGET_ESP32C3
97100
// Nothing to do

0 commit comments

Comments
 (0)