I2C runs out of memory

lukilukeskywalker
Posts: 21
Joined: Wed Feb 22, 2023 4:25 pm

I2C runs out of memory

Postby lukilukeskywalker » Wed Feb 22, 2023 4:57 pm

Hi!!! This is my first post in the comunity, so I am hopping I am not breaking any rules or writing in the right forum,

So, I have been developing a application that utilizes a I2C driver chip, the KTD2061, for some Led animations. I just finished developing the library of the chip, and It utilizes the i2cdev component https://esp-idf-lib.readthedocs.io/en/l ... 2cdev.html for comunication with the chip, as I wanted to create a flexible not hardware fix library. From this component, my library only uses the

Code: Select all

i2c_dev_read_reg
and

Code: Select all

i2c_dev_write_reg
functions.
The configuration of the i2c driver, the i2cdev and my library is included:

Code: Select all

int master_port = CONFIG_I2C_MASTER_PORT_NUM;
   i2c_config_t i2c_driver_config = {
        .mode = I2C_MODE_MASTER,
        .sda_io_num = CONFIG_I2C_MASTER_SDA_IO,
        .sda_pullup_en = GPIO_PULLUP_ENABLE,
        .scl_io_num = CONFIG_I2C_MASTER_SCL_IO,
        .scl_pullup_en = GPIO_PULLUP_ENABLE,
        .master.clk_speed = CONFIG_I2C_MASTER_FREQ_HZ,
        .clk_flags = 0,   //clk_flags is for APB clock configurator to find the best suitable clock source, for example in case
                        //we want to mantain I2C funtionality while being in light sleep. 0 does not pose any restrictions.
    };
    i2c_dev_t dev = {
        .port = master_port,
        .cfg = i2c_driver_config,
        .addr = KTD2061_I2C_BASE_MODULE_ADDRESS,
        .timeout_ticks = 0,
    };
    ktd2061_t ktd = {
        .read = i2c_dev_read_reg,
        .write = i2c_dev_write_reg,
        .handle = &dev,
    };
Everything works almost flawlesly, except on that for some reason after 16 min the following error is spited out from the serial console:

Code: Select all

D (1038934) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
D (1038934) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
D (1038934) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
D (1039044) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
D (1039044) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
D (1039044) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1039044) i2c: i2c command link malloc error
D (1039054) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1040054) i2cdev: Could not write to device [0x68 at 1]: 263 (ESP_ERR_TIMEOUT)
D (1040154) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1040154) i2c: i2c command link malloc error
D (1040154) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1041154) i2cdev: Could not write to device [0x68 at 1]: 263 (ESP_ERR_TIMEOUT)
D (1041154) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1041154) i2c: i2c command link malloc error
E (1041154) i2c: i2c command link malloc error
D (1041164) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
D (1041264) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1041264) i2c: i2c command link malloc error
E (1041264) i2c: i2c command link malloc error
D (1041264) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
D (1041274) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1041274) i2c: i2c command link malloc error
E (1041284) i2c: i2c command link malloc error
D (1041284) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
D (1041394) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1041394) i2c: i2c command link malloc error
E (1041394) i2c: i2c command link malloc error
E (1041394) i2c: i2c command link malloc error
D (1041404) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1041404) i2c: i2c command link malloc error
D (1041414) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1041414) i2c: i2c command link malloc error
E (1041424) i2c: i2c command link malloc error
E (1041424) i2c: i2c command link malloc error
E (1041434) i2c: i2c command link malloc error
D (1041434) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1041444) i2c: i2c command link malloc error
E (1041444) i2c: i2c command link malloc error
D (1041554) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1041554) i2c: i2c command link malloc error
E (1041554) i2c: i2c command link malloc error
E (1041554) i2c: i2c command link malloc error
E (1041554) i2c: i2c command link malloc error
D (1041564) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1041574) i2c: i2c command link malloc error
E (1041574) i2c: i2c command link malloc error
D (1041584) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1041584) i2c: i2c command link malloc error
E (1041594) i2c: i2c command link malloc error
E (1041594) i2c: i2c command link malloc error
E (1041604) i2c: i2c command link malloc error
E (1041604) i2c: i2c command link malloc error
D (1041614) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1041614) i2c: i2c command link malloc error
E (1041624) i2c: i2c command link malloc error
E (1041624) i2c: i2c command link malloc error
D (1041734) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1041734) i2c: i2c command link malloc error
E (1041734) i2c: i2c command link malloc error
E (1041734) i2c: i2c command link malloc error
E (1041734) i2c: i2c command link malloc error
E (1041744) i2c: i2c command link malloc error
E (1041754) i2c: i2c command link malloc error
E (1042754) i2cdev: Could not read from device [0x68 at 1]: 263 (ESP_ERR_TIMEOUT)
D (1042754) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1042754) i2c: i2c command link malloc error
E (1042754) i2c: i2c command link malloc error
E (1042764) i2c: i2c command link malloc error
E (1042764) i2c: i2c command link malloc error
E (1043774) i2cdev: Could not write to device [0x68 at 1]: 263 (ESP_ERR_TIMEOUT)
D (1043774) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1043774) i2c: i2c command link malloc error
E (1043774) i2c: i2c command link malloc error
E (1043784) i2c: i2c command link malloc error
E (1043784) i2c: i2c command link malloc error
E (1043794) i2c: i2c command link malloc error
E (1043794) i2c: i2c command link malloc error
E (1044804) i2cdev: Could not read from device [0x68 at 1]: 263 (ESP_ERR_TIMEOUT)
D (1044804) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1044804) i2c: i2c command link malloc error
E (1044804) i2c: i2c command link malloc error
E (1044814) i2c: i2c command link malloc error
E (1044814) i2c: i2c command link malloc error
E (1045824) i2cdev: Could not write to device [0x68 at 1]: 263 (ESP_ERR_TIMEOUT)
D (1045924) i2cdev: Timeout: ticks = 0 (0 usec) on port 1
E (1045924) i2c: i2c command link malloc error
E (1045924) i2c: i2c command link malloc error
E (1045924) i2c: i2c command link malloc error
E (1045924) i2c: i2c command link malloc error
E (1045934) i2c: i2c command link malloc error
E (1045944) i2c: i2c command link malloc error
E (1045944) i2c: i2c command link malloc error
Guru Meditation Error: Core  0 panic'ed (StoreProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x400df01d  PS      : 0x00060d30  A0      : 0x800d6f8d  A1      : 0x3ffb8fe0  
0x400df01d: i2c_master_cmd_begin at C:/Users/me/AppData/Local/Programs/esp-idf/components/driver/i2c.c:1515

A2      : 0x00000001  A3      : 0x3fffffdc  A4      : 0x00000064  A5      : 0x3ffb7f48
A6      : 0x0001984f  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x3ffb8fb0
A10     : 0x00000000  A11     : 0x3ffb06ac  A12     : 0x00000008  A13     : 0x3ffb0688
A14     : 0x3f403bbc  A15     : 0x00000000  SAR     : 0x00000004  EXCCAUSE: 0x0000001d
EXCVADDR: 0x00000008  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xfffffffe


Backtrace: 0x400df01a:0x3ffb8fe0 0x400d6f8a:0x3ffb9020 0x400d714b:0x3ffb9060 0x400d76e2:0x3ffb9090 0x400d7252:0x3ffb90b0 0x40089dad:0x3ffb9
0x400df01a: i2c_master_cmd_begin at C:/Users/me/AppData/Local/Programs/esp-idf/components/driver/i2c.c:1515

0x400d6f8a: i2c_dev_read at C:/Users/me/Desktop/Project/Firmware/Project/components/i2cdev/i2cdev.c:297

0x400d714b: i2c_dev_read_reg at C:/Users/me/Desktop/Project/Firmware/Project/components/i2cdev/i2cdev.c:340

0x400d76e2: ktd2061_setChannelOff at C:/Users/me/Desktop/Project/Firmware/Project/components/KTD2061/KTD206
The I2C also starts to look wrong. As you can see, a transmision (one of those small lines on the left side) only takes ms, and at some point, the SDA line is pulled down, and doesn't return until a sec later
Image
I2C_Mem_alloc_error_result.PNG
I2C_Mem_alloc_error_result.PNG (43.22 KiB) Viewed 1938 times
Has someone got that problem, or knows what could be provoking it? By the way, I must say it allways happens after 15~16 min

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: I2C runs out of memory

Postby ESP_Sprite » Fri Feb 24, 2023 1:15 am

'E (1039044) i2c: i2c command link malloc error' sounds like you have a memory leak somewhere.

lukilukeskywalker
Posts: 21
Joined: Wed Feb 22, 2023 4:25 pm

Re: I2C runs out of memory

Postby lukilukeskywalker » Sun Feb 26, 2023 10:24 pm

And indeed, I had a memory leak :?
I didn´t free malloc-ed memory in a function of the library :oops:
I noticed it the same morning, but I couldn't find the post to tell about my error or delete it

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 117 guests