Closed andycarle closed 2 years ago
I have the same problem. The following quick fix seems to rectify the problem:
The problematic line 1345 should have a null-pointer guard, like so:
if(p_i2c->cmd_link.head) {
p_i2c->cmd_link.head->cmd.bytes_used = 0;
}
@suslic2012 Agreed that that is probably the right fix. Perhaps one of us should just put in a PR to that effect referencing this issue and see if anyone disagrees.
Hi @andycarle and @suslic2012 , Thanks for reporting this issue (and for the PR), I am going to handle this.
Small remark regarding the snippet of code you showed. In 4.4, you can now provide a buffer to i2c_cmd_link_create_static
in order to create a static command link (macro I2C_LINK_RECOMMENDED_SIZE
can help for determining the minimum size required for a particular transfer). This is handy if you want to avoid dynamic allocations, increasing program's speed.
Check this function here: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/i2c.html#_CPPv426i2c_cmd_link_create_staticP7uint8_t8uint32_t
Another new feature is the possibility to reuse already-sent command links. Let's say that you need to send a buffer multiple times on the bus and only few bytes change across the calls, you can use this feature to only modify the bytes that need to within your buffer and then re-use the same I2C command link to start a new transfer. This is useful for framebuffers, for example.
@o-marshmallow Nice; thank you for the heads-up for and taking a look at this issue!
Fix for v4.4: f60a914
Thanks @AxelLin for the commit number! Closing this issue
Can you also look at adding the same thing on line 1289?
EDIT: Opened a new issue #8548
Environment
Problem Description
In ESP-IDF v4.4, I2C command links that do not terminate with a stop bit (
i2c_master_stop
) cause a crash.For instance, this code:
crashes when
sendStop
isfalse
. The crash is (fromidf.py monitor
):The same code does not crash when
sendStop
istrue
.This crash makes it impossible to create sequences of I2C writes and reads with repeated start conditions across multiple I2C command links. This ability is a requirement for implementing the ECMA-419 ECMAScript embedded systems API specification on top of the ESP-IDF. More generally, this ability is needed for any application framework that allows construction of raw I2C and SMBus read/write sequences by stringing together atomic I2C read and write commands, such as is supported in the Moddable SDK's I2C implementation.
I2C command links without stop bits at the end worked as expected in ESP-IDF v4.3.2. This issue is new to ESP-IDF v4.4.
Expected Behavior
I2C command links that do not end with a stop bit do not crash.
Actual Behavior
I2C command links that do not end with a stop bit crash.
Debug Logs