@@ -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
283283static 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
294301static 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
305319static 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
312333static 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