-
Notifications
You must be signed in to change notification settings - Fork 1.3k
incorrect use of i2c api leads to crash with idf4.4 #5680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I also caused a crash with another I2C sensor - si7021 |
hmmm -- this crashes
but this runs
|
@jerryneedell did you intend to close this? |
No.. sorry |
Closed by mistake |
Crashes a Feather ESP32-S2 TFT with an adalogger featherwing: import board
i = board.I2C()
i.try_lock()
b = bytearray(1)
i.writeto_then_readfrom(0x68, b, b) It's fine in 7.1.0, broken in 7.2.0-alpha.1. |
Hi! I've been having a similar problem, but on an ESP32-S3 (ESP32-S3-DevKitC-1 w/ 2MB PSRAM), running on tinyuf2 (although i had the same problem without tinyuf2). I first had the problem trying to use a DS1337 (with the DS1307 library), and a PCF8523 (CircuitPython hard crashed when calling the libraries' constructors). I looked at the libraries in the issue history, and the SI7021, DS1307, PCF8523 libraries call I rebuilt CircuitPython with DEBUG=1 and tried to initalise the PCF8523, which crashed the ESP32. I was able to listen to the trace log with I googled that function name, and found someone on the Micropython forums that had a very similar problem. They fixed it with a patch to ESP-IDF v4.4. I applied it to my local circuitpython copy, and rebuilt, and i2c seems to work fine. I got successful tests with a TLV493D, SHTC3, and DS1337 (using the DS1307 library), but I couldn't get the PCF8523 to work (I think that might be for an unrelated reason?) I checked the ESP-IDF versions, and CircuitPython v7.1.0 uses ESP-IDF v4.3, while v7.2.0-alpha1 uses v4.4. The ESP-IDF version was bumped to v4.4 on 2021-12-30 (4daa7b5), but the build of circuitpython in the original issue post was built on 2021-12-07, and I experienced the bug on a version built on 2021-12-29, so it would have still been using v4.3? I'm not totally convinced this is the cause, but I think it was worth mentioning. |
In theory, this Closes: adafruit#5680 -- I didn't test it on HW yet.
Investigating this further I found espressif/esp-idf#7405 Per the comments there, our sequence of API calls in common_hal_busio_write is not acceptable in esp-idf, because we omit the
|
I rebuilt CircuitPython with an unpatched ESP-IDF (release-v4.4), and changed busio's // line 328
writeto(self, args[ARG_address].u_int, args[ARG_out_buffer].u_obj, args[ARG_out_start].u_int,
args[ARG_out_end].u_int, true); // <- set to true to send stop bits
readfrom(self, args[ARG_address].u_int, args[ARG_in_buffer].u_obj, args[ARG_in_start].u_int,
args[ARG_in_end].u_int); I tested this with the I2C devices I used in my last post, and they all seem to work fine. Although I don't own a lot of I2C devices, so I don't know if enabling stop bits would break anything else in the CircuitPython ecosystem. Another thing that I've been thinking about is that there must have been some reason to set the stop bit flag to false in the first place. |
I don't think there is supposed to be a stop bit before the repeated start. I suspect we'll need to have a common-hal API for writeto_then_readfrom so we can do one call to the IDF for it. What is the right call to the IDF for this? |
I don't know the IDF's I2C API that well, but I couldn't find a It made me realise that CircuitPython's |
@atctwo Great find! We'll need to "push down" the writeto() and readfrom() calls into a common_hal function in CP. That way the ESP version can call |
I am debugging #5934. I don't know if this is related at all or not. |
CircuitPython version
Code/REPL
Behavior
Safe mode
Description
Initially noted by @Jerryn on Discord, also seen by @KeithTheEE in the same discussion.
Additional information
No response
The text was updated successfully, but these errors were encountered: