Skip to content
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 I2C主机模式是否在I2C总线出问题时会导致程序崩溃? (AUD-5760) #1293

Closed
SantaPasserby opened this issue Oct 12, 2024 · 2 comments

Comments

@SantaPasserby
Copy link

Environment

  • [Required] Module or chip used: [ESP32-WROOM-32E]
  • [Required] IDF version:v5.3.1-395-g707d097b01
  • [Required] ADF version: v2.7
  • Build system: [idf.py]
  • [Required] Running log:

`ets Jul 29 2019 12:21:46
rst:0x1 (POWERON_RESET),boot:0x12 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:7524
load:0x40078000,len:16540
load:0x40080400,len:4
--- 0x40080400: _init at ??:?
load:0x40080404,len:4312
entry 0x4008065c
I (29) boot: ESP-IDF v5.3.1-395-g707d097b01-dirty 2nd stage bootloader
I (29) boot: compile time Oct 12 2024 02:30:27
I (31) boot: Multicore bootloader
I (35) boot: chip revision: v3.0
I (39) qio_mode: Enabling default flash chip QIO
I (45) boot.esp32: SPI Speed : 40MHz
I (49) boot.esp32: SPI Mode : QIO
I (54) boot.esp32: SPI Flash Size : 16MB
I (58) boot: Enabling RNG early entropy source...
I (64) boot: Partition Table:
I (67) boot: ## Label Usage Type ST Offset Length
I (75) boot: 0 nvs WiFi data 01 02 00011000 00004000
I (82) boot: 1 otadata OTA data 01 00 00015000 00002000
I (90) boot: 2 phy_init RF data 01 01 00017000 00001000
I (97) boot: 3 ota_0 OTA app 00 10 00020000 00300000
I (105) boot: 4 ota_1 OTA app 00 11 00320000 00300000
I (112) boot: 5 storage Unknown data 01 81 00620000 00400000
I (120) boot: End of partition table
I (124) boot: No factory image, trying OTA 0
I (129) esp_image: segment 0: paddr=00020020 vaddr=3f400020 size=0f960h ( 63840) map
I (156) esp_image: segment 1: paddr=0002f988 vaddr=3ffbdb60 size=00690h ( 1680) load
I (157) esp_image: segment 2: paddr=00030020 vaddr=400d0020 size=25068h (151656) map
I (206) esp_image: segment 3: paddr=00055090 vaddr=3ffbe1f0 size=01e5ch ( 7772) load
I (208) esp_image: segment 4: paddr=00056ef4 vaddr=40080000 size=0dab0h ( 55984) load
I (237) boot: Loaded app from partition at offset 0x20000
I (279) boot: Set actual ota_seq=1 in otadata[0]
I (279) boot: Disabling RNG early entropy source...
I (290) quad_psram: This chip is ESP32-D0WD
I (290) esp_psram: Found 8MB PSRAM device
I (290) esp_psram: Speed: 40MHz
I (294) esp_psram: PSRAM initialized, cache is in low/high (2-core) mode.
W (301) esp_psram: Virtual address not enough for PSRAM, map as much as we can. 4MB is mapped
I (311) cpu_start: Multicore app
I (326) cpu_start: Pro cpu start user code
I (326) cpu_start: cpu freq: 240000000 Hz
I (326) app_init: Application information:
I (331) app_init: Project name: IPB_AS_APP_ESP32
I (337) app_init: App version: 065255f-dirty
I (342) app_init: Compile time: Oct 12 2024 02:30:07
I (348) app_init: ELF file SHA256: fdd1478bc8660eae...
I (354) app_init: ESP-IDF: v5.3.1-395-g707d097b01-dirty
I (361) efuse_init: Min chip rev: v3.0
I (365) efuse_init: Max chip rev: v3.99
I (370) efuse_init: Chip rev: v3.0
I (375) heap_init: Initializing. RAM available for dynamic allocation:
I (382) heap_init: At 3FFAE6E0 len 0000F480 (61 KiB): DRAM
I (388) heap_init: At 3FFC0C40 len 0001F3C0 (124 KiB): DRAM
I (395) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (401) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (407) heap_init: At 4008DAB0 len 00012550 (73 KiB): IRAM
I (414) esp_psram: Adding pool of 4096K of PSRAM memory to heap allocator
I (422) spi_flash: detected chip: generic
I (426) spi_flash: flash io: qio
I (430) main_task: Started on CPU0
I (434) esp_psram: Reserving pool of 32K of internal memory for DMA/internal allocations
I (442) main_task: Calling app_main()
I (457) gpio: GPIO[39]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (458) gpio: GPIO[36]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (467) gpio: GPIO[32]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (476) gpio: GPIO[12]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (486) gpio: GPIO[14]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
W (495) i2c_bus_v2: I2C master handle is NULL, will create new one
I (502) gpio: GPIO[15]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (511) gpio: GPIO[2]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (522) main_task: Returned from app_main()
E (129283) i2c.master: I2C hardware NACK detected
E (129283) i2c.master: I2C transaction unexpected nack detected
E (129284) i2c.master: s_i2c_synchronous_transaction(880): I2C transaction failed
I (129292) gpio: GPIO[15]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (129301) gpio: GPIO[2]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
E (129311) i2c.master: i2c_master_transmit_receive(1118): I2C transaction failed
E (134282) i2c.master: I2C hardware NACK detected
E (134283) i2c.master: I2C transaction unexpected nack detected
E (134283) i2c.master: s_i2c_synchronous_transaction(880): I2C transaction failed
I (134292) gpio: GPIO[15]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (134301) gpio: GPIO[2]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
E (134311) i2c.master: i2c_master_transmit(1095): I2C transaction failed
E (137219) i2c.master: I2C hardware NACK detected
E (137220) i2c.master: I2C transaction unexpected nack detected
E (137220) i2c.master: s_i2c_synchronous_transaction(880): I2C transaction failed
I (137229) gpio: GPIO[15]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (137238) gpio: GPIO[2]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
E (137248) i2c.master: i2c_master_transmit_receive(1118): I2C transaction failed
E (191284) i2c.master: I2C hardware NACK detected
E (191284) i2c.master: I2C transaction unexpected nack dete.master: s_i2c_synchronous_transaction(880): I2C transaction failed
I (191293) gpio: GPIO[15]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (191302) gpio: GPIO[2]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
E (191312) i2c.master: i2c_master_transmit_receive(1118): I2C transaction failed
Guru Meditation Error: Core 0 panic'ed (StoreProhibited). Exception was unhandled.

Core 0 register dump:
PC : 0x40085709 PS : 0x00060033 A0 : 0x8008235c A1 : 0x3ffbecf0
--- 0x40085709: i2c_ll_read_rxfifo at /opt/esp/idf/components/hal/esp32/include/hal/i2c_ll.h:576
(inlined by) i2c_isr_receive_handler at /opt/esp/idf/components/esp_driver_i2c/i2c_master.c:617
(inlined by) i2c_master_isr_handler_default at /opt/esp/idf/components/esp_driver_i2c/i2c_master.c:675

A2 : 0x3ffb7230 A3 : 0xffffffff A4 : 0x00000001 A5 : 0x3ffb755c
A6 : 0x3ffb755c A7 : 0x3ffb72a4 A8 : 0x00000000 A9 : 0x00000000
A10 : 0x00000001 A11 : 0x3ff53000 A12 : 0x00000000 A13 : 0x00000000
A14 : 0x00000000 A15 : 0x0000cdcd SAR : 0x00000000 EXCCAUSE: 0x0000001d
EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0x00000000
--- 0x4000c2e0: memcpy in ROM
0x4000c2f6: memcpy in ROM

Backtrace: 0x40085706:0x3ffbecf0 0x40082359:0x3ffbed30 0x40083d4d:0x3ffbed50 0x4000bfed:0x3f802f50 0x40087937:0x3f802f60 0x400859b1:0x3f802f80 0x400f2f7d:0x3f802fc0 0x400f3114:0x3f802ff0 0x400f3408:0x3f803020 0x400f3c59:0x3f803050 0x400d7194:0x3f8030e0 0x400d6e19:0x3f803110 0x400d65b2:0x3f803140
--- 0x40085706: i2c_ll_read_rxfifo at /opt/esp/idf/components/hal/esp32/include/hal/i2c_ll.h:576
(inlined by) i2c_isr_receive_handler at /opt/esp/idf/components/esp_driver_i2c/i2c_master.c:617
(inlined by) i2c_master_isr_handler_default at /opt/esp/idf/components/esp_driver_i2c/i2c_master.c:675
0x40082359: shared_intr_isr at /opt/esp/idf/components/esp_hw_support/intr_alloc.c:445
0x40083d4d: _xt_lowint1 at /opt/esp/idf/components/xtensa/xtensa_vectors.S:1240
0x4000bfed: _xtos_set_intlevel in ROM
0x40087937: vPortClearInterruptMaskFromISR at /opt/esp/idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:560
(inlined by) vPortExitCritical at /opt/esp/idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:509
0x400859b1: vPortExitCriticalSafe at /opt/esp/idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:596
(inlined by) s_i2c_start_end_command at /opt/esp/idf/components/esp_driver_i2c/i2c_master.c:357
0x400f2f7d: s_i2c_send_commands at /opt/esp/idf/components/esp_driver_i2c/i2c_master.c:479
0x400f3114: s_i2c_transaction_start at /opt/esp/idf/components/esp_driver_i2c/i2c_master.c:592
0x400f3408: s_i2c_synchronous_transaction at /opt/esp/idf/components/esp_driver_i2c/i2c_master.c:880
(inlined by) s_i2c_synchronous_transaction at /opt/esp/idf/components/esp_driver_i2c/i2c_master.c:860
0x400f3c59: i2c_master_transmit_receive at /opt/esp/idf/components/esp_driver_i2c/i2c_master.c:1118
0x400d7194: i2c_bus_read_bytes at /opt/esp/esp-adf/esp-adf-v2.7/components/esp_peripherals/driver/i2c_bus/i2c_bus_v2.c:206
0x400d6e19: extend_mcu_read_reg at /workspaces/components/extern_mcu/extend_mcu.c:53
0x400d65b2: extend_mcu_task at /workspaces/main/app/app_extend_mcu.c:96

`

  • Compiler version ): xtensa-esp-elf-gcc (crosstool-NG esp-13.2.0_20240530) 13.2.0
  • Operating system: [Linux]
  • Using an IDE?: [No]
  • Power supply: [external 3.3V]

Problem Description

ESP32与STM32通过i2c总线通讯,STM32一端是作为从机,STM32 硬件I2C控制器偶尔会崩溃,但会重启控制器。STM32 I2C控制器崩溃时,会导致I2C总线无法正常使用。ESP32 I2C经过长时间就会出现上述崩溃信息,从崩溃信息分析,应该是遇到了NULL指针。在idf-v4.4与adf-v2.6版本一起搭配使用的时候,没有遇到这样的崩溃。

Code

代码也相当简单,就ESP32不断通过I2C总线去读写STM32实现的I2C从设备。

  • 下面是I2C操作代码:
static int i2c_init(void)
{
    int ret = 0;
    i2c_config_t es_i2c_cfg = {
        .mode = I2C_MODE_MASTER,
        .sda_pullup_en = GPIO_PULLUP_ENABLE,
        .scl_pullup_en = GPIO_PULLUP_ENABLE,
        .master.clk_speed = 100000,
    };
    ret = get_i2c_pins(I2C_NUM_0, &es_i2c_cfg);

    EXTEND_MCU_ASSERT(ret, "getting i2c pins error", ESP_FAIL);
    i2c_handle = i2c_bus_create(I2C_NUM_0, &es_i2c_cfg);
    return ret;
}

esp_err_t extend_mcu_write_reg(uint8_t slave_addr, uint8_t reg_add, uint8_t *p_data)
{
    return i2c_bus_write_bytes(i2c_handle, slave_addr, &reg_add, sizeof(reg_add), p_data, 1);
	// return EXTEND_MCU_Write_Buff(reg_add, p_data, 1);
}
esp_err_t extend_mcu_read_reg(uint8_t slave_addr, uint8_t reg_add, uint8_t *p_data)
{
    return i2c_bus_read_bytes(i2c_handle, slave_addr, &reg_add, sizeof(reg_add), p_data, 1);
	// return EXTEND_MCU_Read_Buff(reg_add, p_data, 1);
}
  • 下面是读写STM32 I2C设备的线程函数:
void app_extend_mcu_init(void)
{
#if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
    task = heap_caps_calloc(1, sizeof(StaticTask_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
    stack = (StackType_t *) heap_caps_malloc(TASK_EXTERNAL_STACk_SIZE, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT);
    if(task && stack) {
        if(xTaskCreateStatic(extend_mcu_task, "mcu", TASK_EXTERNAL_STACk_SIZE, NULL, 1, stack, task) == NULL) {

            heap_caps_free(task);
            heap_caps_free(stack);
            ESP_LOGE(TAG, "mcu thread create failed!");
            return;
        }
    }
    else {
        if(task) heap_caps_free(task);
        if(stack) heap_caps_free(stack);
        ESP_LOGE(TAG, "mcu thread malloc failed!");
        return;
    }
#else
    xTaskCreate(extend_mcu_task, "mcu", 4096, NULL, 1, NULL);
#endif
}
static void extend_mcu_task(void *arg) {
    
    uint8_t buf = 0;
    uint8_t val;
    uint16_t t_id, p_id;
    uint32_t addr;
    uint32_t id;
    uint8_t device_name[16];
    uint8_t type = 0;
    uint32_t state;
    struct tm *tm_time;
    time_t time;
    for(;;) {

        /** 设备类型 */
        get_device_name((char *)device_name, sizeof(device_name));
        if(device_name[4] == 'D') {
            if(device_name[5] == '3') {
                type = 0x5A;
            } else {
                type = 0;
            }
        } else if((device_name[4] == 'B' && device_name[5] == '2') ||
                   (device_name[4] == 'A' && device_name[5] == '1')) {
            vTaskDelay(pdMS_TO_TICKS(1500));
            continue;
        }

        if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_DEVICE_TYPE, &buf) == ESP_OK) {
            val = type;
            if(buf != val) {
                if(extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_DEVICE_TYPE, &val) == ESP_OK) {
                    
                }
            }
        }


        state = get_exam_mode_state();
        if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_EXAM_MODE, &buf) == ESP_OK) {
            val = (uint8_t)state;
            if(buf != val) {
                if(extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_EXAM_MODE, &val) == ESP_OK) {
                    
                }
            }
        }
        /** 设备状态 */
        state = get_device_state();
        if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_DEVICE_STATUS, &buf) == ESP_OK) {
            val = (uint8_t)state;
            if(buf != val) {
                if(extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_DEVICE_STATUS, &val) == ESP_OK) {
                    
                }
            }
        }

        if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_SYS_LED, &buf) == ESP_OK) {
            val = is_ethernet_connected();
            if(buf != val) {
                if(extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_SYS_LED, &val) == ESP_OK) {
                    
                }
            }
        }
        if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_RELAY_DC, &buf) == ESP_OK) {
            val = get_pwr_state(POWER_24V_CTL);
            if(buf != val) {
                if(extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_RELAY_DC, &val) == ESP_OK) {

                }
            }
        }
        if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_RELAY_AC2, &buf) == ESP_OK) {
            val = get_pwr_state(POWER_B_CTL);
            if(buf != val) {
                if(extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_RELAY_AC2, &val) == ESP_OK) {

                }
            }
        }
        if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_RELAY_AC1, &buf) == ESP_OK) {
            val = get_pwr_state(POWER_A_CTL);
            if(buf != val) {
                if(extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_RELAY_AC1, &val) == ESP_OK) {

                }
            }
        }

        if(get_is_update_time_flag()) {
            set_is_update_time_flag(0);
            time = get_rtc_time();
            tm_time = localtime(&time);
            val = tm_time->tm_hour;
            extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_HOUR, &val);
            val = tm_time->tm_min;
            extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_MINUTE, &val);
            val = tm_time->tm_sec;
            extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_SECOND, &val);
            val = tm_time->tm_year - 100;
            extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_YEAR, &val);
            val = tm_time->tm_mon + 1;
            extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_MONTH, &val);
            val = tm_time->tm_mday;;
            extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_DATE, &val);
            val = tm_time->tm_wday;
            extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_WEEKDAY, &val);
            ESP_LOGI(TAG, "time:20%02d-%02d-%02d %02d:%02d:%02d", tm_time->tm_year - 100, 
                                                                tm_time->tm_mon + 1, 
                                                                tm_time->tm_mday, 
                                                                tm_time->tm_hour, 
                                                                tm_time->tm_min, 
                                                                tm_time->tm_sec);
        }


        /** ID */
        device_get_terminal_id(&p_id, &t_id);
        if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_DEVICE_ID0, &buf) == ESP_OK) {
            val = t_id;
            if(buf != val) {
                if(extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_DEVICE_ID0, &val) == ESP_OK) {

                }
            }
        }
        if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_DEVICE_ID1, &buf) == ESP_OK) {
            val = t_id >> 8;
            if(buf != val) {
                if(extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_DEVICE_ID1, &val) == ESP_OK) {

                }
            }
        }

        /** 当前ip */
        if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_IP_ADDR0, &buf) == ESP_OK) {
            val = (user_configuration.cur_ip_addr & 0xFF);
            if(buf != val) {
                extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_IP_ADDR0, &val);
            }
        }
        if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_IP_ADDR1, &buf) == ESP_OK) {
            val = (user_configuration.cur_ip_addr >> 8) & 0xFF;
            if(buf != val) {
                extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_IP_ADDR1, &val);
            }
        }
        if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_IP_ADDR2, &buf) == ESP_OK) {
            val = (user_configuration.cur_ip_addr >> 16) & 0xFF;            
            if(buf != val) {
                extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_IP_ADDR2, &val);
            }
        }
        if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_IP_ADDR3, &buf) == ESP_OK) {
            val = (user_configuration.cur_ip_addr >> 24) & 0xFF;
            if(buf != val) {
                extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_IP_ADDR3, &val);
            }
        }

        /** 服务器ip */
        if(get_addrs_from_list(ADDR_OCA_ADDR_LIST, (uint32_t *)&id, 1) > 0) {
            struct client_conn * conn;
            conn = find_client_conn(id);
            if(conn) {
                addr = conn->ip;
            } else {
                addr = 0;
            }
            if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_SERVERIP_ADDR0, &buf) == ESP_OK) {
                val = (addr & 0xFF);
                if(buf != val) {
                    extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_SERVERIP_ADDR0, &val);
                }
            }
            if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_SERVERIP_ADDR1, &buf) == ESP_OK) {
                val = (addr >> 8) & 0xFF;
                if(buf != val) {
                    extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_SERVERIP_ADDR1, &val);
                }
            }
            if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_SERVERIP_ADDR2, &buf) == ESP_OK) {
                val = (addr >> 16) & 0xFF;         
                if(buf != val) {
                    extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_SERVERIP_ADDR2, &val);
                }
            }
            if(extend_mcu_read_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_SERVERIP_ADDR3, &buf) == ESP_OK) {
                val = (addr >> 24) & 0xFF;
                if(buf != val) {
                    extend_mcu_write_reg(I2C_ADDR_EXTEND_MCU, REG_ADDR_SERVERIP_ADDR3, &val);
                }
            }
        }
        vTaskDelay(pdMS_TO_TICKS(200));
    }
}



@github-actions github-actions bot changed the title ESP32 I2C主机模式是否在I2C总线出问题时会导致程序崩溃? ESP32 I2C主机模式是否在I2C总线出问题时会导致程序崩溃? (AUD-5760) Oct 12, 2024
@theGuen
Copy link

theGuen commented Nov 7, 2024

How did you solve this?

i get no connection on the i2c on a Audio-dev kit

log is like

9:21:02.776 -> �[0;32mI (461) cpu_start: cpu freq: 160000000 Hz�[0m
09:21:02.776 -> �[0;32mI (461) app_init: Application information:�[0m
09:21:02.776 -> �[0;32mI (464) app_init: Project name:     play_bt_music�[0m
09:21:02.776 -> �[0;32mI (469) app_init: App version:      v2.7-18-gff7f39dc-dirty�[0m
09:21:02.776 -> �[0;32mI (476) app_init: Compile time:     Nov  7 2024 09:02:02�[0m
09:21:02.776 -> �[0;32mI (482) app_init: ELF file SHA256:  37f125b9e...�[0m
09:21:02.776 -> �[0;32mI (487) app_init: ESP-IDF:          v5.3.1-dirty�[0m
09:21:02.776 -> �[0;32mI (492) efuse_init: Min chip rev:     v0.0�[0m
09:21:02.776 -> �[0;32mI (497) efuse_init: Max chip rev:     v3.99 �[0m
09:21:02.776 -> �[0;32mI (502) efuse_init: Chip rev:         v3.0�[0m
09:21:02.776 -> �[0;32mI (507) heap_init: Initializing. RAM available for dynamic allocation:�[0m
09:21:02.776 -> �[0;32mI (514) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM�[0m
09:21:02.776 -> �[0;32mI (520) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM�[0m
09:21:02.776 -> �[0;32mI (526) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM�[0m
09:21:02.776 -> �[0;32mI (532) heap_init: At 3FFCC670 len 00013990 (78 KiB): DRAM�[0m
09:21:02.776 -> �[0;32mI (538) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM�[0m
09:21:02.776 -> �[0;32mI (545) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM�[0m
09:21:02.776 -> �[0;32mI (551) heap_init: At 4009BAF4 len 0000450C (17 KiB): IRAM�[0m
09:21:02.776 -> �[0;32mI (559) spi_flash: detected chip: generic�[0m
09:21:02.776 -> �[0;32mI (562) spi_flash: flash io: dio�[0m
09:21:02.776 -> �[0;33mW (566) spi_flash: Detected size(8192k) larger than the size in the binary image header(4096k). Using the size in the binary image header.�[0m
09:21:02.776 -> �[0;32mI (580) coexist: coex firmware version: 4482466�[0m
09:21:02.776 -> �[0;32mI (585) main_task: Started on CPU0�[0m
09:21:02.776 -> �[0;32mI (595) main_task: Calling app_main()�[0m
09:21:02.776 -> �[0;32mI (595) BLUETOOTH_EXAMPLE: [ 1 ] Create Bluetooth service�[0m
09:21:02.776 -> �[0;32mI (595) BTDM_INIT: BT controller compile version [b022216]�[0m
09:21:02.776 -> �[0;32mI (605) BTDM_INIT: Bluetooth MAC: 78:21:84:d3:be:b2�[0m
09:21:02.776 -> �[0;32mI (605) phy_init: phy_version 4830,54550f7,Jun 20 2024,14:22:08�[0m
09:21:03.288 -> �[0;33mW (1265) BT_BTC: btc_avrc_tg_set_rn_supported_evt failed: AVRC TG not yet initialized
09:21:03.319 -> �[0m
09:21:03.319 -> �[0;33mW (1275) BT_BTC: A2DP Enable with AVRC�[0m
09:21:03.319 -> �[0;32mI (1285) BLUETOOTH_EXAMPLE: [ 2 ] Start codec chip�[0m
09:21:03.319 -> �[0;32mI (1285) gpio: GPIO[19]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:3 �[0m
09:21:03.319 -> �[0;33mW (1295) i2c_bus_v2: I2C master handle is NULL, will create new one�[0m
09:21:03.352 -> D (1295) i2c.common: new bus(0) at 0x3ffd6970�[0m
09:21:03.352 -> �[0;32mI (1305) gpio: GPIO[33]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0 �[0m
09:21:03.352 -> �[0;32mI (1315) gpio: GPIO[32]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0 �[0m
09:21:03.352 -> D (1315) i2c.common: bus clock source frequency: 80000000hz�[0m
09:21:03.352 -> �[0;32mI (1325) gpio: GPIO[33]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0 �[0m
09:21:03.385 -> �[0;32mI (1335) gpio: GPIO[32]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0 �[0m
09:21:03.580 -> �[0;31mE (1545) i2c.master: I2C software timeout�[0m
09:21:03.580 -> �[0;31mE (1545) i2c.master: s_i2c_synchronous_transaction(872): I2C transaction failed�[0m

@SantaPasserby
Copy link
Author

@theGuen
ADF-V2.7 uses i2c_bus_v2.c, which is the V2 version. I used ADF-V2.6 with i2c_bus.c before, and the product has always been stable and has not caused any problems.
Later I verified that i2c_buf_v2.c would access the null pointer, but I didn't have time to find out what the problem was.

So I modified the CMakeLists.txt file to force the use of i2c_bus.c instead of i2c_bus_v2.c. The location I modified is ${ADF_PATH}/components/esp_peripherals/CMakeLists.txt.

# if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_LESS "5.3")
    list(APPEND COMPONENT_SRCS  ./driver/i2c_bus/i2c_bus.c)
# else()
#     list(APPEND COMPONENT_SRCS  ./driver/i2c_bus/i2c_bus_v2.c)
# endif()

2131313

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants