PSRAM problem while frame buffer init?

salbdch
Posts: 17
Joined: Wed Dec 02, 2020 2:06 pm

PSRAM problem while frame buffer init?

Postby salbdch » Fri Jan 15, 2021 12:24 pm

System keep rebooting while frame buffer init and here's log while.
I have no idea why free space on PSRAM shows abnomal values after allocating 960kBytes.

Code: Select all

I (2556) camera: Detected OV5640 camera
E (2556) camera: in_bpp: 2, fb_bpp: 2, fb_size: 983040, mode: 3, width: 2560 height: 1920
I (2556) camera: [DEBUG] Frame Buffer(2) Init...in Camera.c
I (2556) camera: ********* PSRAM CHECK(2) *********
I (2566) camera: heap_caps_get_total_size(MALLOC_CAP_SPIRAM) = 4194303
I (2576) camera: heap_caps_get_free_size(MALLOC_CAP_SPIRAM) = 4194264
I (2576) camera: heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM) = 4194264
I (2586) camera: heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM) = 4194264
I (2596) camera: *************************************
I (2606) camera: Allocating 960 KB frame buffer in PSRAM
I (2606) camera: ********* PSRAM CHECK(3) *********
I (2616) camera: heap_caps_get_total_size(MALLOC_CAP_SPIRAM) = 4194303
I (2616) camera: heap_caps_get_free_size(MALLOC_CAP_SPIRAM) = 4194264
I (2626) camera: heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM) = 4194264
I (2636) camera: heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM) = 4194264
I (2646) camera: *************************************
E (2776) camera: [DEBUG]Allocating 960 KB frame buffer in PSRAM Success
I (2776) camera: ********* PSRAM CHECK(4) *********
I (2776) camera: heap_caps_get_total_size(MALLOC_CAP_SPIRAM) = 4194303
I (2786) camera: heap_caps_get_free_size(MALLOC_CAP_SPIRAM) = -24831
I (2796) camera: heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM) = -1
assertion "next > (intptr_t)block" failed: file "D:/esp-idf-v4.1/components/heap/multi_heap.c", line 131, function: get_next_block
abort() was called at PC 0x401518b0 on core 0

ELF file SHA256: 4646feaf3aec573f

Backtrace: 0x4008c165:0x3ffbffa0 0x4008c501:0x3ffbffc0 0x401518b0:0x3ffbffe0 0x4009196a:0x3ffc0010 0x400d69e6:0x3ffc0030 0x400d6a45:0x3ffc0070 0x400e2197:0x3ffc00b0 0x400e2257:0x3ffc00d0 0x400e2ab7:0x3ffc0100 0x400e2e31:0x3ffc0140 0x400d94fd:0x3ffc0170 0x400d9052:0x3ffc0220 0x400d31c0:0x3ffc0240 0x4008d83d:0x3ffc0260

Rebooting...
ets Jul 29 2019 12:21:46
Code

Code: Select all

static void psram_check(uint8_t location)
{
    ESP_LOGI(TAG, "********* PSRAM CHECK(%d) *********", location);
	ESP_LOGI(TAG, "heap_caps_get_total_size(MALLOC_CAP_SPIRAM) = %d", heap_caps_get_total_size(MALLOC_CAP_SPIRAM) );
	ESP_LOGI(TAG, "heap_caps_get_free_size(MALLOC_CAP_SPIRAM) = %d", heap_caps_get_free_size(MALLOC_CAP_SPIRAM) );
	ESP_LOGI(TAG, "heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM) = %d", heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM) );
	ESP_LOGI(TAG, "heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM) = %d", heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM) );
    ESP_LOGI(TAG, "*************************************");	
}

static esp_err_t camera_fb_init(size_t count)
{
    if(!count) {
        return ESP_ERR_INVALID_ARG;
    }

    camera_fb_deinit();

    psram_check(2);

    camera_fb_int_t * _fb = NULL, * _fb1 = NULL, * _fb2 = NULL;
    for(size_t i = 0; i < count; i++) {   	
        _fb2 = (camera_fb_int_t *)malloc(sizeof(camera_fb_int_t));
        if(!_fb2) {
            goto fail;
        }
        memset(_fb2, 0, sizeof(camera_fb_int_t));
        _fb2->size = s_state->fb_size;
        _fb2->buf = (uint8_t*) calloc(_fb2->size, 1);
   
        if(!_fb2->buf) {
            ESP_LOGI(TAG, "Allocating %d KB frame buffer in PSRAM", s_state->fb_size/1024);
			psram_check(3);
            _fb2->buf = (uint8_t*) heap_caps_calloc(_fb2->size, 1, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
            ESP_LOGE(TAG, "[DEBUG]Allocating %d KB frame buffer in PSRAM Success", s_state->fb_size/1024);
            psram_check(4);
            
        } else {
            ESP_LOGI(TAG, "Allocating %d KB frame buffer in OnBoard RAM", s_state->fb_size/1024);
        }
        if(!_fb2->buf) {
            free(_fb2);
            ESP_LOGE(TAG, "Allocating %d KB frame buffer Failed", s_state->fb_size/1024);
            goto fail;
        }
        memset(_fb2->buf, 0, _fb2->size);
        _fb2->next = _fb;
        _fb = _fb2;
        if(!i) {
            _fb1 = _fb2;
        }
    }
    if(_fb1) {
        _fb1->next = _fb;
    }

    s_state->fb = _fb;//load first buffer

    return ESP_OK;

fail:
    while(_fb) {
        _fb2 = _fb;
        _fb = _fb->next;
        free(_fb2->buf);
        free(_fb2);
    }
    return ESP_ERR_NO_MEM;
}

salbdch
Posts: 17
Joined: Wed Dec 02, 2020 2:06 pm

Re: PSRAM problem while frame buffer init?

Postby salbdch » Mon Jan 18, 2021 8:32 am

Case closed,

Was not exactly the PSRAM issue.
Please refer https://www.esp32.com/viewtopic.php?f=13&t=18950 if may someone interested.

Regards,

Who is online

Users browsing this forum: No registered users and 10 guests