Skip to content

Commit 7b25c02

Browse files
committed
UART: fix high baudrate selection
Following the conversation with @mukyokyo on arduino#25 Tested at 500000, 921600, 1M, 2M on UNO R4 WiFi
1 parent eafa364 commit 7b25c02

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cores/arduino/Serial.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,12 @@ void UART::begin(unsigned long baudrate, uint16_t config) {
272272

273273
fsp_err_t err;
274274
const bool bit_mod = true;
275-
const uint32_t err_rate = 5;
275+
const uint32_t err_rate = 3000; //means 3%
276276

277277
err = R_SCI_UART_BaudCalculate(baudrate, bit_mod, err_rate, &uart_baud);
278+
if (uart_baud.mddr == 0) {
279+
err = R_SCI_UART_BaudCalculate(baudrate, false, err_rate, &uart_baud);
280+
}
278281
err = R_SCI_UART_Open (&uart_ctrl, &uart_cfg);
279282
if(err != FSP_SUCCESS) while(1);
280283
err = R_SCI_UART_BaudSet(&uart_ctrl, (void *) &uart_baud);

0 commit comments

Comments
 (0)