espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.83k stars 7.32k forks source link

Using I2C_CLK_SRC_DEFAULT as a clk_source and LP_I2C_NUM_0 as i2c_port in i2c_master_bus_config_t crashes when calling i2c_master_bus_add_device() (IDFGH-14098) #14908

Open sampohuttunen-pehutec opened 6 days ago

sampohuttunen-pehutec commented 6 days ago

Answers checklist.

IDF version.

5.3.1

Espressif SoC revision.

ESP32-C6

Operating System used.

Linux

How did you build your project?

VS Code IDE

If you are using Windows, please specify command line type.

None

Development Kit.

ESP32-C6-DevKitC-1

Power Supply used.

USB

What is the expected behavior?

Either just work as a i2c master, or, like with legacy i2c API, gracefully exit with an error message of not supported configuration.

What is the actual behavior?

Crash with core dump on assert failed: lp_i2c_ll_set_source_clk /IDF/components/hal/esp32c6/include/hal/i2c_ll.h:823 (false)

Steps to reproduce.

Initialialize i2c master with the new API (driver/i2c_master.h) and using the following configuration:

i2c_master_bus_config_t master_config = {
    .clk_source = I2C_CLK_SRC_DEFAULT
    .i2c_port = LP_I2C_NUM_0,
    .scl_io_num = I2C_MASTER_SCL_PIN,
    .sda_io_num = I2C_MASTER_SDA_PIN,
    .glitch_ignore_cnt = 7,
    .flags.enable_internal_pullup = true,
};

and call ESP_ERROR_CHECK(i2c_master_bus_add_device(bus_handle, &esp_slave_dev_cfg, &esp_slave_dev_handle));

That is, the intention here is to use the low power i2c port for i2c master, as the I2C_NUM_0 is already occupied for a i2c slave, i.e. there are both master and slave i2c ports in use simultaneously in the same ESP32. If using the legacy i2c API, then trying to use LP_I2C_NUM_0 as the port is handled gracefully with an error description (although with a typo), but using the new i2c API, there's just a crash. But if the clock source is also set to SOC_MOD_CLK_XTAL_D2, then the communication can be succesfully initialized.

Debug Logs.

No response

More Information.

No response