abort (at locks.c:81) while create mutex during i2c implement

trustmiao
Posts: 43
Joined: Mon Aug 06, 2018 5:16 am

abort (at locks.c:81) while create mutex during i2c implement

Postby trustmiao » Thu May 09, 2019 8:37 am

while we test basic i2c functions, esp32 reset around every 7000 loops. back trace point to

Code: Select all

 xSemaphoreHandle new_sem = xQueueCreateMutex(mutex_type);
        if (!new_sem) {
            abort(); /* No more semaphores available or OOM */
        }

in locks.c

here is the code, very basic i2c functions:

Code: Select all

#include <stdio.h>
#include "driver/i2c.h"
#include "sdkconfig.h"

uint8_t _i2cAddr = 0x4B;
//uint8_t _i2cAddr = 0x58;
#define ACK_EN 0x01
#define DEFAULT_UART_TIMEOUT_MS 100

void app_main()
{
   
    i2c_config_t conf;
    conf.mode = I2C_MODE_MASTER;
    conf.sda_io_num = 22;
    conf.scl_io_num = 21;
    conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
    conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
    conf.master.clk_speed = 100000; 
    i2c_param_config(I2C_NUM_0, &conf);
    i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);


    uint8_t buffer[4];
    esp_err_t errx;
    while (1)
    {
        i2c_cmd_handle_t cmd = i2c_cmd_link_create();
        cmd = i2c_cmd_link_create();
        i2c_master_start(cmd);
        i2c_master_write_byte(cmd, (_i2cAddr << 1) | I2C_MASTER_READ, ACK_EN);
        i2c_master_read(cmd, buffer, 4, (i2c_ack_type_t)0x02);
        i2c_master_stop(cmd);
       
        for (int round = 1; round <= 64; round++)
        {
            errx = i2c_master_cmd_begin(I2C_NUM_0, cmd, DEFAULT_UART_TIMEOUT_MS / portTICK_PERIOD_MS);
            if (errx == ESP_OK)
            {
                break;
            }
            else if ((errx != ESP_OK) && (round < 64))
            {
                continue;
            }
            else
            {
                i2c_cmd_link_delete(cmd);
            }
        }
        
        i2c_cmd_link_delete(cmd);
    }
    vTaskDelete(NULL);
}
here is the back trace

Code: Select all

abort() was called at PC 0x4008271f on core 0
0x4008271f: lock_init_generic at G:/msys32/home/deyeen/esp/esp-idf/components/newlib/locks.c:81


Backtrace: 0x40084dec:0x3ffb47d0 0x40085015:0x3ffb47f0 0x4008271f:0x3ffb4810 0x40082740:0x3ffb4830 0x4008288d:0x3ffb4860 0x400d8b12:0x3ffb4880 0x400dbd6d:0x3ffb4b90 0x40082695:0x3ffb4bc0 0x400e18f7:0x3ffb4c10 0x400e2637:0x
3ffb4c30 0x400d2339:0x3ffb4c70 0x400d0b22:0x3ffb4cb0 0x4008776d:0x3ffb4cd0
0x40084dec: invoke_abort at G:/msys32/home/deyeen/esp/esp-idf/components/esp32/panic.c:707

0x40085015: abort at G:/msys32/home/deyeen/esp/esp-idf/components/esp32/panic.c:707

0x4008271f: lock_init_generic at G:/msys32/home/deyeen/esp/esp-idf/components/newlib/locks.c:81

0x40082740: lock_acquire_generic at G:/msys32/home/deyeen/esp/esp-idf/components/newlib/locks.c:134

0x4008288d: _lock_acquire_recursive at G:/msys32/home/deyeen/esp/esp-idf/components/newlib/locks.c:171

0x400d8b12: _vfprintf_r at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/vfprintf.c:860 (discriminator 2)

0x400dbd6d: vprintf at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/vprintf.c:39

0x40082695: esp_log_write at G:/msys32/home/deyeen/esp/esp-idf/components/log/log.c:215

0x400e18f7: i2c_cmd_link_append at G:/msys32/home/deyeen/esp/esp-idf/components/driver/i2c.c:1036

0x400e2637: i2c_master_stop at G:/msys32/home/deyeen/esp/esp-idf/components/driver/i2c.c:1036

0x400d2339: app_main at G:/esp32_apps/i2c_bno_debug/main/i2c_example_main.c:50

0x400d0b22: main_task at G:/msys32/home/deyeen/esp/esp-idf/components/esp32/cpu_start.c:518

0x4008776d: vPortTaskWrapper at G:/msys32/home/deyeen/esp/esp-idf/components/freertos/port.c:403
We 've also report the issue https://github.com/espressif/esp-idf/issues/3444
Have anyone got good suggestions?

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: abort (at locks.c:81) while create mutex during i2c implement

Postby ESP_Sprite » Fri May 10, 2019 1:56 am

You run i2c_cmd_link_create() 2 times. The result of the 2nd will overwrite the 1st, but not free the memory, so in the long run, you run out of memory.

trustmiao
Posts: 43
Joined: Mon Aug 06, 2018 5:16 am

Re: abort (at locks.c:81) while create mutex during i2c implement

Postby trustmiao » Fri May 10, 2019 8:33 am

thanks alot, problem solved, we should not i2c_cmd_link_create twice.

Who is online

Users browsing this forum: jcolebaker and 164 guests