@@ -184,6 +184,8 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
184
184
185
185
bool retCode = true;
186
186
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 );
187
189
// connect RX Pad
188
190
bool ret = ESP_OK == uart_set_pin (uart -> num , UART_PIN_NO_CHANGE , rxPin , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE );
189
191
if (ret ) {
@@ -196,6 +198,8 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
196
198
retCode &= ret ;
197
199
}
198
200
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 );
199
203
// connect TX Pad
200
204
bool ret = ESP_OK == uart_set_pin (uart -> num , txPin , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE );
201
205
if (ret ) {
@@ -208,6 +212,8 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
208
212
retCode &= ret ;
209
213
}
210
214
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 );
211
217
// connect CTS Pad
212
218
bool ret = ESP_OK == uart_set_pin (uart -> num , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE , ctsPin );
213
219
if (ret ) {
@@ -220,6 +226,8 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
220
226
retCode &= ret ;
221
227
}
222
228
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 );
223
231
// connect RTS Pad
224
232
bool ret = ESP_OK == uart_set_pin (uart -> num , UART_PIN_NO_CHANGE , UART_PIN_NO_CHANGE , rtsPin , UART_PIN_NO_CHANGE );
225
233
if (ret ) {
@@ -759,12 +767,14 @@ int log_printfv(const char *format, va_list arg)
759
767
return 0 ;
760
768
}
761
769
}
770
+ /*
771
+ // This causes dead locks with logging in specific cases and also with C++ constructors that may send logs
762
772
#if !CONFIG_DISABLE_HAL_LOCKS
763
773
if(s_uart_debug_nr != -1 && _uart_bus_array[s_uart_debug_nr].lock){
764
774
xSemaphoreTake(_uart_bus_array[s_uart_debug_nr].lock, portMAX_DELAY);
765
775
}
766
776
#endif
767
-
777
+ */
768
778
#if CONFIG_IDF_TARGET_ESP32C3
769
779
vsnprintf (temp , len + 1 , format , arg );
770
780
ets_printf ("%s" , temp );
@@ -774,15 +784,19 @@ int log_printfv(const char *format, va_list arg)
774
784
ets_write_char_uart (temp [i ]);
775
785
}
776
786
#endif
777
-
787
+ /*
788
+ // This causes dead locks with logging and also with constructors that may send logs
778
789
#if !CONFIG_DISABLE_HAL_LOCKS
779
790
if(s_uart_debug_nr != -1 && _uart_bus_array[s_uart_debug_nr].lock){
780
791
xSemaphoreGive(_uart_bus_array[s_uart_debug_nr].lock);
781
792
}
782
793
#endif
794
+ */
783
795
if (len >= sizeof (loc_buf )){
784
796
free (temp );
785
797
}
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 )));
786
800
return len ;
787
801
}
788
802
0 commit comments