espressif / esp-who

Face detection and recognition framework
Other
1.64k stars 458 forks source link

Init PSRAM manually trowing failed to allocate frame buffers. (AIV-564) #235

Closed nikhil-robinson closed 1 year ago

nikhil-robinson commented 1 year ago

Hello there is it possible to initialize the psram manually and use it with who examples ? i am trying to initialize psram after boot up but camera frame failed to allocate. I haveesp32s3 with 8 mb OCTAL psram.

Example code.

#include "who_camera.h"
#include "who_human_face_detection.hpp"
#include "who_lcd.h"
#include <esp_spiram.h>
#include <esp_himem.h>

static QueueHandle_t xQueueAIFrame = NULL;
static QueueHandle_t xQueueLCDFrame = NULL;

extern "C" void app_main(void)
{

    esp_spiram_init();

    xQueueAIFrame = xQueueCreate(2, sizeof(camera_fb_t *));
    xQueueLCDFrame = xQueueCreate(2, sizeof(camera_fb_t *));

    register_camera(PIXFORMAT_RGB565, FRAMESIZE_240X240, 2, xQueueAIFrame);
    register_human_face_detection(xQueueAIFrame, NULL, NULL, xQueueLCDFrame, false);
    register_pc_lcd(xQueueLCDFrame, NULL, true);

}

Debug log:

SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x1670
load:0x403c9700,len:0xbb0
load:0x403cc700,len:0x2f0c
entry 0x403c9950
I (24) boot: ESP-IDF v4.4.3-173-g1f63dc70b8 2nd stage bootloader
I (25) boot: compile time 19:11:07
I (25) boot: chip revision: 0
I (28) boot.esp32s3: Boot SPI Speed : 80MHz
I (32) boot.esp32s3: SPI Mode       : DIO
I (37) boot.esp32s3: SPI Flash Size : 8MB
I (42) boot: Enabling RNG early entropy source...
I (47) boot: Partition Table:
I (51) boot: ## Label            Usage          Type ST Offset   Length
I (58) boot:  0 factory          factory app      00 00 00010000 003c0000
I (66) boot:  1 nvs              WiFi data        01 02 003d0000 00004000
I (73) boot:  2 fr               Unknown data     01 06 003e0000 00020000
I (81) boot: End of partition table
I (85) esp_image: segment 0: paddr=00010020 vaddr=3c090020 size=62450h (402512) map
I (165) esp_image: segment 1: paddr=00072478 vaddr=3fc96190 size=03fd4h ( 16340) load
I (169) esp_image: segment 2: paddr=00076454 vaddr=40374000 size=09bc4h ( 39876) load
I (180) esp_image: segment 3: paddr=00080020 vaddr=42000020 size=80db0h (527792) map
I (276) esp_image: segment 4: paddr=00100dd8 vaddr=4037dbc4 size=085cch ( 34252) load
I (291) boot: Loaded app from partition at offset 0x10000
I (292) boot: Disabling RNG early entropy source...
I (303) cpu_start: Pro cpu up.
I (303) cpu_start: Starting app cpu, entry point is 0x4037560c
0x4037560c: call_start_cpu1 at /home/nikhil/esp/esp-idf/components/esp_system/port/cpu_start.c:148

I (0) cpu_start: App cpu up.
I (317) cpu_start: Pro cpu start user code
I (317) cpu_start: cpu freq: 240000000
I (317) cpu_start: Application information:
I (320) cpu_start: Project name:     play_sdcard_music
I (325) cpu_start: App version:      570643d-dirty
I (331) cpu_start: Compile time:     Nov 29 2022 19:11:06
I (337) cpu_start: ELF file SHA256:  baa9984270662418...
I (343) cpu_start: ESP-IDF:          v4.4.3-173-g1f63dc70b8
I (349) heap_init: Initializing. RAM available for dynamic allocation:
I (356) heap_init: At 3FC9D348 len 0004C3C8 (304 KiB): D/IRAM
I (363) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (370) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (376) heap_init: At 600FE000 len 00002000 (8 KiB): RTCRAM
I (383) spi_flash: detected chip: generic
I (387) spi_flash: flash io: dio
I (395) sleep: Configure to isolate all GPIO pins in sleep state
I (397) sleep: Enable automatic switching of GPIO sleep configuration
I (405) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (415) spiram: Reserving pool of 32K of internal memory for DMA/internal allocations
I (425) opi psram: vendor id : 0x0d (AP)
I (435) opi psram: dev id    : 0x02 (generation 3)
I (435) opi psram: density   : 0x03 (64 Mbit)
I (445) opi psram: good-die  : 0x01 (Pass)
I (445) opi psram: Latency   : 0x01 (Fixed)
I (455) opi psram: VCC       : 0x01 (3V)
I (455) opi psram: SRF       : 0x01 (Fast Refresh)
I (465) opi psram: BurstType : 0x01 (Hybrid Wrap)
I (465) opi psram: BurstLen  : 0x01 (32 Byte)
I (475) opi psram: Readlatency  : 0x02 (10 cycles@Fixed)
I (475) opi psram: DriveStrength: 0x00 (1/1)
W (485) PSRAM: DO NOT USE FOR MASS PRODUCTION! Timing parameters will be updated in future IDF version.
I (495) spiram: Found 64MBit SPI RAM device
I (495) spiram: SPI RAM mode: sram 80m
I (505) spiram: PSRAM initialized, cache is in normal (1-core) mode.
I (515) who_camera: Camera module is ESP-S3-EYE
I (515) s3 ll_cam: DMA Channel=4
I (525) cam_hal: cam init ok
I (525) sccb: pin_sda 4 pin_scl 5
I (535) camera: Detected camera at address=0x30
I (535) camera: Detected OV2640 camera
I (535) camera: Camera PID=0x26 VER=0x42 MIDL=0x7f MIDH=0xa2
I (615) s3 ll_cam: node_size: 3840, nodes_per_line: 1, lines_per_node: 8
I (615) s3 ll_cam: dma_half_buffer_min:  3840, dma_half_buffer: 11520, lines_per_half_buffer: 24, dma_buffer_size: 23040
I (625) cam_hal: buffer_size: 23040, half_buffer_size: 11520, node_buffer_size: 3840, node_cnt: 6, total_cnt: 10
I (635) cam_hal: Allocating 115200 Byte frame buffer in PSRAM
E (645) cam_hal: cam_dma_config(292): frame buffer malloc failed
E (645) cam_hal: cam_config(376): cam_dma_config failed
E (655) camera: Camera config failed with error 0xffffffff
E (665) who_camera: Camera init failed with error 0xffffffff
Sandra-lol commented 1 year ago

Hi, it seems more like a psram initialization issue, better to create an issue in IDF repo and discuss there)

nikhil-robinson commented 1 year ago

I was able to fix the above issue with enabling esp_spiram_add_to_heapalloc(); but now i am getting some other issues.

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0x38 (SPI_FAST_FLASH_BOOT)
Saved PC:0x403758e6
0x403758e6: xt_highint4 at /home/nikhil/esp/esp-idf/components/esp_system/port/soc/esp32s3/highint_hdl.S:57

SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x1670
load:0x403c9700,len:0xbb0
load:0x403cc700,len:0x2f0c
entry 0x403c9950
I (24) boot: ESP-IDF v4.4.3-173-g1f63dc70b8 2nd stage bootloader
I (25) boot: compile time 15:38:51
I (25) boot: chip revision: 0
I (28) boot.esp32s3: Boot SPI Speed : 80MHz
I (32) boot.esp32s3: SPI Mode       : DIO
I (37) boot.esp32s3: SPI Flash Size : 8MB
I (42) boot: Enabling RNG early entropy source...
I (47) boot: Partition Table:
I (51) boot: ## Label            Usage          Type ST Offset   Length
I (58) boot:  0 factory          factory app      00 00 00010000 003c0000
I (66) boot:  1 nvs              WiFi data        01 02 003d0000 00004000
I (73) boot:  2 fr               Unknown data     01 06 003e0000 00020000
I (81) boot: End of partition table
I (85) esp_image: segment 0: paddr=00010020 vaddr=3c0a0020 size=6b078h (438392) map
I (172) esp_image: segment 1: paddr=0007b0a0 vaddr=3fc96da0 size=0401ch ( 16412) load
I (176) esp_image: segment 2: paddr=0007f0c4 vaddr=40374000 size=00f54h (  3924) load
I (178) esp_image: segment 3: paddr=00080020 vaddr=42000020 size=98a94h (625300) map
I (298) esp_image: segment 4: paddr=00118abc vaddr=40374f54 size=11e40h ( 73280) load
I (322) boot: Loaded app from partition at offset 0x10000
I (323) boot: Disabling RNG early entropy source...
I (334) cpu_start: Pro cpu up.
I (334) cpu_start: Starting app cpu, entry point is 0x40375674
0x40375674: call_start_cpu1 at /home/nikhil/esp/esp-idf/components/esp_system/port/cpu_start.c:148

I (0) cpu_start: App cpu up.
I (348) cpu_start: Pro cpu start user code
I (348) cpu_start: cpu freq: 160000000
I (348) cpu_start: Application information:
I (351) cpu_start: Project name:     play_sdcard_music
I (357) cpu_start: App version:      f82540e-dirty
I (362) cpu_start: Compile time:     Dec  1 2022 12:03:03
I (368) cpu_start: ELF file SHA256:  46f00cf88739d58c...
I (374) cpu_start: ESP-IDF:          v4.4.3-173-g1f63dc70b8
I (380) heap_init: Initializing. RAM available for dynamic allocation:
I (388) heap_init: At 3FC9E070 len 0004B6A0 (301 KiB): D/IRAM
I (394) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (401) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (407) heap_init: At 600FE000 len 00002000 (8 KiB): RTCRAM
I (414) spi_flash: detected chip: generic
I (418) spi_flash: flash io: dio
I (428) sleep: Configure to isolate all GPIO pins in sleep state
I (429) sleep: Enable automatic switching of GPIO sleep configuration
I (436) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (446) spiram: Reserving pool of 32K of internal memory for DMA/internal allocations
I (456) opi psram: vendor id : 0x0d (AP)
I (466) opi psram: dev id    : 0x02 (generation 3)
I (466) opi psram: density   : 0x03 (64 Mbit)
I (476) opi psram: good-die  : 0x01 (Pass)
I (476) opi psram: Latency   : 0x01 (Fixed)
I (486) opi psram: VCC       : 0x01 (3V)
I (486) opi psram: SRF       : 0x01 (Fast Refresh)
I (496) opi psram: BurstType : 0x01 (Hybrid Wrap)
I (496) opi psram: BurstLen  : 0x01 (32 Byte)
I (506) opi psram: Readlatency  : 0x02 (10 cycles@Fixed)
I (506) opi psram: DriveStrength: 0x00 (1/1)
W (516) PSRAM: DO NOT USE FOR MASS PRODUCTION! Timing parameters will be updated in future IDF version.
I (526) spiram: Found 64MBit SPI RAM device
I (526) spiram: SPI RAM mode: sram 80m
I (536) spiram: PSRAM initialized, cache is in normal (1-core) mode.
I (546) spiram: Adding pool of 8192K of external SPI memory to heap allocator
I (546) PC_STORAGE: Initializing SD card
I (556) PC_STORAGE: Using SDMMC peripheral
I (556) PC_STORAGE: Mounting filesystem
I (566) gpio: GPIO[39]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (576) gpio: GPIO[38]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (586) gpio: GPIO[40]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (626) PC_STORAGE: Filesystem mounted
Name: 8310 
Type: SDSC
Speed: 20 MHz
Size: 481MB
I (636) PLAY_SDCARD_MUSIC: [ 1 ] Mount sdcard
I (636) PLAY_SDCARD_MUSIC: [ 2 ] Start codec chip
I (636) new_codec: new_codec init
I (646) AUDIO_HAL: Codec mode is 2, Ctrl:1
I (646) PLAY_SDCARD_MUSIC: [3.0] Create audio pipeline for playback
I (656) PLAY_SDCARD_MUSIC: [3.1] Create fatfs stream to read data from sdcard
I (666) PLAY_SDCARD_MUSIC: [3.2] Create i2s stream to write data to codec chip
W (666) I2S: APLL not supported on current chip, use I2S_CLK_D2CLK as default clock source
I (686) I2S: DMA Malloc info, datalen=blocksize=1200, dma_buf_count=3
I (686) I2S: DMA Malloc info, datalen=blocksize=1200, dma_buf_count=3
I (696) MY_BOARD_V1_0: I2S0, MCLK output by GPIO0
I (696) PLAY_SDCARD_MUSIC: [3.3] Create mp3 decoder
I (706) MP3_DECODER: MP3 init
I (706) PLAY_SDCARD_MUSIC: [3.4] Register all elements to audio pipeline
I (716) PLAY_SDCARD_MUSIC: [3.5] Link it together [sdcard]-->fatfs_stream-->music_decoder-->i2s_stream-->[codec_chip]
I (726) AUDIO_PIPELINE: link el->rb, el:0x3fceaad8, tag:file, rb:0x3fceb824
I (736) AUDIO_PIPELINE: link el->rb, el:0x3fceb494, tag:dec, rb:0x3fced96c
I (746) PLAY_SDCARD_MUSIC: [ 4 ] Set up  event listener
I (746) PLAY_SDCARD_MUSIC: [4.1] Listening event from all elements of pipeline
I (756) PLAY_SDCARD_MUSIC: [4.2] Listening event from peripherals
I (766) who_camera: Camera module is ESP-S3-EYE
I (766) s3 ll_cam: DMA Channel=4
I (766) cam_hal: cam init ok
I (776) sccb: pin_sda 4 pin_scl 5
I (786) camera: Detected camera at address=0x30
I (786) camera: Detected OV2640 camera
I (786) camera: Camera PID=0x26 VER=0x42 MIDL=0x7f MIDH=0xa2
I (876) s3 ll_cam: node_size: 3840, nodes_per_line: 1, lines_per_node: 8
I (876) s3 ll_cam: dma_half_buffer_min:  3840, dma_half_buffer: 11520, lines_per_half_buffer: 24, dma_buffer_size: 23040
I (886) cam_hal: buffer_size: 23040, Y half_buffer_size: 11520, node_buffer_size: 3840, node_cnt: 6, total_cnt: 10
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x8 (TG1WDT_SYS_RST),boot:0x38 (SPI_FAST_FLASH_BOOT)
Saved PC:0x403758e6
0x403758e6: xt_highint4 at /home/nikhil/esp/esp-idf/components/esp_system/port/soc/esp32s3/highint_hdl.S:57

SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x1670
load:0x403c9700,len:0xbb0
load:0x403cc700,len:0x2f0c
entry 0x403c9950
I (24) boot: ESP-IDF v4.4.3-173-g1f63dc70b8 2nd stage bootloader
I (24) boot: compile time 15:38:51
I (25) boot: chip revision: 0
I (27) boot.esp32s3: Boot SPI Speed : 80MHz
I (32) boot.esp32s3: SPI Mode       : DIO
I (37) boot.esp32s3: SPI Flash Size : 8MB
W (41) boot.esp32s3: PRO CPU has been reset by WDT.
W (47) boot.esp32s3: APP CPU has been reset by WDT.
I (52) boot: Enabling RNG early entropy source...
I (58) boot: Partition Table:
I (61) boot: ## Label            Usage          Type ST Offset   Length
I (69) boot:  0 factory          factory app      00 00 00010000 003c0000
I (76) boot:  1 nvs              WiFi data        01 02 003d0000 00004000
I (84) boot:  2 fr               Unknown data     01 06 003e0000 00020000
I (91) boot: End of partition table
I (95) esp_image: segment 0: paddr=00010020 vaddr=3c0a0020 size=6b078h (438392) map
I (182) esp_image: segment 1: paddr=0007b0a0 vaddr=3fc96da0 size=0401ch ( 16412) load
I (187) esp_image: segment 2: paddr=0007f0c4 vaddr=40374000 size=00f54h (  3924) load
I (189) esp_image: segment 3: paddr=00080020 vaddr=42000020 size=98a94h (625300) map
I (309) esp_image: segment 4: paddr=00118abc vaddr=40374f54 size=11e40h ( 73280) load
I (333) boot: Loaded app from partition at offset 0x10000
I (333) boot: Disabling RNG early entropy source...
I (344) cpu_start: Pro cpu up.
I (344) cpu_start: Starting app cpu, entry point is 0x40375674
0x40375674: call_start_cpu1 at /home/nikhil/esp/esp-idf/components/esp_system/port/cpu_start.c:148

I (0) cpu_start: App cpu up.
I (358) cpu_start: Pro cpu start user code
I (359) cpu_start: cpu freq: 160000000
I (359) cpu_start: Application information:
I (361) cpu_start: Project name:     play_sdcard_music
I (367) cpu_start: App version:      f82540e-dirty
I (373) cpu_start: Compile time:     Dec  1 2022 12:03:03
I (379) cpu_start: ELF file SHA256:  46f00cf88739d58c...
I (385) cpu_start: ESP-IDF:          v4.4.3-173-g1f63dc70b8
I (391) heap_init: Initializing. RAM available for dynamic allocation:
I (398) heap_init: At 3FC9E070 len 0004B6A0 (301 KiB): D/IRAM
I (404) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (411) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (417) heap_init: At 600FE000 len 00002000 (8 KiB): RTCRAM
I (424) spi_flash: detected chip: generic
I (428) spi_flash: flash io: dio
I (438) sleep: Configure to isolate all GPIO pins in sleep state
I (439) sleep: Enable automatic switching of GPIO sleep configuration
I (446) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (457) spiram: Reserving pool of 32K of internal memory for DMA/internal allocations
I (467) opi psram: vendor id : 0x0d (AP)
I (477) opi psram: dev id    : 0x02 (generation 3)
I (477) opi psram: density   : 0x03 (64 Mbit)
I (487) opi psram: good-die  : 0x01 (Pass)
I (487) opi psram: Latency   : 0x01 (Fixed)
I (497) opi psram: VCC       : 0x01 (3V)
I (497) opi psram: SRF       : 0x01 (Fast Refresh)
I (507) opi psram: BurstType : 0x01 (Hybrid Wrap)
I (507) opi psram: BurstLen  : 0x01 (32 Byte)
I (517) opi psram: Readlatency  : 0x02 (10 cycles@Fixed)
I (517) opi psram: DriveStrength: 0x00 (1/1)
W (527) PSRAM: DO NOT USE FOR MASS PRODUCTION! Timing parameters will be updated in future IDF version.
I (537) spiram: Found 64MBit SPI RAM device
I (537) spiram: SPI RAM mode: sram 80m
I (547) spiram: PSRAM initialized, cache is in normal (1-core) mode.
I (557) spiram: Adding pool of 8192K of external SPI memory to heap allocator
I (557) PC_STORAGE: Initializing SD card
I (567) PC_STORAGE: Using SDMMC peripheral
I (567) PC_STORAGE: Mounting filesystem
I (577) gpio: GPIO[39]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (587) gpio: GPIO[38]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (597) gpio: GPIO[40]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (637) PC_STORAGE: Filesystem mounted
Name: 8310 
Type: SDSC
Speed: 20 MHz
Size: 481MB
I (647) PLAY_SDCARD_MUSIC: [ 1 ] Mount sdcard
I (647) PLAY_SDCARD_MUSIC: [ 2 ] Start codec chip
I (647) new_codec: new_codec init
I (657) AUDIO_HAL: Codec mode is 2, Ctrl:1
I (657) PLAY_SDCARD_MUSIC: [3.0] Create audio pipeline for playback
I (667) PLAY_SDCARD_MUSIC: [3.1] Create fatfs stream to read data from sdcard
I (677) PLAY_SDCARD_MUSIC: [3.2] Create i2s stream to write data to codec chip
W (677) I2S: APLL not supported on current chip, use I2S_CLK_D2CLK as default clock source
I (697) I2S: DMA Malloc info, datalen=blocksize=1200, dma_buf_count=3
I (697) I2S: DMA Malloc info, datalen=blocksize=1200, dma_buf_count=3
I (707) MY_BOARD_V1_0: I2S0, MCLK output by GPIO0
I (707) PLAY_SDCARD_MUSIC: [3.3] Create mp3 decoder
I (717) MP3_DECODER: MP3 init
I (717) PLAY_SDCARD_MUSIC: [3.4] Register all elements to audio pipeline
I (727) PLAY_SDCARD_MUSIC: [3.5] Link it together [sdcard]-->fatfs_stream-->music_decoder-->i2s_stream-->[codec_chip]
I (737) AUDIO_PIPELINE: link el->rb, el:0x3fceaad8, tag:file, rb:0x3fceb824
I (747) AUDIO_PIPELINE: link el->rb, el:0x3fceb494, tag:dec, rb:0x3fced96c
I (757) PLAY_SDCARD_MUSIC: [ 4 ] Set up  event listener
I (757) PLAY_SDCARD_MUSIC: [4.1] Listening event from all elements of pipeline
I (767) PLAY_SDCARD_MUSIC: [4.2] Listening event from peripherals
I (777) who_camera: Camera module is ESP-S3-EYE
I (777) s3 ll_cam: DMA Channel=4
I (777) cam_hal: cam init ok
I (787) sccb: pin_sda 4 pin_scl 5
I (797) camera: Detected camera at address=0x30
I (797) camera: Detected OV2640 camera
I (797) camera: Camera PID=0x26 VER=0x42 MIDL=0x7f MIDH=0xa2
I (887) s3 ll_cam: node_size: 3840, nodes_per_line: 1, lines_per_node: 8
I (887) s3 ll_cam: dma_half_buffer_min:  3840, dma_half_buffer: 11520, lines_per_half_buffer: 24, dma_buffer_size: 23040
I (897) cam_hal: buffer_size: 23040, Y half_buffer_size: 11520, node_buffer_size: 3840, node_cnt: 6, total_cnt: 10
nikhil-robinson commented 1 year ago

What i am trying to achieve is run ADF with esp-who framework with audio playback and stream.