Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 80418fa

Browse files
Fixes UART detach. Fixes espressif#3878 (espressif#3894)
* Fixes UART detach. Fixes espressif#3878 * 0 is not a good holder value for pins! * 0 is not a good holder value for pins!
1 parent 8b6d020 commit 80418fa

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

‎cores/esp32/HardwareSerial.cpp‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
5353
}
5454

5555
_uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, 256, invert);
56+
_tx_pin = txPin;
57+
_rx_pin = rxPin;
5658

5759
if(!baud) {
5860
uartStartDetectBaudrate(_uart);
@@ -70,6 +72,8 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
7072
} else {
7173
log_e("Could not detect baudrate. Serial data at the port must be present within the timeout for detection to be possible");
7274
_uart = NULL;
75+
_tx_pin = 255;
76+
_rx_pin = 255;
7377
}
7478
}
7579
}
@@ -84,7 +88,8 @@ void HardwareSerial::end()
8488
if(uartGetDebug() == _uart_nr) {
8589
uartSetDebug(0);
8690
}
87-
uartEnd(_uart);
91+
log_v("pins %d %d",_tx_pin, _rx_pin);
92+
uartEnd(_uart, _tx_pin, _rx_pin);
8893
_uart = 0;
8994
}
9095

‎cores/esp32/HardwareSerial.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class HardwareSerial: public Stream
104104
protected:
105105
int _uart_nr;
106106
uart_t* _uart;
107+
uint8_t _tx_pin;
108+
uint8_t _rx_pin;
107109
};
108110

109111
extern void serialEventRun(void) __attribute__((weak));

‎cores/esp32/esp32-hal-uart.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,21 @@ void uartDisableInterrupt(uart_t* uart)
124124
UART_MUTEX_UNLOCK();
125125
}
126126

127-
void uartDetachRx(uart_t* uart)
127+
void uartDetachRx(uart_t* uart, uint8_trxPin)
128128
{
129129
if(uart == NULL) {
130130
return;
131131
}
132-
pinMatrixInDetach(UART_RXD_IDX(uart->num), false, false);
132+
pinMatrixInDetach(rxPin, false, false);
133133
uartDisableInterrupt(uart);
134134
}
135135

136-
void uartDetachTx(uart_t* uart)
136+
void uartDetachTx(uart_t* uart, uint8_ttxPin)
137137
{
138138
if(uart == NULL) {
139139
return;
140140
}
141-
pinMatrixOutDetach(UART_TXD_IDX(uart->num), false, false);
141+
pinMatrixOutDetach(txPin, false, false);
142142
}
143143

144144
void uartAttachRx(uart_t* uart, uint8_t rxPin, bool inverted)
@@ -226,7 +226,7 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
226226
return uart;
227227
}
228228

229-
void uartEnd(uart_t* uart)
229+
void uartEnd(uart_t* uart, uint8_ttxPin, uint8_trxPin)
230230
{
231231
if(uart == NULL) {
232232
return;
@@ -243,8 +243,8 @@ void uartEnd(uart_t* uart)
243243

244244
UART_MUTEX_UNLOCK();
245245

246-
uartDetachRx(uart);
247-
uartDetachTx(uart);
246+
uartDetachRx(uart, rxPin);
247+
uartDetachTx(uart, txPin);
248248
}
249249

250250
size_t uartResizeRxBuffer(uart_t * uart, size_t new_size) {

‎cores/esp32/esp32-hal-uart.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct uart_struct_t;
5252
typedef struct uart_struct_t uart_t;
5353

5454
uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t queueLen, bool inverted);
55-
void uartEnd(uart_t* uart);
55+
void uartEnd(uart_t* uart, uint8_trxPin, uint8_ttxPin);
5656

5757
uint32_t uartAvailable(uart_t* uart);
5858
uint32_t uartAvailableForWrite(uart_t* uart);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /