uart baudrate and source clock
Posted: Tue Jun 20, 2023 7:37 am
Hello! I have problem with usins uart with standart baudratedifferent than 115200.
When I use default 115200 and than check by uart_get_baudrate(UART_NUM_0, &brd);, brd = 115201 (small difference),
but with 921600 -> uart_get_baudrate(UART_NUM_0, &brd);, brd = 922190 (huge difference).
I undarstand, it's because UART_CLK_FREQ = 80 MHz, but where I can to change it to use with standart uart baudrates?
Is there any API for this or I need change library file soc.h?
Sdk config: CPU freq = 240MHz
soc.h file:[Codebox]
//Periheral Clock {{
#define APB_CLK_FREQ_ROM ( 40*1000000 )
#define CPU_CLK_FREQ_ROM APB_CLK_FREQ_ROM
#define UART_CLK_FREQ_ROM ( 40*1000000)
#define EFUSE_CLK_FREQ_ROM ( 20*1000000)
#define CPU_CLK_FREQ APB_CLK_FREQ
#if CONFIG_IDF_ENV_FPGA
#define APB_CLK_FREQ ( 40*1000000 )
#else
#define APB_CLK_FREQ ( 80*1000000 )
#endif
#define REF_CLK_FREQ ( 1000000 )
#define RTC_CLK_FREQ (20*1000000)
#define XTAL_CLK_FREQ (40*1000000)
#define UART_CLK_FREQ APB_CLK_FREQ
#define WDT_CLK_FREQ APB_CLK_FREQ
#define TIMER_CLK_FREQ (80000000>>4) //80MHz divided by 16
#define SPI_CLK_DIV 4
#define TICKS_PER_US_ROM 40 // CPU is 80MHz
#define GPIO_MATRIX_DELAY_NS 0
//}}
[/Codebox]
When I use default 115200 and than check by uart_get_baudrate(UART_NUM_0, &brd);, brd = 115201 (small difference),
but with 921600 -> uart_get_baudrate(UART_NUM_0, &brd);, brd = 922190 (huge difference).
I undarstand, it's because UART_CLK_FREQ = 80 MHz, but where I can to change it to use with standart uart baudrates?
Is there any API for this or I need change library file soc.h?
Sdk config: CPU freq = 240MHz
soc.h file:[Codebox]
//Periheral Clock {{
#define APB_CLK_FREQ_ROM ( 40*1000000 )
#define CPU_CLK_FREQ_ROM APB_CLK_FREQ_ROM
#define UART_CLK_FREQ_ROM ( 40*1000000)
#define EFUSE_CLK_FREQ_ROM ( 20*1000000)
#define CPU_CLK_FREQ APB_CLK_FREQ
#if CONFIG_IDF_ENV_FPGA
#define APB_CLK_FREQ ( 40*1000000 )
#else
#define APB_CLK_FREQ ( 80*1000000 )
#endif
#define REF_CLK_FREQ ( 1000000 )
#define RTC_CLK_FREQ (20*1000000)
#define XTAL_CLK_FREQ (40*1000000)
#define UART_CLK_FREQ APB_CLK_FREQ
#define WDT_CLK_FREQ APB_CLK_FREQ
#define TIMER_CLK_FREQ (80000000>>4) //80MHz divided by 16
#define SPI_CLK_DIV 4
#define TICKS_PER_US_ROM 40 // CPU is 80MHz
#define GPIO_MATRIX_DELAY_NS 0
//}}
[/Codebox]