Merge branch 'contrib/github_pr_12179' into 'master'

Update uart_ll.h - Fixing division by zero (GitHub PR)

Closes IDFGH-10990

See merge request espressif/esp-idf!25907
This commit is contained in:
Song Ruo Jing
2023-09-14 11:30:42 +08:00
7 changed files with 39 additions and 36 deletions

View File

@@ -305,7 +305,9 @@ FORCE_INLINE_ATTR void uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint3
{
#define DIV_UP(a, b) (((a) + (b) - 1) / (b))
const uint32_t max_div = BIT(12) - 1; // UART divider integer part only has 12 bits
int sclk_div = DIV_UP(sclk_freq, max_div * baud);
uint32_t sclk_div = DIV_UP(sclk_freq, (uint64_t)max_div * baud);
if (sclk_div == 0) abort();
uint32_t clk_div = ((sclk_freq) << 4) / (baud * sclk_div);
// The baud rate configuration register is divided into