Open Andrew-Exeter opened 2 weeks ago
No it shouldn't be this case It looks that i2c_isr_receive_handler function tries to write some data to user read/write buffer (data member of i2c_operation_t) which is not assigned to i2c operation of type I2C_LL_CMD_STOP, but I could be wrong.
Umm, could you please try that in the latest master, setting .scl_wait_us = 0,
with larger value like 20*1000, and see if there is anything wrong.
Secondly, what about slowing down scl frequency
As for QMC5883 is the exclusive sensor that causes this error, interesting and I'm going to got one for further debugging.
By the way, are you sure 0x0D
is correct in your case? I think I2C hardware NACK detected
thought the address is wrong. Even this is not the root cause of this bug
Thank you for your reply.
I tried following combinations of configuration changes and always was able to reproduce the same exception/backtrace:
.scl_speed_hz = 50000
.scl_wait_us = 20000
.scl_speed_hz = 50000
, .scl_wait_us = 20000
.scl_speed_hz = 10000
, .scl_wait_us = 20000
.scl_speed_hz = 10000
, .scl_wait_us = 40000
.scl_speed_hz = 10000
, .scl_wait_us = 40000
, .i2c_port = I2C_NUM_0
.scl_speed_hz = 10000
, .scl_wait_us = 40000
, .intr_priority = 3
.scl_speed_hz = 10000
, .scl_wait_us = 40000
, .glitch_ignore_cnt = 14
.scl_speed_hz = 10000
, .scl_wait_us = 40000
, .glitch_ignore_cnt = 28
.scl_speed_hz = 10000
, .scl_wait_us = 40000
, .glitch_ignore_cnt = 56
Tests has been done with esp-idf repository updated to v5.4-dev-2620-g6673376297 version.
Addresses of QMC5883 and status register should be valid, they are taken over from library, which was able to read the sensor properly, and values matches with register map in datasheet. To be sure, I tested it using /examples/peripherals/i2c/i2c_tools
:
i2c-tools> i2cconfig --port=1 --freq=400000 --sda=19 --scl=18
I (165256) gpio: GPIO[19]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (165256) gpio: GPIO[18]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
i2c-tools> i2cdetect
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- -- 0d -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
i2c-tools> i2cget -c 0x0D -r 0x06
0x00
i2c-tools> i2cset -c 0x0D -r 0x09 0x01
I (510556) cmd_i2ctools: Write OK
i2c-tools> i2cget -c 0x0D -r 0x06
0x05
(After sensor is switched to continuous mode by MODE
field in "Control Register 1" (0x09
), DRDY
and DOR
flags in "Status Register" (0x06
) indicates operation.)
Some I2C hardware NACK detected
are in the debug log because circuit is on a breadboard, not ideal connections ...
I tried following combinations of configuration changes and always was able to reproduce the same exception/backtrace:
Strange, anyway, my sensor is on the way, I will try to reproduce that locally and see what is exactly happening..
I got a QMC5883 but regretfully didn't reproduce the same issue. But anyway, I go through the gdb log again, It seems that it really want to receive data in STOP command as you described. I don't know why this happened excactly.. still debugging.
Because you can reproduce easily, may you please try add a line https://github.com/espressif/esp-idf/blob/master/components/esp_driver_i2c/i2c_master.c#L430 here i2c_master->contains_read = false;
and see if this will happen once more? Thanks @Andrew-Exeter
But..
From the gdb log, the interrupt has been triggered in a very strange place, it shouldn't be theoretical. So, do you use multi core to run i2c or enable some special configs?
After adding i2c_master->contains_read = false;
exceptions kept appearing.
I tried to append printf("///---///\n");
after the line 430
to see when the code is reached, maybe it could be useful:
///---///
///---///
///---///
///---///
///---///
///---///
///---///
///---///
///---///
///---///
E (12719) i2c.master: I2C hardware timeout detected
E (12729) i2c.master: s_i2c_synchronous_transaction(896): I2C transaction failed
I (12729) gpio: GPIO[19]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (12739) gpio: GPIO[18]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
E (12749) i2c.master: i2c_master_transmit_receive(1169): I2C transaction failed
I (12859) gpio: GPIO[19]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (12859) gpio: GPIO[18]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (12869) gpio: GPIO[19]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (12869) gpio: GPIO[18]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
E (12879) i2c.master: I2C hardware timeout detected
E (12889) i2c.master: s_i2c_synchronous_transaction(896): I2C transaction failed
I (12899) gpio: GPIO[19]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (12909) gpio: GPIO[18]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
E (12909) i2c.master: i2c_master_transmit_receive(1169): I2C transaction failed
I (13019) gpio: GPIO[19]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (13019) gpio: GPIO[18]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
E (13039) i2c.master: I2C software timeout
E (13039) i2c.master: s_i2c_synchronous_transaction(896): I2C transaction failed
I (13039) gpio: GPIO[19]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (13049) gpio: GPIO[18]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
E (13059) i2c.master: i2c_master_transmit_receive(1169): I2C transaction failed
I (13169) gpio: GPIO[19]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (13169) gpio: GPIO[18]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
Guru Meditation Error: Core 0 panic'ed (StoreProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x40084437 PS : 0x00060033 A0 : 0x8008454d A1 : 0x3ffb0f40
0x40084437: i2c_ll_read_rxfifo at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/hal/esp32/include/hal/i2c_ll.h:576
(inlined by) i2c_isr_receive_handler at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/esp_driver_i2c/i2c_master.c:633
A2 : 0x3ffb4bfc A3 : 0x3ffb4c0c A4 : 0x3ffb0f70 A5 : 0x00000000
A6 : 0x3ffb4ed0 A7 : 0x3ffb4c70 A8 : 0x00000000 A9 : 0x00000000
A10 : 0x00000000 A11 : 0x00000001 A12 : 0x00000000 A13 : 0x00000000
A14 : 0x3ff67000 A15 : 0x0000cdcd SAR : 0x00000020 EXCCAUSE: 0x0000001d
EXCVADDR: 0x00000000 LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0x00000000
0x4000c46c: memset in ROM
0x4000c477: memset in ROM
Backtrace: 0x40084434:0x3ffb0f40 0x4008454a:0x3ffb0f70 0x4008238d:0x3ffb0fb0 0x40082e0d:0x3ffb0fd0 0x4000bfed:0x3ffb3d30 0x400868c6:0x3ffb3d40 0x400d96e7:0x3ffb3d60 0x400d9ea3:0x3ffb3db0 0x400da051:0x3ffb3de0 0x400da125:0x3ffb3e10 0x400dab95:0x3ffb3e40 0x400d6761:0x3ffb3ed0 0x400e6b98:0x3ffb3f30 0x40086515:0x3ffb3f60
0x40084434: i2c_ll_read_rxfifo at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/hal/esp32/include/hal/i2c_ll.h:576
(inlined by) i2c_isr_receive_handler at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/esp_driver_i2c/i2c_master.c:633
0x4008454a: i2c_master_isr_handler_default at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/esp_driver_i2c/i2c_master.c:691
0x4008238d: shared_intr_isr at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/esp_hw_support/intr_alloc.c:445
0x40082e0d: _xt_lowint1 at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/xtensa/xtensa_vectors.S:1240
0x4000bfed: _xtos_set_intlevel in ROM
0x400868c6: vPortClearInterruptMaskFromISR at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:560
(inlined by) vPortExitCritical at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:509
0x400d96e7: vPortExitCriticalSafe at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:596
(inlined by) s_i2c_start_end_command at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/esp_driver_i2c/i2c_master.c:364
0x400d9ea3: s_i2c_send_commands at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/esp_driver_i2c/i2c_master.c:488
0x400da051: s_i2c_transaction_start at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/esp_driver_i2c/i2c_master.c:608
0x400da125: s_i2c_synchronous_transaction at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/esp_driver_i2c/i2c_master.c:896
0x400dab95: i2c_master_transmit_receive at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/esp_driver_i2c/i2c_master.c:1169
0x400d6761: app_main at C:/Users/Andrew_Exeter/espressif_projects/i2c_test/main/main.c:45
0x400e6b98: main_task at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/freertos/app_startup.c:208
0x40086515: vPortTaskWrapper at C:/Users/Andrew_Exeter/esp/master/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:134
So, do you use multi core to run i2c or enable some special configs?
I'am not sure if I understood question properly, but driver API is called always from single task. I use code provided in "Steps to reproduce." section for all tests. I don't know whether it is related, but compiling project with sdkconfig option FREERTOS_UNICORE
doesn't change behavior.
I tried delete sdkconfig
file to recovery default settings, again with same results. Are there some another configurations, which I should check?
no more need to check. I tried several scenario like nack or timeout, no produce anyway... i will continue going through. But a suggestion for you might to decline the error report like nack or timeout in order that try not to disturb the state machine..
Answers checklist.
IDF version.
v5.2.2-639-g43098fc4de, v5.3-383-g0bbd728196, v5.4-dev-2596-g6e5414b6c4
Espressif SoC revision.
ESP32-D0WDQ6 (revision v1.0)
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
None
Development Kit.
NodeMCU-ESP32 ESP32 DEVKITV1
Power Supply used.
USB
What is the expected behavior?
i2c_master_transmit_receive
function should return error code on i2c transaction failure.What is the actual behavior?
StoreProhibited
exception is thrown by accessing to null ptr in functioni2c_ll_read_rxfifo
.Steps to reproduce.
main/main.c
andmain/CMakeLists.txt
files.void app_main(void) { i2c_master_bus_config_t i2c_mst_config = { .i2c_port = I2C_NUM_1, .sda_io_num = GPIO_NUM_19, .scl_io_num = GPIO_NUM_18, .clk_source = I2C_CLK_SRC_DEFAULT, .glitch_ignore_cnt = 7, .intr_priority = 0, .trans_queue_depth = 0, .flags = { .enable_internal_pullup = true, } };
i2c_master_bus_handle_t bus = NULL; if (i2c_new_master_bus(&i2c_mst_config, &bus) == ESP_OK) { printf("bus installed\n");
}
while (true) { vTaskDelay(1000/portTICK_PERIOD_MS); } }
idf_component_register(SRCS "main.c" INCLUDE_DIRS "." PRIV_REQUIRES driver)
More Information.
My project crashed time by time and always with same exception/backtrace. To exclude posibilities that problem is related to other project specific code or configuration I created new project as described in "Steps to reproduce" section, but with same behavior. Clean installations of esp-idf and tools didn't help. (I tried versions v5.2, v5.3, master) I tried
/examples/peripherals/i2c/i2c_tools
example too. During i2c device register reading ("i2cget" command) occurs exactly same exception.This problem araised mostly (almost exclusively) with QMC5883 sensor in comparison to other i2c devices.
It looks that
i2c_isr_receive_handler
function tries to write some data to user read/write buffer (data
member ofi2c_operation_t
) which is not assigned to i2c operation of typeI2C_LL_CMD_STOP
, but I could be wrong.I am attaching backtrace, states of lacal variables and states of same other i2c driver related objects acquired using GDB debugger:
gdb-backtrace.txt gdb-i2c_master_bus_t-related.txt gdb-locals.txt