@@ -184,6 +184,8 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
184184
185185 bool retCode = true;
186186 if (rxPin >= 0 ) {
187+ // forces a clean detaching from a previous peripheral
188+ if (perimanGetPinBusType (rxPin ) != ESP32_BUS_TYPE_INIT ) perimanSetPinBus (rxPin , ESP32_BUS_TYPE_INIT , NULL );
187189 // connect RX Pad
188190 bool ret = ESP_OK == uart_set_pin (uart -> num , UART_PIN_NO_CHANGE , rxPin , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE );
189191 if (ret ) {
@@ -196,6 +198,8 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
196198 retCode &= ret ;
197199 }
198200 if (txPin >= 0 ) {
201+ // forces a clean detaching from a previous peripheral
202+ if (perimanGetPinBusType (txPin ) != ESP32_BUS_TYPE_INIT ) perimanSetPinBus (txPin , ESP32_BUS_TYPE_INIT , NULL );
199203 // connect TX Pad
200204 bool ret = ESP_OK == uart_set_pin (uart -> num , txPin , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE );
201205 if (ret ) {
@@ -208,6 +212,8 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
208212 retCode &= ret ;
209213 }
210214 if (ctsPin >= 0 ) {
215+ // forces a clean detaching from a previous peripheral
216+ if (perimanGetPinBusType (ctsPin ) != ESP32_BUS_TYPE_INIT ) perimanSetPinBus (ctsPin , ESP32_BUS_TYPE_INIT , NULL );
211217 // connect CTS Pad
212218 bool ret = ESP_OK == uart_set_pin (uart -> num , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE , ctsPin );
213219 if (ret ) {
@@ -220,6 +226,8 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
220226 retCode &= ret ;
221227 }
222228 if (rtsPin >= 0 ) {
229+ // forces a clean detaching from a previous peripheral
230+ if (perimanGetPinBusType (rtsPin ) != ESP32_BUS_TYPE_INIT ) perimanSetPinBus (rtsPin , ESP32_BUS_TYPE_INIT , NULL );
223231 // connect RTS Pad
224232 bool ret = ESP_OK == uart_set_pin (uart -> num , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE , rtsPin , UART_PIN_NO_CHANGE );
225233 if (ret ) {
@@ -759,12 +767,14 @@ int log_printfv(const char *format, va_list arg)
759767 return 0 ;
760768 }
761769 }
770+ /*
771+ // This causes dead locks with logging in specific cases and also with C++ constructors that may send logs
762772#if !CONFIG_DISABLE_HAL_LOCKS
763773 if(s_uart_debug_nr != -1 && _uart_bus_array[s_uart_debug_nr].lock){
764774 xSemaphoreTake(_uart_bus_array[s_uart_debug_nr].lock, portMAX_DELAY);
765775 }
766776#endif
767-
777+ */
768778#if CONFIG_IDF_TARGET_ESP32C3
769779 vsnprintf (temp , len + 1 , format , arg );
770780 ets_printf ("%s" , temp );
@@ -774,15 +784,19 @@ int log_printfv(const char *format, va_list arg)
774784 ets_write_char_uart (temp [i ]);
775785 }
776786#endif
777-
787+ /*
788+ // This causes dead locks with logging and also with constructors that may send logs
778789#if !CONFIG_DISABLE_HAL_LOCKS
779790 if(s_uart_debug_nr != -1 && _uart_bus_array[s_uart_debug_nr].lock){
780791 xSemaphoreGive(_uart_bus_array[s_uart_debug_nr].lock);
781792 }
782793#endif
794+ */
783795 if (len >= sizeof (loc_buf )){
784796 free (temp );
785797 }
798+ // flushes TX - make sure that the log message is completely sent.
799+ if (s_uart_debug_nr != -1 ) while (!uart_ll_is_tx_idle (UART_LL_GET_HW (s_uart_debug_nr )));
786800 return len ;
787801}
788802
0 commit comments