espressif / esp-idf

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

I2C timeout is ignored on IDF 4.4 (IDFGH-7110) #8718

Open readmodifywrite opened 2 years ago

readmodifywrite commented 2 years ago

IDF 4.4 ESP32

Using the i2c_master_cmd_begin() API:

i2c_master_cmd_begin( I2C_MASTER_PORT, handle, 50 / portTICK_RATE_MS );

This should set the timeout to 50 ms, and it does so on the IDF 3.3.x. On 4.4, it is ignoring the argument and using a 1000 ms timeout, which is resulting in a task watchdog reset.

readmodifywrite commented 2 years ago

I tried this as a workaround in my init code:

i2c_set_timeout( I2C_MASTER_PORT, 4000000 );

This results in an error on the trace log: E (9208) i2c: i2c_set_timeout(817): i2c timing value error

Followed by the watchdog reset.

readmodifywrite commented 2 years ago

i2c_set_timeout( I2C_MASTER_PORT, 50 )

This seems to actually work. However, the timeout setting is documented as APB bus cycles. This appears to actually result in something like 20 ms. I do not see the correlation of the number 50 to either 20 ms or to APB bus cycles.

readmodifywrite commented 2 years ago

Actually, that appears to time out more or less instantly, which kills all I2C comms.

What happened here? The I2C driver was fine the way it was.

AxelLin commented 1 year ago

@readmodifywrite Do you still hit issue with recent v4.4.4 release?

readmodifywrite commented 1 year ago

Sorry, I have no idea. I only very rarely update the IDF because lots of small things (just like this issue) break every time I do so. The amount of API churn and regressions (in really basic things, like I2C) is simply too much to keep up with.

AxelLin commented 1 year ago

I don't get it. You cannot get bug fix if you don't update your esp-idf. Should be no api change between v4.4 and v4.4.4.

readmodifywrite commented 1 year ago

I've already worked around the issue and I don't want to deal with whatever new stuff comes up. I won't get just a bug fix for the I2C, it's always 1000 other things.

Sorry, but I'm a busy engineer and I don't have time to debug this 13 month old issue plus all the other things I have to do every day. Every time I update the IDF it's a multi-day slog through multiple issues that were completely fine before. I can only update if I have an extremely compelling reason to. This is the practical reality of the profession.

yuhongshuai commented 8 months ago

I hit the same problem. find bug in idf i2c.c

    TickType_t wait_time = xTaskGetTickCount();
    if (wait_time - ticks_start > ticks_to_wait) { // out of time
        wait_time = I2C_CMD_ALIVE_INTERVAL_TICK;
    } else {
        wait_time = ticks_to_wait - (wait_time - ticks_start);
        if (wait_time < I2C_CMD_ALIVE_INTERVAL_TICK) {
            wait_time = I2C_CMD_ALIVE_INTERVAL_TICK;
        }
    }