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
Crash when repeatedly creating and destroying busio.I2C object #3846
Comments
@igrr We've been puzzled by multiple i2c problems in CircuitPython. This one is pretty simple to reproduce, can you take a look and see if you can spot what we're doing wrong with the esp-idf APIs? Thanks! |
I'll need to set up circuitpython build environment again to debug this, but upon cursory look i don't see anything wrong with I2C APIs usage. Just a few notes, i doubt any of this is the cause of this issue, though:
|
Indicates the value of CPU program counter at the time when the watchdog triggered. 0x40028200 seems to be part of the vector table, specifically the Level4InterruptVector. This interrupt level is associated with various debugging features. On the ESP32-S2 these are interrupt watchdog interrupt and memory protection interrupt. Normally this level 4 interrupt handler invokes the panic handler, which prints a nice human-readable panic message to the UART console. This doesn't seem to be the case here, which indicates that either some memory got corrupted, and the Level4 interrupt and/or the panic handler do not do their job anymore; or that there is some other system-level issue. |
Thank you for the pointers @igrr!
|
Progress notes: I looked more carefully at how to do I have gone back to the original scheme of installing and deleting I2C drivers on demand. I think have fixed the problem of installing and deleting the driver multiple times. But I am still looking at why deleting an I2C driver then causes the Typical test that will cause a crash with the old scheme: import board,busio
i2c = busio.I2C(board.SCL, board.SDA)
i2c.deinit()
import wifi |
@igrr I narrowed down the issue to the treatment of a single semaphore in esp_err_t i2c_driver_delete(i2c_port_t i2c_num)
{
I2C_CHECK(i2c_num < I2C_NUM_MAX, I2C_NUM_ERROR_STR, ESP_ERR_INVALID_ARG);
I2C_CHECK(p_i2c_obj[i2c_num] != NULL, I2C_DRIVER_ERR_STR, ESP_FAIL);
i2c_obj_t *p_i2c = p_i2c_obj[i2c_num];
i2c_hal_disable_intr_mask(&(i2c_context[i2c_num].hal), I2C_INTR_MASK);
esp_intr_free(p_i2c->intr_handle);
p_i2c->intr_handle = NULL;
if (p_i2c->cmd_mux) {
xSemaphoreTake(p_i2c->cmd_mux, portMAX_DELAY); //<--------- commenting this out prevents the crash
vSemaphoreDelete(p_i2c->cmd_mux);
}
... This This seems related to your case 3. above. Is this a bug? This code is the same at the tip of master. Another test I did was not to actually free the Thanks for your help with all this. EDIT: Some more research. The CircuitPython code above does not do any I2C transactions. I put some logging in |
Running the following sequence twice in the same REPL causes CircuitPython to reset (not into safe mode, just a "normal" reset!)
Tested on a kaluga with
DEBUG=1
at f2204d7(tio is my terminal program)
gdb debugging doesn't show anything interesting. hardware debug console doesn't show anything interesting. I don't know how to continue debugging this sort of reset (e.g., to set a breakpoint to "catch" it)
The text was updated successfully, but these errors were encountered: