Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LEDc configuration error and camera_probe failed #66

Closed
masterd89 opened this issue Aug 27, 2019 · 8 comments
Closed

LEDc configuration error and camera_probe failed #66

masterd89 opened this issue Aug 27, 2019 · 8 comments

Comments

@masterd89
Copy link

Hello there,

i have an issue with ESP32-CAM module with OV2640:

E (1582) ledc: requested frequency and duty resolution can not be achieved, try reducing freq_hz or duty_resolution. div_param=3
E (1592) camera_xclk: ledc_timer_config failed, rc=ffffffff
I (1602) sccb: pin_sda 26 pin_scl 27

I (1602) gpio: GPIO[32]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
E (1662) camera: Detected camera not supported.
E (1662) camera: Camera probe failed with error 0x20004
E (1662) app_camera: Camera init failed with error 0x20004

I've tried everything: enable/disable all camera module support and hw I2C from menuconfig, tried with 3 different unit and different cameras. Tried custom firmware and examples firmware, examined the code and the pin configuration, different USB to serial boards, powering the boards with external PSU.....and yet i still get that error.
I also updated esp-idf framework by deleting and re cloning the repo. No luck with that also.

Any idea?
Thanks,
D

@mirronelli
Copy link
Contributor

mirronelli commented Aug 28, 2019

there was a change in ledc driver that is used to drive the clock

to work with the current version a one line of code needs to be added into xclk.c
the line is:

timer_conf.clk_cfg = LEDC_USE_APB_CLK;

put in in the block bellow

        ledc_timer_config_t timer_conf;
        timer_conf.duty_resolution = 2;
        timer_conf.freq_hz = config->xclk_freq_hz;
	timer_conf.speed_mode = LEDC_HIGH_SPEED_MODE;
	timer_conf.timer_num = config->ledc_timer;
	timer_conf.clk_cfg = LEDC_USE_APB_CLK;
	esp_err_t err = ledc_timer_config(&timer_conf);
	if (err != ESP_OK) {
		ESP_LOGE(TAG, "ledc_timer_config failed, rc=%x", err);
		return err;
	}

you will find the the file in yourproject/components/esp32-camera/driver/xclk.c

use of the APB clock was assumed in previous commit to ledc.c and now it needs to be explicitly set

@masterd89
Copy link
Author

Thanks @mirronelli, i already figured it out though (while i used LEDC_AUTO_CLK).

Strange thing is, if i ran the ledc initialization snippet (whitout setting the clock source) from the app-main it didn't give any error at all.

Moreover, while this solution solves the duty cycle - frequency error, in my case it still hangs in "skip_frame()" function, thowing a timeout error. I found out this occurred because the VSYNC pin wasn't actually clocking, even though it was correctly initialized.

I solved it by moving the pheripheral enable command at the end of the function, after the parameters assignment:

ledc_timer_config_t timer_conf;
timer_conf.duty_resolution = 2;
timer_conf.freq_hz = config->xclk_freq_hz;
timer_conf.speed_mode = LEDC_HIGH_SPEED_MODE;
timer_conf.timer_num = config->ledc_timer;
ESP_LOGI(TAG,"dr = %d, fr = %d", timer_conf.duty_resolution, timer_conf.freq_hz);
timer_conf.clk_cfg = LEDC_AUTO_CLK;
esp_err_t err = ledc_timer_config(&timer_conf);
if (err != ESP_OK) {
    ESP_LOGE(TAG, "ledc_timer_config failed, rc=%x", err);
    return err;
}

ledc_channel_config_t ch_conf;
ch_conf.gpio_num = config->pin_xclk;
ch_conf.speed_mode = LEDC_HIGH_SPEED_MODE;
ch_conf.channel = config->ledc_channel;
ch_conf.intr_type = LEDC_INTR_DISABLE;
ch_conf.timer_sel = config->ledc_timer;
ch_conf.duty = 2;
ch_conf.hpoint = 0;
err = ledc_channel_config(&ch_conf);
if (err != ESP_OK) {
    ESP_LOGE(TAG, "ledc_channel_config failed, rc=%x", err);
    return err;
}
periph_module_enable(PERIPH_LEDC_MODULE);
return ESP_OK;

The other issue i found (the one that caused error 0x20004), which is however related to the circuit, is that camera wasn't responding to i2c commands, thus preventing the software to recognize the correct model.

ESP32-CAM board has camera PWDN pin tied to GND (so camera is always powered) while camera RST is passively deasserted a little time afte 3.3V supply is started. However, GPIO32 controls the power supply enable of the camera by means of a transistor. Thus, if GPIO32 is not set low before calling camera_init(), the camera is powered down and cannot reply to i2c commands of course. This solved the issue:

//initialize the camera
gpio_config_t gpio_pwr_config;
gpio_pwr_config.pin_bit_mask = (1ULL << 32);
gpio_pwr_config.mode = GPIO_MODE_OUTPUT;
gpio_pwr_config.pull_down_en = GPIO_PULLDOWN_DISABLE;
gpio_pwr_config.pull_up_en = GPIO_PULLUP_DISABLE;
gpio_pwr_config.intr_type = GPIO_INTR_DISABLE;
gpio_config(&gpio_pwr_config);
gpio_set_level(32,0);
vTaskDelay(10/ portTICK_PERIOD_MS);

esp_err_t err = esp_camera_init(&camera_config);

@jxyxg
Copy link

jxyxg commented Aug 13, 2020

Hello, sorry to bother you guys, now i am writing a driver code of the ov2640 with esp32cam, but actually i have no idea and donnot know how to start and i have found that there is few material about writing a driver code from scratch, I wondering whether you have some experience or have some useful tutorial material, can you share them with me ? Many thanks ! @masterd89 @mirronelli

@won0-kim
Copy link

// Select camera model
// #define CAMERA_MODEL_WROVER_KIT // Has PSRAM
//#define CAMERA_MODEL_ESP_EYE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
#define CAMERA_MODEL_AI_THINKER // Has PSRAM
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM

@jxyxg I think.. this problem could be solved easily by only changing these comments like that.

@github-actions
Copy link

This issue appears to be stale. Please close it if its no longer valid.

@yugandharc9
Copy link

In my case I had to comment
#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
and uncomment

#define CAMERA_MODEL_AI_THINKER // Has PSRAM

@Morchack
Copy link

Morchack commented Jan 4, 2022

Obrigado @mirronelli , eu já descobri (enquanto usava LEDC_AUTO_CLK).

O estranho é que, se eu executei o snippet de inicialização do ledc (sem definir a fonte do relógio) do app-main, não deu nenhum erro.

Além disso, embora esta solução resolva o erro de ciclo de trabalho - frequência, no meu caso ela ainda trava na função "skip_frame ()", resultando em um erro de tempo limite. Descobri que isso ocorreu porque o pino VSYNC não estava realmente sincronizando, embora tenha sido inicializado corretamente.

Resolvi movendo o comando de habilitação de pheripheral no final da função, após a atribuição dos parâmetros:

ledc_timer_config_t timer_conf;
timer_conf.duty_resolution = 2;
timer_conf.freq_hz = config->xclk_freq_hz;
timer_conf.speed_mode = LEDC_HIGH_SPEED_MODE;
timer_conf.timer_num = config->ledc_timer;
ESP_LOGI(TAG,"dr = %d, fr = %d", timer_conf.duty_resolution, timer_conf.freq_hz);
timer_conf.clk_cfg = LEDC_AUTO_CLK;
esp_err_t err = ledc_timer_config(&timer_conf);
if (err != ESP_OK) {
    ESP_LOGE(TAG, "ledc_timer_config failed, rc=%x", err);
    return err;
}

ledc_channel_config_t ch_conf;
ch_conf.gpio_num = config->pin_xclk;
ch_conf.speed_mode = LEDC_HIGH_SPEED_MODE;
ch_conf.channel = config->ledc_channel;
ch_conf.intr_type = LEDC_INTR_DISABLE;
ch_conf.timer_sel = config->ledc_timer;
ch_conf.duty = 2;
ch_conf.hpoint = 0;
err = ledc_channel_config(&ch_conf);
if (err != ESP_OK) {
    ESP_LOGE(TAG, "ledc_channel_config failed, rc=%x", err);
    return err;
}
periph_module_enable(PERIPH_LEDC_MODULE);
return ESP_OK;

O outro problema que encontrei (o que causou o erro 0x20004), porém relacionado ao circuito, é que a câmera não respondia aos comandos do i2c, impedindo que o software reconhecesse o modelo correto.

A placa ESP32-CAM tem o pino PWDN da câmera ligado ao GND (para que a câmera esteja sempre ligada), enquanto a câmera RST é desativada passivamente um pouco depois que o fornecimento de 3,3 V é iniciado. No entanto, o GPIO32 controla a ativação da fonte de alimentação da câmera por meio de um transistor. Portanto, se o GPIO32 não estiver definido como baixo antes de chamar camera_init (), a câmera será desligada e não poderá responder aos comandos i2c, é claro. Isso resolveu o problema:

//initialize the camera
gpio_config_t gpio_pwr_config;
gpio_pwr_config.pin_bit_mask = (1ULL << 32);
gpio_pwr_config.mode = GPIO_MODE_OUTPUT;
gpio_pwr_config.pull_down_en = GPIO_PULLDOWN_DISABLE;
gpio_pwr_config.pull_up_en = GPIO_PULLUP_DISABLE;
gpio_pwr_config.intr_type = GPIO_INTR_DISABLE;
gpio_config(&gpio_pwr_config);
gpio_set_level(32,0);
vTaskDelay(10/ portTICK_PERIOD_MS);

esp_err_t err = esp_camera_init(&camera_config);

@Morchack
Copy link

Morchack commented Jan 4, 2022

ola eu também tenho este problema , em que parte do código é que eu devo colocar este novo código que colocou aqui em cima.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants