espressif / esp32-camera

Apache License 2.0
1.87k stars 635 forks source link

ESP32-S3-DevKitC-1 interfacing with ov5640. The board keeps rebooting during camera initialisation #389

Closed mohnazemi closed 2 years ago

mohnazemi commented 2 years ago

Hi guys,

I am trying to connect my ESP32-S3-DevKitC-1-N32R8V board and interface it with the OV5640 Camera Board from Waveshare

I am using the latest IDF release version 4.4.1 and the latest version of esp32-camera. One issue is that my dev board has 32MB of FLASH which is not currently supported in IDF 4.4.1. The latest release version only supports up to 16MB of FLASH which I have selected in menuconfig (I get a warning in the debug output regarding this)

I also have enabled the PSRAM to run at 80Mhz via Octal SPI. This is detected as 8MB of PSRAM memory during boot.

During camera initialisation, the Ov5640 camera is detected but then the board reboots after that. I cannot see any errors being thrown. I have seen other examples of people initialising the cameras and they often see RSRAM memory initialisation after camera detection but I do not get there.

Here is the debug output when I run the program:

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x3b (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
Octal Flash Mode Enabled
For OPI Flash, Use Default Flash Boot Mode
mode:SLOW_RD, clock div:1
load:0x3fcd0108,len:0x1650
load:0x403b6000,len:0xb7c
load:0x403ba000,len:0x2f74
entry 0x403b6248
I (32) boot: ESP-IDF v4.4.1-dirty 2nd stage bootloader
I (32) boot: compile time 18:09:51
I (32) boot: chip revision: 0
I (34) boot.esp32s3: Boot SPI Speed : 80MHz
I (39) boot.esp32s3: SPI Mode       : SLOW READ
I (45) boot.esp32s3: SPI Flash Size : 16MB
I (49) boot: Enabling RNG early entropy source...
I (55) boot: Partition Table:
I (58) boot: ## Label            Usage          Type ST Offset   Length
I (66) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (73) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (81) boot:  2 factory          factory app      00 00 00010000 00100000
I (88) boot: End of partition table
I (92) esp_image: segment 0: paddr=00010020 vaddr=3c020020 size=0a4f8h ( 42232) map
I (111) esp_image: segment 1: paddr=0001a520 vaddr=3fc92ed0 size=02e40h ( 11840) load
I (114) esp_image: segment 2: paddr=0001d368 vaddr=40374000 size=02cb0h ( 11440) load
I (121) esp_image: segment 3: paddr=00020020 vaddr=42000020 size=1d3d8h (119768) map
I (154) esp_image: segment 4: paddr=0003d400 vaddr=40376cb0 size=0c21ch ( 49692) load
I (168) esp_image: segment 5: paddr=00049624 vaddr=50000000 size=00010h (    16) load
I (174) boot: Loaded app from partition at offset 0x10000
I (174) boot: Disabling RNG early entropy source...
I (188) opi psram: vendor id : 0x0d (AP)
I (188) opi psram: dev id    : 0x02 (generation 3)
I (189) opi psram: density   : 0x03 (64 Mbit)
I (192) opi psram: good-die  : 0x01 (Pass)
I (197) opi psram: Latency   : 0x01 (Fixed)
I (202) opi psram: VCC       : 0x00 (1.8V)
I (207) opi psram: SRF       : 0x01 (Fast Refresh)
I (212) opi psram: BurstType : 0x01 (Hybrid Wrap)
I (217) opi psram: BurstLen  : 0x01 (32 Byte)
I (222) opi psram: Readlatency  : 0x02 (10 cycles@Fixed)
I (228) opi psram: DriveStrength: 0x00 (1/1)
W (233) PSRAM: DO NOT USE FOR MASS PRODUCTION! Timing parameters will be updated in future IDF version.
I (244) spiram: Found 64MBit SPI RAM device
I (248) spiram: SPI RAM mode: sram 80m
I (253) spiram: PSRAM initialized, cache is in normal (1-core) mode.
I (260) cpu_start: Pro cpu up.
I (264) cpu_start: Starting app cpu, entry point is 0x40375330
0x40375330: call_start_cpu1 at /Users/mo/esp/esp-idf/components/esp_system/port/cpu_start.c:160

I (0) cpu_start: App cpu up.
I (690) spiram: SPI SRAM memory test OK
I (699) cpu_start: Pro cpu start user code
I (699) cpu_start: cpu freq: 240000000
I (699) cpu_start: Application information:
I (702) cpu_start: Project name:     OV5640
I (707) cpu_start: App version:      v4.4.1-dirty
I (712) cpu_start: Compile time:     May  4 2022 18:09:40
I (718) cpu_start: ELF file SHA256:  465d5ddab6ec0022...
I (724) cpu_start: ESP-IDF:          v4.4.1-dirty
I (730) heap_init: Initializing. RAM available for dynamic allocation:
I (737) heap_init: At 3FC96730 len 000498D0 (294 KiB): D/IRAM
I (743) heap_init: At 3FCE0000 len 0000EE34 (59 KiB): STACK/DRAM
I (750) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (756) heap_init: At 600FE000 len 00002000 (8 KiB): RTCRAM
I (762) spiram: Adding pool of 8192K of external SPI memory to heap allocator
I (771) spi_flash: detected chip: mxic
W (775) spi_flash: Detected flash size > 16 MB, but access beyond 16 MB is not supported for this flash model yet.
I (786) spi_flash: flash io: dio
W (790) spi_flash: Detected size(32768k) larger than the size in the binary image header(16384k). Using the size in the binary image header.
I (803) sleep: Configure to isolate all GPIO pins in sleep state
I (810) sleep: Enable automatic switching of GPIO sleep configuration
I (817) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (837) spiram: Reserving pool of 32K of internal memory for DMA/internal allocations
I (837) example:take_picture: OV5640 app running...
I (847) s3 ll_cam: DMA Channel=4
I (847) cam_hal: cam init ok
I (857) sccb: pin_sda 5 pin_scl 41
I (857) gpio: GPIO[8]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (887) gpio: GPIO[2]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (937) camera: Detected camera at address=0x3c
I (937) camera: Detected OV5640 camera
I (937) camera: Camera PID=0x5640 VER=0x00 MIDL=0x00 MIDH=0x00
I (1607) cam_hal: buffer_size: 15360, half_buffer_size: 1024, node_buffer_size: 1024, node_cnt: 15, total_cnt: 15
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x8 (TG1WDT_SYS_RST),boot:0x3b (SPI_FAST_FLASH_BOOT)
Saved PC:0x40375771
0x40375771: panicHandler at /Users/mo/esp/esp-idf/components/esp_system/port/panic_handler.c:213

Does anyone have any idea what may be going wrong here ? Could this be a power issue ? Thanks

me-no-dev commented 2 years ago

Did you also select Flash to be OPI? Your module has OPI both Flash and PSRAM

mohnazemi commented 2 years ago

Yes I tried that before but the program will fail even sooner. I think it fails in cam_init() function in the cam_hal.c If I do not choose OPI, then it seems to fail in cam_dma_config() function which is a bit further down the code path. My suspicion is that heap_caps_calloc() function somehow fails and leads to a reboot but cannot confirm this. There is literally no error message printed. I check out the release/4.4 breach of the IDF where I can select the correct size fro my flash (32MB) in the menuconfig. It makes no difference

mohnazemi commented 2 years ago

I managed to fix this after carefully reading the notes on ESP32-S3:

SPI0/1: GPIO26-32 are usually used for SPI flash and PSRAM and not recommended for other uses. When using Octal Flash or Octal PSRAM or both, GPIO 33 ~ 37 are connected to SPIIO4 ~ SPIIO7 and SPIDQS. Therefore on ESP32-S3R8 / ESP32-S3R8V board GPIO33~37 are also not recommended for other uses.

The dev kit above provides easy access to many of these GPIO pins but clearly, they should not be used for anything while using Octal SPI mode for Flash and PSRAM. So I made sure that none of those pins are being used for interfacing with the camera board. Problem solved.

Thanks @me-no-dev for pointing out the OPI. That gave me the idea to investigate OPI more carefully

piyushy6 commented 2 years ago

I managed to fix this after carefully reading the notes on ESP32-S3:

SPI0/1: GPIO26-32 are usually used for SPI flash and PSRAM and not recommended for other uses. When using Octal Flash or Octal PSRAM or both, GPIO 33 ~ 37 are connected to SPIIO4 ~ SPIIO7 and SPIDQS. Therefore on ESP32-S3R8 / ESP32-S3R8V board GPIO33~37 are also not recommended for other uses.

The dev kit above provides easy access to many of these GPIO pins but clearly, they should not be used for anything while using Octal SPI mode for Flash and PSRAM. So I made sure that none of those pins are being used for interfacing with the camera board. Problem solved.

Thanks @me-no-dev for pointing out the OPI. That gave me the idea to investigate OPI more carefully

Hi, Can you send an image of the connection between ov5640 and ESP32Devkit S3?

mohnazemi commented 2 years ago

@piyushy6 The ov5640 camera needs a few LDOs and components in order to be interfaced with a Microprocessor. That is why I am using OV5640 Camera Board from Waveshare. You can connect the board pins to the GPIO pins on the Dev kit as you wish, except for the ones I mentioned above.

raviibot commented 1 year ago

Hi mohnazemi, can you please share your code, I am trying to interface OV5640 Camera Board with esp32s3devkitC-1, I have pasted the log below it is restarting . I think there is some configuration issue

I (24) boot: ESP-IDF v4.4.3 2nd stage bootloader I (25) boot: compile time 18:01:45 I (25) boot: chip revision: 0 I (26) boot.esp32s3: Boot SPI Speed : 80MHz I (31) boot.esp32s3: SPI Mode : DIO I (36) boot.esp32s3: SPI Flash Size : 2MB I (40) boot: Enabling RNG early entropy source... I (46) boot: Partition Table: I (49) boot: ## Label Usage Type ST Offset Length I (57) boot: 0 nvs WiFi data 01 02 00009000 00006000 I (64) boot: 1 phy_init RF data 01 01 0000f000 00001000 I (72) boot: 2 factory factory app 00 00 00010000 00100000 I (79) boot: End of partition table I (83) esp_image: segment 0: paddr=00010020 vaddr=3c030020 size=0c508h ( 50440) map I (101) esp_image: segment 1: paddr=0001c530 vaddr=3fc93310 size=03ae8h ( 15080) load I (104) esp_image: segment 2: paddr=00020020 vaddr=42000020 size=24524h (148772) map I (135) esp_image: segment 3: paddr=0004454c vaddr=3fc96df8 size=00100h ( 256) load I (136) esp_image: segment 4: paddr=00044654 vaddr=40374000 size=0f30ch ( 62220) load I (155) esp_image: segment 5: paddr=00053968 vaddr=50000000 size=00010h ( 16) load I (161) boot: Loaded app from partition at offset 0x10000 I (161) boot: Disabling RNG early entropy source... I (175) opi psram: vendor id : 0x00 (UNKNOWN) I (175) opi psram: dev id : 0x03 (generation 4) I (175) opi psram: density : 0x07 (256 Mbit) I (179) opi psram: good-die : 0x01 (Pass) I (184) opi psram: Latency : 0x01 (Fixed) I (189) opi psram: VCC : 0x01 (3V) I (194) opi psram: SRF : 0x00 (Slow Refresh) I (199) opi psram: BurstType : 0x01 ( Wrap) I (204) opi psram: BurstLen : 0x03 (1024 Byte) I (209) opi psram: Readlatency : 0x07 (20 cycles@Fixed) I (215) opi psram: DriveStrength: 0x03 (1/8) I (220) spiram: Found 256MBit SPI RAM device I (225) spiram: SPI RAM mode: sram 40m I (229) spiram: PSRAM initialized, cache is in normal (1-core) mode. ESP-ROM:esp32s3-20210327 Build:Mar 27 2021 rst:0x10 (RTCWDT_RTC_RST),boot:0x8 (SPI_FAST_FLASH_BOOT) SPIWP:0xee mode:DIO, clock div:1 load:0x3fce3808,len:0x1668 load:0x403c9700,len:0xbb8 load:0x403cc700,len:0x2e8c entry 0x403c9954

raviibot commented 1 year ago

Hi mohnazemi, can you share the configuration you have set in menuconfig settings.

mohnazemi commented 1 year ago

How big are the PSRAM and the Flash on your module ? You can find the relevant module information here: https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html This might not be a coding issue but a hardware/ interfacing issue similar to mine above.

raviibot commented 1 year ago

Hi mohnazemi, I have flashed example camera webserver code(changed gpios wrt to camlcd) from arduino ide with flash settings FlashSize:8MB,PSRAM:QSPIRAM it is working fine, but when tried with idf example with same settings, it is not working.I am not sure about the PSRAM and the Flash size, when I tried ardunio sdk config(mapped to idf sdk config) with edp-idf ,it is not working

log:

SPIWP:0xee mode:DIO, clock div:1 load:0x3fce3808,len:0x3b4 load:0x403c9700,len:0x9bc load:0x403cc700,len:0x27c0 entry 0x403c98c0 I (76) cpu_start: Pro cpu up. I (76) cpu_start: Starting app cpu, entry point is 0x403752f4 0x403752f4: call_start_cpu1 at /home/****88/esp/esp-idf-v4.4.3/components/esp_system/port/cpu_start.c:148

I (59) cpu_start: App cpu up. I (87) cpu_start: Pro cpu start user code I (87) cpu_start: cpu freq: 240000000 I (88) cpu_start: Application information: I (88) cpu_start: Project name: camera I (91) cpu_start: App version: v4.4.3 I (95) cpu_start: Compile time: Dec 3 2022 16:45:33 I (100) cpu_start: ELF file SHA256: 2bd66f31edb08095... I (105) cpu_start: ESP-IDF: v4.4.3 I (109) heap_init: Initializing. RAM available for dynamic allocation: I (115) heap_init: At 3FC94F88 len 00054788 (337 KiB): D/IRAM I (120) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM I (126) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM I (131) heap_init: At 600FE000 len 00001FF0 (7 KiB): RTCRAM I (137) spi_flash: detected chip: generic I (141) spi_flash: flash io: dio I (144) cpu_start: Starting scheduler on PRO CPU. I (0) cpu_start: Starting scheduler on APP CPU. I (156) s3 ll_cam: DMA Channel=4 I (159) cam_hal: cam init ok I (162) sccb: pin_sda 17 pin_scl 18 I (165) sccb: sccb_i2c_port=1

I (178) camera: Detected camera at address=0x30 I (181) camera: Detected OV2640 camera I (181) camera: Camera PID=0x26 VER=0x42 MIDL=0x7f MIDH=0xa2 I (260) cam_hal: buffer_size: 16384, half_buffer_size: 1024, node_buffer_size: 1024, node_cnt: 16, total_cnt: 23 I (260) cam_hal: Allocating 23680 Byte frame buffer in PSRAM E (264) cam_hal: cam_dma_config(306): frame buffer malloc failed E (270) cam_hal: cam_config(390): cam_dma_config failed E (275) camera: Camera config failed with error 0xffffffff E (280) Camera: Camera Init Failed I (283) Camera: Taking picture...

mohnazemi commented 1 year ago

The log clearly tells you that framebuffer allocation failed in the PSRAM. Please check what is written on your module, it will be something like this: ESP32-S3-WROOM-1-N8R2 It is very very important to figure out the size of PSRAM and the Flash on your module to debug this.

robokrishan commented 1 year ago

I had the same issue with an ESP32-S3-WROOM-1-N8R8. The problem was the PSRAM mode. In my case, the 8 MB PSRAM was in Octal mode, which was using 3 pins that I had used for the OV5640 data lines. When I disabled support for external PSRAM in menuconfig, the crashing stopped. Of course this may limit you in terms of the image resolution that you will be able to work with.