Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f71a4bd

Browse filesBrowse files
Jeroen88me-no-dev
authored andcommitted
Bugfix/detect baudrate (espressif#3188)
* Expose uartStartDetectBaudrate(uart_t *) in esp32-hal-uart.h and call it from HardwareSerial::begin() if baudrate detection is requested (by passing a baudrate of 0) to solve baudrate detection problems * Avoid a division by zero error in uartGetBaudRate()
1 parent 5f77b01 commit f71a4bd
Copy full SHA for f71a4bd

File tree

Expand file treeCollapse file tree

3 files changed

+15
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+15
-0
lines changed

‎cores/esp32/HardwareSerial.cpp

Copy file name to clipboardExpand all lines: cores/esp32/HardwareSerial.cpp
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
5555
_uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, 256, invert);
5656

5757
if(!baud) {
58+
uartStartDetectBaudrate(_uart);
5859
time_t startMillis = millis();
5960
unsigned long detectedBaudRate = 0;
6061
while(millis() - startMillis < timeout_ms && !(detectedBaudRate = uartDetectBaudrate(_uart))) {

‎cores/esp32/esp32-hal-uart.c

Copy file name to clipboardExpand all lines: cores/esp32/esp32-hal-uart.c
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,12 @@ uint32_t uartGetBaudRate(uart_t* uart)
401401
if(uart == NULL) {
402402
return 0;
403403
}
404+
404405
uint32_t clk_div = (uart->dev->clk_div.div_int << 4) | (uart->dev->clk_div.div_frag & 0x0F);
406+
if(!clk_div) {
407+
return 0;
408+
}
409+
405410
return ((getApbFrequency()<<4)/clk_div);
406411
}
407412

@@ -522,6 +527,14 @@ unsigned long uartBaudrateDetect(uart_t *uart, bool flg)
522527
* detected calling uartBadrateDetect(). The raw baudrate is computed using the UART_CLK_FREQ. The raw baudrate is
523528
* rounded to the closed real baudrate.
524529
*/
530+
void uartStartDetectBaudrate(uart_t *uart) {
531+
if(!uart) return;
532+
533+
uart->dev->auto_baud.glitch_filt = 0x08;
534+
uart->dev->auto_baud.en = 0;
535+
uart->dev->auto_baud.en = 1;
536+
}
537+
525538
unsigned long
526539
uartDetectBaudrate(uart_t *uart)
527540
{

‎cores/esp32/esp32-hal-uart.h

Copy file name to clipboardExpand all lines: cores/esp32/esp32-hal-uart.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ size_t uartResizeRxBuffer(uart_t* uart, size_t new_size);
7272
void uartSetDebug(uart_t* uart);
7373
int uartGetDebug();
7474

75+
void uartStartDetectBaudrate(uart_t *uart);
7576
unsigned long uartDetectBaudrate(uart_t *uart);
7677

7778
bool uartRxActive(uart_t* uart);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.