mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
uart: add uart support on esp32s3
This commit is contained in:
@@ -27,7 +27,7 @@ extern "C" {
|
||||
// The default fifo depth
|
||||
#define UART_LL_FIFO_DEF_LEN (SOC_UART_FIFO_LEN)
|
||||
// Get UART hardware instance with giving uart num
|
||||
#define UART_LL_GET_HW(num) (((num) == 0) ? (&UART0) : (&UART1))
|
||||
#define UART_LL_GET_HW(num) (((num) == 0) ? (&UART0) : (((num) == 1) ? (&UART1) : (&UART2)))
|
||||
|
||||
#define UART_LL_MIN_WAKEUP_THRESH (2)
|
||||
#define UART_LL_INTR_MASK (0x7ffff) //All interrupt mask
|
||||
@@ -56,20 +56,92 @@ typedef enum {
|
||||
} uart_intr_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the UART source clock.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param source_clk The UART source clock. The source clock can be APB clock, RTC clock or XTAL clock.
|
||||
* If the source clock is RTC/XTAL, the UART can still work when the APB changes.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
static inline void uart_ll_set_sclk(uart_dev_t *hw, uart_sclk_t source_clk)
|
||||
{
|
||||
switch (source_clk) {
|
||||
default:
|
||||
case UART_SCLK_APB:
|
||||
hw->clk_conf.sclk_sel = 1;
|
||||
break;
|
||||
case UART_SCLK_RTC:
|
||||
hw->clk_conf.sclk_sel = 2;
|
||||
break;
|
||||
case UART_SCLK_XTAL:
|
||||
hw->clk_conf.sclk_sel = 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the UART source clock type.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param source_clk The pointer to accept the UART source clock type.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
static inline void uart_ll_get_sclk(uart_dev_t *hw, uart_sclk_t *source_clk)
|
||||
{
|
||||
switch (hw->clk_conf.sclk_sel) {
|
||||
default:
|
||||
case 1:
|
||||
*source_clk = UART_SCLK_APB;
|
||||
break;
|
||||
case 2:
|
||||
*source_clk = UART_SCLK_RTC;
|
||||
break;
|
||||
case 3:
|
||||
*source_clk = UART_SCLK_XTAL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the UART source clock frequency.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
*
|
||||
* @return Current source clock frequency
|
||||
*/
|
||||
static inline uint32_t uart_ll_get_sclk_freq(uart_dev_t *hw)
|
||||
{
|
||||
switch (hw->clk_conf.sclk_sel) {
|
||||
default:
|
||||
case 1:
|
||||
return APB_CLK_FREQ;
|
||||
case 2:
|
||||
return RTC_CLK_FREQ;
|
||||
case 3:
|
||||
return XTAL_CLK_FREQ;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the baud-rate.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param source_clk The UART source clock. The source clock can be APB clock, RTC clock or XTAL clock.
|
||||
* If the source clock is RTC/XTAL, the UART can still work when the APB changes.
|
||||
* @param baud The baud rate to be set. When the source clock is APB, the max baud rate is `UART_LL_BITRATE_MAX`
|
||||
* @param source_clk The UART source clock. The source clock can be APB clock or REF_TICK.
|
||||
* If the source clock is REF_TICK, the UART can still work when the APB changes.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
static inline void uart_ll_set_baudrate(uart_dev_t *hw, uart_sclk_t source_clk, uint32_t baud)
|
||||
{
|
||||
uint32_t sclk_freq = (source_clk == UART_SCLK_APB) ? APB_CLK_FREQ : REF_CLK_FREQ;
|
||||
uint32_t clk_div = ((sclk_freq) << 4) / baud;
|
||||
uint32_t sclk_freq, clk_div;
|
||||
|
||||
uart_ll_set_sclk(hw, source_clk);
|
||||
sclk_freq = uart_ll_get_sclk_freq(hw);
|
||||
clk_div = ((sclk_freq) << 4) / baud;
|
||||
// The baud rate configuration register is divided into
|
||||
// an integer part and a fractional part.
|
||||
hw->clk_div.div_int = clk_div >> 4;
|
||||
@@ -85,9 +157,9 @@ static inline void uart_ll_set_baudrate(uart_dev_t *hw, uart_sclk_t source_clk,
|
||||
*/
|
||||
static inline uint32_t uart_ll_get_baudrate(uart_dev_t *hw)
|
||||
{
|
||||
uint32_t src_clk = APB_CLK_FREQ;
|
||||
uint32_t sclk_freq = uart_ll_get_sclk_freq(hw);
|
||||
typeof(hw->clk_div) div_reg = hw->clk_div;
|
||||
return ((src_clk << 4)) / ((div_reg.div_int << 4) | div_reg.div_frag);
|
||||
return ((sclk_freq << 4)) / ((div_reg.div_int << 4) | div_reg.div_frag);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -473,19 +545,6 @@ static inline void uart_ll_set_data_bit_num(uart_dev_t *hw, uart_word_length_t d
|
||||
hw->conf0.bit_num = data_bit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the UART source clock.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param source_clk The pointer to accept the UART source clock configuration.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
static inline void uart_ll_get_sclk(uart_dev_t *hw, uart_sclk_t *source_clk)
|
||||
{
|
||||
*source_clk = UART_SCLK_APB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the rts active level.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user