espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.65k stars 7.41k forks source link

Esp32 Cam Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled. #7534

Closed arslan437 closed 1 year ago

arslan437 commented 1 year ago

Board

Esp32-cam

Device Description

Its esp32 cam board.

Hardware Configuration

Only push button is connected with gpio 0 to put the device in program mode

Version

v2.0.5

IDE Name

Platformio

Operating System

Windows 11

Flash frequency

40MHz

PSRAM enabled

yes

Upload speed

115200

Description

I try to initialize the camera on the esp32 cam but when code reaches the line

esp_err_t err = esp_camera_init(&config);

Esp32 gets restarts.

Sketch

Here are the some parts of the camera related code

void init_cam()
{
    camera_config_t config;
    config.ledc_channel = LEDC_CHANNEL_0;
    config.ledc_timer = LEDC_TIMER_0;
    config.pin_d0 = Y2_GPIO_NUM;
    config.pin_d1 = Y3_GPIO_NUM;
    config.pin_d2 = Y4_GPIO_NUM;
    config.pin_d3 = Y5_GPIO_NUM;
    config.pin_d4 = Y6_GPIO_NUM;
    config.pin_d5 = Y7_GPIO_NUM;
    config.pin_d6 = Y8_GPIO_NUM;
    config.pin_d7 = Y9_GPIO_NUM;
    config.pin_xclk = XCLK_GPIO_NUM;
    config.pin_pclk = PCLK_GPIO_NUM;
    config.pin_vsync = VSYNC_GPIO_NUM;
    config.pin_href = HREF_GPIO_NUM;
    config.pin_sscb_sda = SIOD_GPIO_NUM;
    config.pin_sscb_scl = SIOC_GPIO_NUM;
    config.pin_pwdn = PWDN_GPIO_NUM;
    config.pin_reset = RESET_GPIO_NUM;
    config.xclk_freq_hz = 20000000;
    config.pixel_format = PIXFORMAT_JPEG;

    // init with high specs to pre-allocate larger buffers
    if (psramFound())
    {
        DEBUGLF("PS RAM found");
        config.frame_size = FRAMESIZE_UXGA;
        config.jpeg_quality = 10;
        config.fb_count = 2;
    }
    else
    {
        config.frame_size = FRAMESIZE_SVGA;
        config.jpeg_quality = 12;
        config.fb_count = 1;
    }

    if (PWDN_GPIO_NUM != -1)
    {
        pinMode(PWDN_GPIO_NUM, OUTPUT);
        digitalWrite(PWDN_GPIO_NUM, LOW);
    }

    esp_err_t err = esp_camera_init(&config);
    if (err != ESP_OK)
    {
        DEBUGX("Camera init failed with error 0x%x", err);
        return;
    }
    else
    {
        DEBUGLF("Camera init done...");
    }
}

### Debug Message

```plain
Here is the debug info that is printed on the serial monitor

rst:0xc (SW_CPU_RESET),boot:0x13 (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:1184
load:0x40078000,len:13132
load:0x40080400,len:3036
entry 0x400805e4

Booting up...
Loading Data from eeprom...
AP Mode
PS RAM found
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x400933c5  PS      : 0x00060f30  A0      : 0x8009407e  A1      : 0x3ffb2600
A2      : 0xffffffff  A3      : 0xffffffff  A4      : 0x3ffc5d5c  A5      : 0x00060f23
A6      : 0x00060f20  A7      : 0x00000001  A8      : 0x00000017  A9      : 0x00000000
A10     : 0x0000000f  A11     : 0x0000005c  A12     : 0x00060f20  A13     : 0x00060f23
A14     : 0x00060f23  A15     : 0x00000000  SAR     : 0x0000001f  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000013  LBEG    : 0x4008afa8  LEND    : 0x4008afbe  LCOUNT  : 0xffffffff

Backtrace:0x400933c2:0x3ffb26000x4009407b:0x3ffb2620 0x400943a0:0x3ffb2640 0x40083dc6:0x3ffb2660 0x40083dd9:0x3ffb2690 0x40083fe0:0x3ffb26b0 0x4011907b:0x3ffb26d0 0x40118c2b:0x3ffb2710 0x400d30bd:0x3ffb2760 0x400d34a7:0x3ffb27f0 0x400e7732:0x3ffb2820

  #0  0x400933c2:0x3ffb2600 in search_suitable_block at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_tlsf.c:183
      (inlined by) block_locate_free at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_tlsf.c:441
      (inlined by) tlsf_malloc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_tlsf.c:757
  #1  0x4009407b:0x3ffb2620 in multi_heap_malloc_impl at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/multi_heap.c:197        
  #2  0x400943a0:0x3ffb2640 in multi_heap_malloc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/multi_heap_poisoning.c:230   
      (inlined by) multi_heap_malloc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/multi_heap_poisoning.c:219
  #3  0x40083dc6:0x3ffb2660 in heap_caps_malloc_base at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_caps.c:147
  #4  0x40083dd9:0x3ffb2690 in heap_caps_malloc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_caps.c:167
  #5  0x40083fe0:0x3ffb26b0 in heap_caps_calloc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_caps.c:441
  #6  0x4011907b:0x3ffb26d0 in cam_dma_config at /Users/ficeto/Desktop/ESP32/ESP32S2/esp32-arduino-lib-builder/components/esp32-camera/driver/cam_hal.c:274
      (inlined by) cam_config at /Users/ficeto/Desktop/ESP32/ESP32S2/esp32-arduino-lib-builder/components/esp32-camera/driver/cam_hal.c:389
  #7  0x40118c2b:0x3ffb2710 in esp_camera_init at /Users/ficeto/Desktop/ESP32/ESP32S2/esp32-arduino-lib-builder/components/esp32-camera/driver/esp_camera.c:296
  #8  0x400d30bd:0x3ffb2760 in init_cam() at src/cam2AWS_S3.cpp:54
  #9  0x400d34a7:0x3ffb27f0 in setup() at src/main.cpp:23
  #10 0x400e7732:0x3ffb2820 in loopTask(void*) at C:/Users/Muhammad Arslan/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:42


### Other Steps to Reproduce

_No response_

### I have checked existing issues, online documentation and the Troubleshooting Guide

- [X] I confirm I have checked existing issues, online documentation and Troubleshooting guide.
me-no-dev commented 1 year ago

Could you please enable core debug to verbose and try again? Maybe PSRAM is not OK. Also make sure you power those boards reliably.

arslan437 commented 1 year ago

So currently I moved the position of function bit above in the setup. It worked but now I am unable to take the pictures.

When I call init_cam function after init_web_server function it does not work. But currently position it works.

Setup function is attached in picture below.

Screenshot_20221130-145104_Chrome.png

Jason2866 commented 1 year ago

Does the example camera code do work? If yes your code introduces the issue. Using delay is ALWAYS a bad idea, here it is maybe the reason for your issue.

arslan437 commented 1 year ago

I am testing the camera code separately. Will update you after that.

I don't use the delays buts its just for testing purposes only to make things faster.

arslan437 commented 1 year ago

@me-no-dev Yes there is some issue with the PSRAM.

Here is some info.

I did write a function to print the RAM of esp32. The function is

void print_free_memory()
{
    DEBUGLF("\n>>>---------- Momory Info ----------<<<");
    DEBUGL2("Free Heap: ", ESP.getFreeHeap());
    DEBUGL2("Free PSRAM: ", ESP.getFreePsram());
    DEBUGL2("Free sketch sapce: ", ESP.getFreeSketchSpace());
    DEBUGL2("Heap Size: ", ESP.getHeapSize());
    DEBUGL2("Max Alloc Heap: ", ESP.getMaxAllocHeap());
    DEBUGL2("Max Alloc Psram: ", ESP.getMaxAllocPsram());
    DEBUGL2("Psram Size: ", ESP.getPsramSize());
    DEBUGLF(">>>---------- Momory Info End ----------<<<\n");
}

Here is the results

before init the camera

>>>---------- Momory Info ----------<<<
Free Heap: 269948
Free PSRAM: 4192139
Free sketch sapce: 3145728
Heap Size: 299024
Max Alloc Heap: 110580
Max Alloc Psram: 4128756
Psram Size: 4192139
>>>---------- Momory Info End ----------<<<

After the camera init is done

>>>---------- Momory Info ----------<<<
Free Heap: 232972
Free PSRAM: 4096123
Free sketch sapce: 3145728
Heap Size: 298712
Max Alloc Heap: 110580
Max Alloc Psram: 4063220
Psram Size: 4192123
>>>---------- Momory Info End ----------<<<

After connecting to wifi

>>>---------- Momory Info ----------<<<
Free Heap: 162072
Free PSRAM: 0
Free sketch sapce: 3145728
Heap Size: 295576
Max Alloc Heap: 94196
Max Alloc Psram: Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x4009327f  PS      : 0x00060f30  A0      : 0x800942b6  A1      : 0x3ffb26d0
A2      : 0x0000084f  A3      : 0x40094304  A4      : 0x3ffb2734  A5      : 0x3ffb2750
A6      : 0xfffffffc  A7      : 0x00000001  A8      : 0x00000854  A9      : 0x3ffb26e0
A10     : 0x00000000  A11     : 0x00060123  A12     : 0x00060120  A13     : 0x00000000
A14     : 0x007b8a28  A15     : 0x003fffff  SAR     : 0x00000010  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000853  LBEG    : 0x4008b110  LEND    : 0x4008b11b  LCOUNT  : 0x00000000

Backtrace:0x4009327c:0x3ffb26d00x400942b3:0x3ffb26f0 0x40094543:0x3ffb2710 0x4010f342:0x3ffb2730 0x4010f391:0x3ffb2770 0x400e6119:0x3ffb27b0 0x400d3685:0x3ffb27d0 0x400d3716:0x3ffb27f0 0x400e8406:0x3ffb2820

  #0  0x4009327c:0x3ffb26d0 in block_size at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_tlsf_block_functions.h:75 (discriminator 4)
      (inlined by) block_is_last at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_tlsf_block_functions.h:86 (discriminator 4)
      (inlined by) tlsf_walk_pool at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_tlsf.c:581 (discriminator 4)
  #1  0x400942b3:0x3ffb26f0 in multi_heap_get_info_impl at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/multi_heap.c:378      
  #2  0x40094543:0x3ffb2710 in multi_heap_get_info at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/multi_heap_poisoning.c:364 
  #3  0x4010f342:0x3ffb2730 in heap_caps_get_info at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_caps.c:499
  #4  0x4010f391:0x3ffb2770 in heap_caps_get_largest_free_block at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_caps.c:487
  #5  0x400e6119:0x3ffb27b0 in EspClass::getMaxAllocPsram() at C:/Users/Muhammad Arslan/.platformio/packages/framework-arduinoespressif32/cores/esp32/Esp.cpp:183
  #6  0x400d3685:0x3ffb27d0 in print_free_memory() at src/globals.cpp:45
  #7  0x400d3716:0x3ffb27f0 in setup() at src/main.cpp:28
  #8  0x400e8406:0x3ffb2820 in loopTask(void*) at C:/Users/Muhammad Arslan/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:42

ELF file SHA256: 0000000000000000

Rebooting...
arslan437 commented 1 year ago

Here is little more progress.

I have commented out all the code in the void setup and void loop.

Here is the my current code

void setup()
{
  #ifdef EN_DEBUG
  Serial.begin(115200);
  DEBUGLF("\n\nBooting up...");
  #endif

  load_dev_config();

  print_free_memory();
  init_cam();
  delay(1000);
  print_free_memory();

  init_hardware_pins();
  init_wifi();
  print_free_memory(); 
}

code fails after the esp32 is either connected with wifi or acting as AP in both cases.

Does PSRAM has any thing to do with wifi ?

arslan437 commented 1 year ago

Here is my init_wifi function

void init_wifi()
{
    if (dev_config.wifi_mode == DEV_WIFI_ST)
    {
        WiFi.softAPdisconnect(true);
        WiFi.disconnect(true);

        DEBUGL2("\nConnecting to: ", dev_config.wifi_ssid);
        WiFi.mode(WIFI_STA);
        WiFi.begin(dev_config.wifi_ssid, dev_config.wifi_pass);
        while (WiFi.status() != WL_CONNECTED)
        {
            DEBUG_F(".");
            vTaskDelay(100 / portTICK_PERIOD_MS);
            check_for_factory_reset_btn();
        }
        DEBUGL2("IP: ", WiFi.localIP());
    }
    else 
    {
        DEBUGLF("AP Mode");
        WiFi.softAPdisconnect(true);
        WiFi.disconnect(true);

        #ifdef ENABLE_DEAFULT_ANDRIOD_DNS
        WiFi.mode(WIFI_AP);
        WiFi.softAP(DEFAULT_AP_SSID);
        WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
        #else
        WiFi.mode(WIFI_AP);
        WiFi.softAP(DEFAULT_AP_SSID, DEFAULT_AP_PASS);
        DEBUGL2("IP: ", WiFi.softAPIP());
        #endif
    }
}
me-no-dev commented 1 year ago

I am not aware of any reason for WiFi to "break" PSRAM. We have even disabled WiFi to use PSRAM in general. All our camera boards use PSRAM (and WiFi), so what you see is rather unexpected.

arslan437 commented 1 year ago

I did ported my code to esp-idf

I am unable to load init the camera

here is the error info

Rebooting...
I (10) boot: ESP-IDF v5.0 2nd stage bootloader
I (10) boot: compile time 21:25:38
I (10) boot: chip revision: v1.0
I (11) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (18) boot.esp32: SPI Speed      : 80MHz
I (23) boot.esp32: SPI Mode       : DIO
I (28) boot.esp32: SPI Flash Size : 4MB
I (32) boot: Enabling RNG early entropy source...
I (38) boot: Partition Table:
I (41) boot: ## Label            Usage          Type ST Offset   Length
I (49) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (56) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (63) boot:  2 factory          factory app      00 00 00010000 00177000
I (71) boot: End of partition table
I (75) boot_comm: chip revision: 1, min. application chip revision: 0
I (82) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=2ee30h (192048) map
I (149) esp_image: segment 1: paddr=0003ee58 vaddr=3ffb0000 size=011c0h (  4544) load
I (150) esp_image: segment 2: paddr=00040020 vaddr=400d0020 size=b6158h (745816) map
I (379) esp_image: segment 3: paddr=000f6180 vaddr=3ffb11c0 size=0402ch ( 16428) load
I (385) esp_image: segment 4: paddr=000fa1b4 vaddr=40080000 size=1c32ch (115500) load
I (425) esp_image: segment 5: paddr=001164e8 vaddr=50000000 size=00010h (    16) load
I (440) boot: Loaded app from partition at offset 0x10000
I (440) boot: Disabling RNG early entropy source...
I (452) quad_psram: This chip is ESP32-D0WD
I (453) esp_psram: Found 8MB PSRAM device
I (453) esp_psram: Speed: 80MHz
I (456) esp_psram: PSRAM initialized, cache is in low/high (2-core) mode.
W (464) esp_psram: Virtual address not enough for PSRAM, map as much as we can. 4MB is mapped
I (473) cpu_start: Pro cpu up.
I (477) cpu_start: Starting app cpu, entry point is 0x40081758
0x40081758: call_start_cpu1 at C:/esp-idf/esp-idf/components/esp_system/port/cpu_start.c:142

I (478) cpu_start: App cpu up.
I (995) esp_psram: SPI SRAM memory test OK
I (1003) cpu_start: Pro cpu start user code
I (1003) cpu_start: cpu freq: 160000000 Hz
I (1003) cpu_start: Application information:
I (1006) cpu_start: Project name:     gate-door-opener
I (1012) cpu_start: App version:      2c20dac-dirty
I (1017) cpu_start: Compile time:     Jan 10 2023 21:24:25
I (1024) cpu_start: ELF file SHA256:  03137fa8897ba109...
I (1030) cpu_start: ESP-IDF:          v5.0
I (1035) heap_init: Initializing. RAM available for dynamic allocation:
I (1042) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (1048) heap_init: At 3FFB9AB0 len 00026550 (153 KiB): DRAM
I (1054) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (1061) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (1067) heap_init: At 4009C32C len 00003CD4 (15 KiB): IRAM
I (1074) esp_psram: Adding pool of 4096K of PSRAM memory to heap allocator
I (1082) spi_flash: detected chip: generic
I (1086) spi_flash: flash io: dio
I (1091) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (1101) Main:

Booting up
I (1151) Global: nvs init is done
I (1161) Global: *******************Config Info*******************
I (1161) Global:
SSID:
Pass: 
Mode: 0
Valid: 0
I (1161) Global: *******************Config End*******************
I (1171) gpio: GPIO[25]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:2
I (1181) cam_hal: cam init ok
I (1181) sccb: pin_sda 26 pin_scl 27
I (1181) sccb: sccb_i2c_port=1

I (1191) gpio: GPIO[32]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (1231) camera: Detected camera at address=0x30
I (1231) camera: Detected OV2640 camera
I (1231) camera: Camera PID=0x26 VER=0x42 MIDL=0x7f MIDH=0xa2
I (1321) cam_hal: buffer_size: 32768, half_buffer_size: 4096, node_buffer_size: 2048, node_cnt: 16, total_cnt: 3
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x4009432a  PS      : 0x00060930  A0      : 0x80093e49  A1      : 0x3ffbc4e0
0x4009432a: search_suitable_block at C:/esp-idf/esp-idf/components/heap/tlsf/tlsf.c:308
 (inlined by) block_locate_free at C:/esp-idf/esp-idf/components/heap/tlsf/tlsf.c:566
 (inlined by) tlsf_malloc at C:/esp-idf/esp-idf/components/heap/tlsf/tlsf.c:934

A2      : 0xffffffff  A3      : 0x00000038  A4      : 0x0000000f  A5      : 0x00000000
A6      : 0x00000001  A7      : 0xff000000  A8      : 0x0000000e  A9      : 0x3ffbc170
A10     : 0x3ffbc190  A11     : 0x00000000  A12     : 0x3ffbc3f4  A13     : 0x00000005
A14     : 0x3ffaf258  A15     : 0x00000000  SAR     : 0x00000004  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000013  LBEG    : 0x4008c209  LEND    : 0x4008c219  LCOUNT  : 0xfffffffd
0x4008c209: strlen at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/machine/xtensa/strlen.S:84

0x4008c219: strlen at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/machine/xtensa/strlen.S:96

Backtrace: 0x40094327:0x3ffbc4e0 0x40093e46:0x3ffbc500 0x40082649:0x3ffbc520 0x40082686:0x3ffbc540 0x4008292d:0x3ffbc560 0x400de31d:0x3ffbc580 0x400de7f7:0x3ffbc5c0 0x400ddfc5:0x3ffbc5f0 0x400ddb96:0x3ffbc630 0x400dc8d1:0x3ffbc650 0x40184925:0x3ffbc670 0x400925e1:0x3ffbc6a0      
0x40094327: search_suitable_block at C:/esp-idf/esp-idf/components/heap/tlsf/tlsf.c:308
 (inlined by) block_locate_free at C:/esp-idf/esp-idf/components/heap/tlsf/tlsf.c:566
 (inlined by) tlsf_malloc at C:/esp-idf/esp-idf/components/heap/tlsf/tlsf.c:934

0x40093e46: multi_heap_malloc_impl at C:/esp-idf/esp-idf/components/heap/multi_heap.c:217

0x40082649: heap_caps_malloc_base at C:/esp-idf/esp-idf/components/heap/heap_caps.c:146

0x40082686: heap_caps_calloc_base at C:/esp-idf/esp-idf/components/heap/heap_caps.c:458

0x4008292d: heap_caps_calloc at C:/esp-idf/esp-idf/components/heap/heap_caps.c:467

0x400de31d: cam_dma_config at D:/Upwork/AviChalid/gate-door-opener/components/esp32-camera/driver/cam_hal.c:274

0x400de7f7: cam_config at D:/Upwork/AviChalid/gate-door-opener/components/esp32-camera/driver/cam_hal.c:389

0x400ddfc5: esp_camera_init at D:/Upwork/AviChalid/gate-door-opener/components/esp32-camera/driver/esp_camera.c:302

0x400ddb96: init_camera at D:/Upwork/AviChalid/gate-door-opener/main/cam_aws_s3.c:59

0x400dc8d1: app_main at D:/Upwork/AviChalid/gate-door-opener/main/main.c:22

0x40184925: main_task at C:/esp-idf/esp-idf/components/freertos/FreeRTOS-Kernel/portable/port_common.c:131 (discriminator 2)

0x400925e1: vPortTaskWrapper at C:/esp-idf/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:151

here is the main function

void app_main(void)
{
    esp_log_level_set("*", ESP_LOG_INFO);
    ESP_LOGI(DEBUG_TAG, "\n\n\nBooting up");
    init_nvs();
    load_dev_config();
    print_dev_config();

    init_hardware_pins();
    init_camera();

    if(dev_config.wifi_mode == DEV_WIFI_ST)
    {
        init_wifi_sta(dev_config.wifi_ssid, dev_config.wifi_pass);
        init_mDNS();
        init_web_server();
    }
    else 
    {
        init_wifi_ap();
        init_mDNS();
        init_web_server();
        start_dns_server();
    }

    take_send_photo();
    // aws_iot_demo_main(0,NULL);
}

here is the init camera function

static camera_config_t camera_config = {
    .pin_pwdn = CAM_PIN_PWDN,
    .pin_reset = CAM_PIN_RESET,
    .pin_xclk = CAM_PIN_XCLK,
    .pin_sccb_sda = CAM_PIN_SIOD,
    .pin_sccb_scl = CAM_PIN_SIOC,

    .pin_d7 = CAM_PIN_D7,
    .pin_d6 = CAM_PIN_D6,
    .pin_d5 = CAM_PIN_D5,
    .pin_d4 = CAM_PIN_D4,
    .pin_d3 = CAM_PIN_D3,
    .pin_d2 = CAM_PIN_D2,
    .pin_d1 = CAM_PIN_D1,
    .pin_d0 = CAM_PIN_D0,
    .pin_vsync = CAM_PIN_VSYNC,
    .pin_href = CAM_PIN_HREF,
    .pin_pclk = CAM_PIN_PCLK,

    //XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental)
    .xclk_freq_hz = 20000000,
    .ledc_timer = LEDC_TIMER_0,
    .ledc_channel = LEDC_CHANNEL_0,

    // .pixel_format = PIXFORMAT_RGB565, //YUV422,GRAYSCALE,RGB565,JPEG
    .pixel_format = PIXFORMAT_JPEG,
    .frame_size = FRAMESIZE_QVGA,    //QQVGA-UXGA, For ESP32, do not use sizes above QVGA when not JPEG. The performance of the ESP32-S series has improved a lot, but JPEG mode always gives better frame rates.

    .jpeg_quality = 12, //0-63, for OV series camera sensors, lower number means higher quality
    .fb_count = 1,       //When jpeg mode is used, if fb_count more than one, the driver will work in continuous mode.
    .grab_mode = CAMERA_GRAB_WHEN_EMPTY,
};

esp_err_t init_camera()
{
    //initialize the camera
    esp_err_t err = esp_camera_init(&camera_config);
    if (err != ESP_OK)
    {
        ESP_LOGE(TAG, "Camera Init Failed");
        return err;
    }

    return ESP_OK;
}
Jason2866 commented 1 year ago

Try not to use NVS for other things in your sketch, if you can't avoid disable interrupts.

arslan437 commented 1 year ago

Camera worked this time when I commented this fubction

void init_hardware_pins() { gpio_set_direction(WIFI_STATUS_LED_PIN, GPIO_MODE_OUTPUT); gpio_set_direction(DEV_FACTORY_RESET_PIN, GPIO_MODE_INPUT); gpio_set_direction(GATE_CTRL_RELAY_PIN, GPIO_MODE_OUTPUT); gpio_set_direction(PAIR_BUTTON_PIN, GPIO_MODE_INPUT); gpio_set_pull_mode(DEV_FACTORY_RESET_PIN, GPIO_PULLUP_ONLY); gpio_set_pull_mode(PAIR_BUTTON_PIN, GPIO_PULLUP_ONLY); ultrasonic_init(&sensor_ultrasonic); }
arslan437 commented 1 year ago

Try not to use NVS for other things in your sketch, if you can't avoid disable interrupts.

I am using nvs to store the device configuration

I am also using a ultrasonic sensor that might be disabling the interrupts.

Ultrasonic library is from this repo https://github.com/UncleRus/esp-idf-lib

Jason2866 commented 1 year ago

Minimize your sketch for testing to Camera function only. Add one by one functions and libs you want. You probably cant add all.

arslan437 commented 1 year ago

After all the testing I found one line if I comment that camera works.

Here is that line

#define GATE_CTRL_RELAY_PIN     16
gpio_set_direction(GATE_CTRL_RELAY_PIN, GPIO_MODE_OUTPUT);

why setting gpio 16 as output breaks the code ?

arslan437 commented 1 year ago

I think I have found the answer

image