@@ -615,7 +615,8 @@ void log_print_buf(const uint8_t *b, size_t len){
615
615
*/
616
616
unsigned long uartBaudrateDetect (uart_t * uart , bool flg )
617
617
{
618
- #ifndef CONFIG_IDF_TARGET_ESP32S3
618
+ // Baud rate detection only works for ESP32 and ESP32S2
619
+ #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
619
620
if (uart == NULL ) {
620
621
return 0 ;
621
622
}
@@ -679,6 +680,8 @@ void uartStartDetectBaudrate(uart_t *uart) {
679
680
//hw->conf0.autobaud_en = 0;
680
681
//hw->conf0.autobaud_en = 1;
681
682
#elif CONFIG_IDF_TARGET_ESP32S3
683
+ log_e ("ESP32-S3 baud rate detection is not supported." );
684
+ return ;
682
685
#else
683
686
uart_dev_t * hw = UART_LL_GET_HW (uart -> num );
684
687
hw -> auto_baud .glitch_filt = 0x08 ;
@@ -694,7 +697,8 @@ uartDetectBaudrate(uart_t *uart)
694
697
return 0 ;
695
698
}
696
699
697
- #ifndef CONFIG_IDF_TARGET_ESP32C3 // ESP32-C3 requires further testing - Baud rate detection returns wrong values
700
+ // Baud rate detection only works for ESP32 and ESP32S2
701
+ #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
698
702
699
703
static bool uartStateDetectingBaudrate = false;
700
704
@@ -707,22 +711,14 @@ uartDetectBaudrate(uart_t *uart)
707
711
if (!divisor ) {
708
712
return 0 ;
709
713
}
710
- // log_i(...) below has been used to check C3 baud rate detection results
711
- //log_i("Divisor = %d\n", divisor);
712
- //log_i("BAUD RATE based on Positive Pulse %d\n", getApbFrequency()/((hw->pospulse.min_cnt + 1)/2));
713
- //log_i("BAUD RATE based on Negative Pulse %d\n", getApbFrequency()/((hw->negpulse.min_cnt + 1)/2));
714
-
715
714
716
- #ifdef CONFIG_IDF_TARGET_ESP32C3
717
- //hw->conf0.autobaud_en = 0;
718
- #elif CONFIG_IDF_TARGET_ESP32S3
719
- #else
720
715
uart_dev_t * hw = UART_LL_GET_HW (uart -> num );
721
716
hw -> auto_baud .en = 0 ;
722
- #endif
717
+
723
718
uartStateDetectingBaudrate = false; // Initialize for the next round
724
719
725
720
unsigned long baudrate = getApbFrequency () / divisor ;
721
+
726
722
//log_i("APB_FREQ = %d\nraw baudrate detected = %d", getApbFrequency(), baudrate);
727
723
728
724
static const unsigned long default_rates [] = {300 , 600 , 1200 , 2400 , 4800 , 9600 , 19200 , 38400 , 57600 , 74880 , 115200 , 230400 , 256000 , 460800 , 921600 , 1843200 , 3686400 };
@@ -741,7 +737,11 @@ uartDetectBaudrate(uart_t *uart)
741
737
742
738
return default_rates [i ];
743
739
#else
740
+ #ifdef CONFIG_IDF_TARGET_ESP32C3
744
741
log_e ("ESP32-C3 baud rate detection is not supported." );
742
+ #else
743
+ log_e ("ESP32-S3 baud rate detection is not supported." );
744
+ #endif
745
745
return 0 ;
746
746
#endif
747
747
}
@@ -795,4 +795,4 @@ int uart_send_msg_with_break(uint8_t uartNum, uint8_t *msg, size_t msgSize)
795
795
{
796
796
// 12 bits long BREAK for 8N1
797
797
return uart_write_bytes_with_break (uartNum , (const void * )msg , msgSize , 12 );
798
- }
798
+ }
0 commit comments