-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Esp32-S2 I2C fixes #4387
Esp32-S2 I2C fixes #4387
Conversation
@dhalbert I have some time and will test this now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this using the CI artifacts on a MetroS2 an a Feather S2 PreRelease.
I ran dan's second code sample, and my own script using the BME_680. Both worked as expected.
I then copied over a script that connects to wifi and then prints the BME values.
It failed to safemode, when I disconnected USB and connected again the script worked.
I tried to reproduce that auto-load failure 10 times and could not.
Unless other people see that behavior, I would call this good.
tested on UM FeatherS2. |
Thank you very much for the testing! I've now moved this up to esp-idf merge commit (code is identical), and turned off draft status. |
When #4378 is changed and merged, it will change from using bitbangio for 0, 1, or 2-byte writes to just 0-byte writes. I will try to test the equivalent of that change with some of the failing peripherals above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! @dhalbert.
I tested all three provided examples on my microS2 and they work flawlessly. Just one question...
@dhalbert I think we can get the idf patch in v4.3 since its a pre-release at the moment. |
I agree, it would be good to PR upstream, but I am still somewhat bothered by the whole thing because I don't see why the IDF fix works. I did some more experiments yesterday and re-read a bunch of our code and their code. I came to no new conclusion. I haven't gotten feedback from igrr about it. Also I inquired with FreeRTOS: https://forums.freertos.org/t/vsemaphoredelete-immediately-after-xsemaphoretake/11956. Ideally I would like to reproduce this in a simple ESP-IDF program, because they might ask for a test case, but I don't have any experience writing one. I could submit a PR and see what happens, but the fix seems a bit superstitious. There are other examples of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! for making the changes.
No clue at the moment, I'll try to replicate this behavior in an |
Failed build was a network problem. Merging. |
When I look at the multiple threads running in a "crashed" program vs one running this fix, they look the same. In other words, it is not a hard crash, but some kind of loop or other problem. The clue with my simple tests above is that the REPL stops working, and eventually disconnects. So perhaps some program that does some USB serial activitiy would hang up. Perhaps also some wifi or I2C activity would fail - that might be easier to test. |
This is the simplest example that reliably fails without the fix. It prints import board,busio
i2c = busio.I2C(board.SCL, board.SDA)
i2c.deinit()
import wifi |
Yes, I get the same behavior... it hangs and no backtrace. From the debug print I see that wifi starts initializing but stops abruptly. |
So the essence of the above is (you can double check this): // From busio.I2C().
i2c_driver_delete(NULL); // does nothing
i2c_param_config();
i2c_driver_install();
// i2c.deinit().
i2c_driver_delete();
// Below from common_hal_wifi_init() and common_hal_wifi_radio_set_enabled().
esp_netif_init();
esp_event_loop_create_default();
xEventGroupCreateStatic();
esp_event_handler_instance_register();
esp_event_handler_instance_register();
esp_wifi_init();
esp_wifi_set_mode();
esp_wifi_start(); I tried moving the |
Yup! that's it... you want to go ahead with the |
I'll try to get the time; I'll let you know. I guess I can gut one of their examples and put that in. |
Glad someone is also wondering why it works. I just got in and all my questions have been posed. |
Moving this discussion to a new issue, #4401. |
Fixes #3846.
Fixes #4046.
i2c_driver_install()
andi2c_driver_delete()
.i2c.c
in the ESP-IDF about how a semaphore is deleted.Tagging @askpatrickw, @microdev1, @skieast for testing.
This is a draft because it depends on adafruit/esp-idf#1, which is not yet done. This build temporarily uses https://github.com/dhalbert/esp-idf/tree/circuitpython-i2c-cmd_mux-fix.
Tests that now work: