Skip to content

Commit 2ee8c06

Browse files
committed
Merge branch 'feature/uart_autoband_detect' into 'master'
feat(uart): add uart_detect_bitrate_bps API for data line bitrate measurement Closes IDFGH-13876, IDF-12195, and IDFGH-14709 See merge request espressif/esp-idf!36620
2 parents f958eb7 + b38ac5a commit 2ee8c06

File tree

39 files changed

+506
-410
lines changed

39 files changed

+506
-410
lines changed

components/esp_driver_i2c/test_apps/i2c_test_apps/main/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ if(NOT CONFIG_I2C_MASTER_ISR_HANDLER_IN_IRAM)
3939
endif()
4040

4141
idf_component_register(SRCS ${srcs}
42-
PRIV_REQUIRES unity driver test_utils
42+
PRIV_REQUIRES esp_driver_i2c unity esp_driver_uart test_utils esp_pm esp_driver_gptimer
4343
WHOLE_ARCHIVE)

components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_10bit.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@
1212
#include "freertos/task.h"
1313
#include "freertos/queue.h"
1414
#include "esp_err.h"
15-
#include "soc/gpio_periph.h"
1615
#include "soc/clk_tree_defs.h"
1716
#include "soc/soc_caps.h"
18-
#include "hal/gpio_hal.h"
1917
#include "hal/uart_ll.h"
2018
#include "esp_private/periph_ctrl.h"
21-
#include "driver/gpio.h"
2219
#include "driver/i2c_master.h"
2320
#include "driver/i2c_slave.h"
24-
#include "esp_rom_gpio.h"
2521
#include "esp_log.h"
2622
#include "test_utils.h"
2723
#include "test_board.h"

components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_broadcast.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@
1212
#include "freertos/task.h"
1313
#include "freertos/queue.h"
1414
#include "esp_err.h"
15-
#include "soc/gpio_periph.h"
1615
#include "soc/clk_tree_defs.h"
1716
#include "soc/soc_caps.h"
18-
#include "hal/gpio_hal.h"
1917
#include "hal/uart_ll.h"
2018
#include "esp_private/periph_ctrl.h"
21-
#include "driver/gpio.h"
2219
#include "driver/i2c_master.h"
2320
#include "driver/i2c_slave.h"
24-
#include "esp_rom_gpio.h"
2521
#include "esp_log.h"
2622
#include "test_utils.h"
2723
#include "test_board.h"

components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_common.c

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -11,18 +11,15 @@
1111
#include "freertos/FreeRTOS.h"
1212
#include "freertos/task.h"
1313
#include "esp_err.h"
14-
#include "soc/gpio_periph.h"
1514
#include "soc/clk_tree_defs.h"
1615
#include "soc/soc_caps.h"
17-
#include "hal/gpio_hal.h"
1816
#include "hal/uart_ll.h"
1917
#include "esp_private/periph_ctrl.h"
20-
#include "driver/gpio.h"
2118
#include "driver/i2c_master.h"
22-
#include "esp_rom_gpio.h"
2319
#include "esp_log.h"
2420
#include "test_utils.h"
2521
#include "test_board.h"
22+
#include "driver/uart.h"
2623

2724
static const char TAG[] = "test-i2c";
2825

@@ -182,6 +179,52 @@ TEST_CASE("I2C peripheral allocate all", "[i2c]")
182179
TEST_ESP_OK(i2c_del_master_bus(bus_handle_2));
183180
}
184181

182+
TEST_CASE("I2C master clock frequency test", "[i2c]")
183+
{
184+
uint8_t data_wr[500] = { 0 };
185+
186+
i2c_master_bus_config_t i2c_mst_config = {
187+
.clk_source = I2C_CLK_SRC_DEFAULT,
188+
.i2c_port = TEST_I2C_PORT,
189+
.scl_io_num = I2C_MASTER_SCL_IO,
190+
.sda_io_num = I2C_MASTER_SDA_IO,
191+
.flags.enable_internal_pullup = true,
192+
.trans_queue_depth = 30,
193+
};
194+
i2c_master_bus_handle_t bus_handle;
195+
196+
TEST_ESP_OK(i2c_new_master_bus(&i2c_mst_config, &bus_handle));
197+
198+
i2c_device_config_t dev_cfg = {
199+
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
200+
.device_address = 0x58,
201+
.scl_speed_hz = 100000,
202+
.flags.disable_ack_check = 1,
203+
};
204+
205+
i2c_master_dev_handle_t dev_handle;
206+
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
207+
208+
TEST_ESP_OK(i2c_master_transmit(dev_handle, data_wr, 500, 0));
209+
210+
uart_bitrate_detect_config_t conf = {
211+
.rx_io_num = I2C_MASTER_SCL_IO,
212+
.source_clk = UART_SCLK_DEFAULT,
213+
};
214+
uart_bitrate_res_t res = {};
215+
uart_detect_bitrate_start(UART_NUM_1, &conf);
216+
vTaskDelay(pdMS_TO_TICKS(50));
217+
uart_detect_bitrate_stop(UART_NUM_1, true, &res);
218+
219+
int freq_hz = res.clk_freq_hz / res.pos_period;
220+
printf("The tested I2C SCL frequency is %d\n", freq_hz);
221+
TEST_ASSERT_INT_WITHIN(500, 100000, freq_hz);
222+
223+
TEST_ESP_OK(i2c_master_bus_rm_device(dev_handle));
224+
225+
TEST_ESP_OK(i2c_del_master_bus(bus_handle));
226+
}
227+
185228
TEST_CASE("I2C master probe device test", "[i2c]")
186229
{
187230
// 0x22,33,44,55 does not exist on the I2C bus, so it's expected to return `not found` error

components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_iram.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@
1212
#include "freertos/task.h"
1313
#include "freertos/queue.h"
1414
#include "esp_err.h"
15-
#include "soc/gpio_periph.h"
1615
#include "soc/clk_tree_defs.h"
1716
#include "soc/soc_caps.h"
18-
#include "hal/gpio_hal.h"
1917
#include "hal/uart_ll.h"
2018
#include "esp_private/periph_ctrl.h"
21-
#include "driver/gpio.h"
2219
#include "driver/i2c_master.h"
2320
#include "driver/i2c_slave.h"
24-
#include "esp_rom_gpio.h"
2521
#include "esp_log.h"
2622
#include "test_utils.h"
2723
#include "test_board.h"

components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_multi.c

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -12,26 +12,14 @@
1212
#include "freertos/task.h"
1313
#include "freertos/queue.h"
1414
#include "esp_err.h"
15-
#include "soc/gpio_periph.h"
1615
#include "soc/clk_tree_defs.h"
1716
#include "soc/soc_caps.h"
18-
#include "hal/gpio_hal.h"
19-
#include "hal/uart_ll.h"
2017
#include "esp_private/periph_ctrl.h"
21-
#include "driver/gpio.h"
2218
#include "driver/i2c_master.h"
2319
#include "driver/i2c_slave.h"
24-
#include "esp_rom_gpio.h"
2520
#include "esp_log.h"
2621
#include "test_utils.h"
2722
#include "test_board.h"
28-
// For clock checking
29-
#include "hal/uart_hal.h"
30-
#include "soc/uart_periph.h"
31-
#include "hal/clk_tree_hal.h"
32-
#include "esp_private/gpio.h"
33-
#include "hal/uart_ll.h"
34-
#include "esp_clk_tree.h"
3523

3624
void disp_buf(uint8_t *buf, int len)
3725
{
@@ -810,92 +798,3 @@ static void i2c_slave_read_test_more_port(void)
810798

811799
TEST_CASE_MULTIPLE_DEVICES("I2C master write slave test, more ports", "[i2c][test_env=generic_multi_device][timeout=150]", i2c_master_write_test_more_port, i2c_slave_read_test_more_port);
812800
#endif
813-
814-
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
815-
// For now, we tested the chip which has such problem.
816-
// This test can be extended to all chip when how uart baud rate
817-
// works has been figured out.
818-
819-
#if SOC_RCC_IS_INDEPENDENT
820-
#define HP_UART_BUS_CLK_ATOMIC()
821-
#else
822-
#define HP_UART_BUS_CLK_ATOMIC() PERIPH_RCC_ATOMIC()
823-
#endif
824-
825-
//Init uart baud rate detection
826-
static void uart_aut_baud_det_init(int rxd_io_num)
827-
{
828-
gpio_func_sel(rxd_io_num, PIN_FUNC_GPIO);
829-
gpio_set_direction(rxd_io_num, GPIO_MODE_INPUT);
830-
gpio_pullup_en(rxd_io_num);
831-
esp_rom_gpio_connect_in_signal(rxd_io_num, UART_PERIPH_SIGNAL(1, SOC_UART_RX_PIN_IDX), 0);
832-
HP_UART_BUS_CLK_ATOMIC() {
833-
uart_ll_enable_bus_clock(1, true);
834-
uart_ll_reset_register(1);
835-
}
836-
/* Reset all the bits */
837-
uart_ll_disable_intr_mask(&UART1, ~0);
838-
uart_ll_clr_intsts_mask(&UART1, ~0);
839-
uart_ll_set_autobaud_en(&UART1, true);
840-
}
841-
842-
static void i2c_master_write_fsm_reset(void)
843-
{
844-
uint8_t data_wr[3] = { 0 };
845-
846-
i2c_master_bus_config_t i2c_mst_config = {
847-
.clk_source = I2C_CLK_SRC_DEFAULT,
848-
.i2c_port = TEST_I2C_PORT,
849-
.scl_io_num = I2C_MASTER_SCL_IO,
850-
.sda_io_num = I2C_MASTER_SDA_IO,
851-
.flags.enable_internal_pullup = true,
852-
};
853-
i2c_master_bus_handle_t bus_handle;
854-
855-
TEST_ESP_OK(i2c_new_master_bus(&i2c_mst_config, &bus_handle));
856-
857-
i2c_device_config_t dev_cfg = {
858-
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
859-
.device_address = 0x58,
860-
.scl_speed_hz = 10000, // Not a typical value for I2C
861-
};
862-
863-
i2c_master_dev_handle_t dev_handle;
864-
TEST_ESP_OK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
865-
866-
// Nack will reset the bus
867-
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, i2c_master_transmit(dev_handle, data_wr, 3, -1));
868-
869-
unity_send_signal("i2c transmit fail--connect uart");
870-
unity_wait_for_signal("uart connected");
871-
872-
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, i2c_master_transmit(dev_handle, data_wr, 3, -1));
873-
874-
unity_send_signal("i2c transmit after fsm reset");
875-
TEST_ESP_OK(i2c_master_bus_rm_device(dev_handle));
876-
877-
TEST_ESP_OK(i2c_del_master_bus(bus_handle));
878-
}
879-
880-
static void uart_test_i2c_master_freq(void)
881-
{
882-
unity_wait_for_signal("i2c transmit fail--connect uart");
883-
uart_aut_baud_det_init(I2C_MASTER_SCL_IO);
884-
885-
unity_send_signal("uart connected");
886-
unity_wait_for_signal("i2c transmit after fsm reset");
887-
int pospulse_cnt = uart_ll_get_pos_pulse_cnt(&UART1);
888-
int negpulse_cnt = uart_ll_get_neg_pulse_cnt(&UART1);
889-
// Uart uses XTAL as default clock source
890-
int freq_hz = (clk_hal_xtal_get_freq_mhz() * 1 * 1000 * 1000) / (pospulse_cnt + negpulse_cnt);
891-
printf("The tested I2C SCL frequency is %d\n", freq_hz);
892-
TEST_ASSERT_INT_WITHIN(500, 10000, freq_hz);
893-
uart_ll_set_autobaud_en(&UART1, false);
894-
HP_UART_BUS_CLK_ATOMIC() {
895-
uart_ll_enable_bus_clock(1, false);
896-
}
897-
}
898-
899-
TEST_CASE_MULTIPLE_DEVICES("I2C master clock frequency test", "[i2c][test_env=generic_multi_device][timeout=150]", uart_test_i2c_master_freq, i2c_master_write_fsm_reset);
900-
901-
#endif // CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3

components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_ram.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@
1212
#include "freertos/task.h"
1313
#include "freertos/queue.h"
1414
#include "esp_err.h"
15-
#include "soc/gpio_periph.h"
1615
#include "soc/clk_tree_defs.h"
1716
#include "soc/soc_caps.h"
18-
#include "hal/gpio_hal.h"
1917
#include "hal/uart_ll.h"
2018
#include "esp_private/periph_ctrl.h"
21-
#include "driver/gpio.h"
2219
#include "driver/i2c_master.h"
2320
#include "driver/i2c_slave.h"
24-
#include "esp_rom_gpio.h"
2521
#include "esp_log.h"
2622
#include "test_utils.h"
2723
#include "test_board.h"

components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_lp_i2c.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@
1212
#include "freertos/task.h"
1313
#include "freertos/queue.h"
1414
#include "esp_err.h"
15-
#include "soc/gpio_periph.h"
1615
#include "soc/clk_tree_defs.h"
1716
#include "soc/soc_caps.h"
18-
#include "hal/gpio_hal.h"
1917
#include "hal/uart_ll.h"
2018
#include "esp_private/periph_ctrl.h"
21-
#include "driver/gpio.h"
2219
#include "driver/i2c_master.h"
2320
#include "driver/i2c_slave.h"
24-
#include "esp_rom_gpio.h"
2521
#include "esp_log.h"
2622
#include "test_utils.h"
2723
#include "test_board.h"

components/esp_driver_ledc/test_apps/ledc/main/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ endif()
1010
# the component can be registered as WHOLE_ARCHIVE
1111
idf_component_register(
1212
SRCS ${srcs}
13-
PRIV_REQUIRES unity esp_driver_pcnt esp_driver_ledc esp_driver_gpio esp_timer esp_psram
13+
PRIV_REQUIRES unity esp_driver_ledc esp_driver_gpio esp_timer esp_psram esp_driver_uart
1414
WHOLE_ARCHIVE
1515
)

0 commit comments

Comments
 (0)