Skip to content

fix esp32s3 compile error when xclk set to -1 #405

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

Closed

Conversation

Kevincoooool
Copy link
Contributor

when i set xclk=-1,complie error

@me-no-dev
Copy link
Member

Please add proper title and explanation on why this change is necessary. Does it have to do with camera with their own XCLK?

@Kevincoooool Kevincoooool changed the title fix esp32s3 xclk=-1 error fix esp32s3 compile error when xclk set to -1 Jun 14, 2022
@Kevincoooool
Copy link
Contributor Author

Please add proper title and explanation on why this change is necessary. Does it have to do with camera with their own XCLK?

The XCLK pin of the camera on my own hardware uses an active crystal oscillator, and is not controlled by the IO port. When I set it to -1, because the XCLK is not judged in the program, an error will be reported.

@me-no-dev
Copy link
Member

OK, then same check should be added here so other chips behave the same :)

@Kevincoooool
Copy link
Contributor Author

OK, then same check should be added here so other chips behave the same :)

Only ESP32S3 needs it, other chips have judgment

@me-no-dev
Copy link
Member

Only ESP32S3 needs it, other chips have judgment

I'm not sure I understand what you mean? Are you saying that the other chips will work fine with -1? I do not see a check for that.

@lovyan03
Copy link

@Kevincoooool
Thanks for this pull request suggestion.

I am facing the same problem and would like to suggest adopting this pull request.
I want to connect an external clock source to the camera and would like to set xclk = - 1.

@me-no-dev
Allow me to offer an additional explanation of the part in question.

The ESP32 and ESP32S2 implementations generate clocks using LEDC by determining if xclk is positive.
In other words, when xclk = -1 is set, the system operates without setting LEDC.

if (config->pin_xclk >= 0) {
ESP_LOGD(TAG, "Enabling XCLK output");
CAMERA_ENABLE_OUT_CLOCK(config);
}

The ESP32S3 implementation crashes at runtime because it accesses the array without checking if xclk is positive.

PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[config->pin_xclk], PIN_FUNC_GPIO);
gpio_set_direction(config->pin_xclk, GPIO_MODE_OUTPUT);
gpio_set_pull_mode(config->pin_xclk, GPIO_FLOATING);
gpio_matrix_out(config->pin_xclk, CAM_CLK_IDX, false, false);

Therefore, it makes sense to add the xclk value check only to the ESP32S3 implementation, as in this pull request.

In other words, the current situation is that xclk = -1 causes a crash only on the ESP32S3.
By adopting this pull request, it would be possible to set xclk = -1 on all processors.

Please consider this matter.

@igrr
Copy link
Member

igrr commented Aug 12, 2022

@lovyan03 Thank you for the explanation, I think it makes sense to add this check.

Copy link
Member

@igrr igrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kevincoooool Could you please address the minor formatting issue and rebase your PR on top of the latest master branch? Thank you.

gpio_matrix_out(config->pin_xclk, CAM_CLK_IDX, false, false);

if(config->pin_xclk>=0)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting nitpick: the opening brace should be on the same line as the if, and there should be a space between if and (.

@igrr
Copy link
Member

igrr commented Aug 15, 2022

Closing in favor of #438.

@Kevincoooool by the way, it is not necessary to create a new branch or a PR when you want to update an existing PR. You can push the changes to the same branch and the PR will be updated automatically. It is also okay to force-push to feature or bugfix branches like this one, in case you do perform a rebase of your local branch.

@igrr igrr closed this Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants