Skip to content

Commit 5f25e44

Browse files
committed
fix(uart): detaching pin check points
1 parent 6ebe14c commit 5f25e44

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

cores/esp32/chip-debug-report.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ static void printPerimanInfo(void) {
291291

292292
void printBeforeSetupInfo(void) {
293293
#if ARDUINO_USB_CDC_ON_BOOT
294-
Serial.begin(0);
294+
Serial.begin();
295295
Serial.setDebugOutput(true);
296296
uint8_t t = 0;
297297
while (!Serial && (t++ < 200)) {

cores/esp32/esp32-hal-uart.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,15 @@ static bool _uartDetachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
282282
// Peripheral Manager detach callback for each specific UART PIN
283283
static bool _uartDetachBus_RX(void *busptr) {
284284
// sanity check - it should never happen
285-
assert(busptr && "_uartDetachBus_RX bus NULL pointer.");
285+
if (busptr == NULL) {
286+
log_e("_uartDetachBus_RX: busptr is NULL");
287+
return false;
288+
}
286289
uart_t *bus = (uart_t *)busptr;
290+
if (bus->_rxPin < 0) {
291+
log_d("_uartDetachBus_RX: RX pin already detached for UART%d", bus->num);
292+
return true;
293+
}
287294
if (bus->_txPin < 0) { // both rx and tx pins are detached, terminate the uart driver
288295
uartEnd(bus->num);
289296
return true;
@@ -293,8 +300,15 @@ static bool _uartDetachBus_RX(void *busptr) {
293300

294301
static bool _uartDetachBus_TX(void *busptr) {
295302
// sanity check - it should never happen
296-
assert(busptr && "_uartDetachBus_TX bus NULL pointer.");
303+
if (busptr == NULL) {
304+
log_e("_uartDetachBus_TX: busptr is NULL");
305+
return false;
306+
}
297307
uart_t *bus = (uart_t *)busptr;
308+
if (bus->_txPin < 0) {
309+
log_d("_uartDetachBus_TX: TX pin already detached for UART%d", bus->num);
310+
return true;
311+
}
298312
if (bus->_rxPin < 0) { // both rx and tx pins are detached, terminate the uart driver
299313
uartEnd(bus->num);
300314
return true;
@@ -304,15 +318,29 @@ static bool _uartDetachBus_TX(void *busptr) {
304318

305319
static bool _uartDetachBus_CTS(void *busptr) {
306320
// sanity check - it should never happen
307-
assert(busptr && "_uartDetachBus_CTS bus NULL pointer.");
321+
if (busptr == NULL) {
322+
log_e("_uartDetachBus_CTS: busptr is NULL");
323+
return false;
324+
}
308325
uart_t *bus = (uart_t *)busptr;
326+
if (bus->_ctsPin < 0) {
327+
log_d("_uartDetachBus_CTS: CTS pin already detached for UART%d", bus->num);
328+
return true;
329+
}
309330
return _uartDetachPins(bus->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, bus->_ctsPin, UART_PIN_NO_CHANGE);
310331
}
311332

312333
static bool _uartDetachBus_RTS(void *busptr) {
313334
// sanity check - it should never happen
314-
assert(busptr && "_uartDetachBus_RTS bus NULL pointer.");
335+
if (busptr == NULL) {
336+
log_e("_uartDetachBus_RTS: busptr is NULL");
337+
return false;
338+
}
315339
uart_t *bus = (uart_t *)busptr;
340+
if (bus->_rtsPin < 0) {
341+
log_d("_uartDetachBus_RTS: RTS pin already detached for UART%d", bus->num);
342+
return true;
343+
}
316344
return _uartDetachPins(bus->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, bus->_rtsPin);
317345
}
318346

0 commit comments

Comments
 (0)