-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
esp32-core: Fix BOARD_CLOCK_FREQUENCY #413
Conversation
Tested on qemu. I left CONFIG_ESP32CORE_RUN_IRAM case and the "Don't ask me" comment as it is because I don't understand it or can test it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should not hardcode the frequency because tehre are 2 available crystal frequencyes
https://bitbucket.org/alinjerpelea/nuttx/src/ce7a0b390c7c983fbf3811734c8d0a4274b9c3bf/boards/xtensa/esp32/esp32-core/Kconfig#lines-9
@jerpelea |
here is the explanation By default it is set to 40MHZ and I do not see the reason to hardcode the frequency I would investigate why CONFIG_ESP32CORE_RUN_IRAM is setting it to 80MhZ |
@jerpelea are you going to investigate CONFIG_ESP32CORE_RUN_IRAM? |
-# define BOARD_CLOCK_FREQUENCY BOARD_XTAL_FREQUENCY this is your change |
I do not have OpenOCD |
@jerpelea |
In your change you replace this line with a hardcoded value |
my thinking is that
|
The frequency is only hardcoded if CONFIG_SUPPRESS_CLOCK_CONFIG is selected. That is because the actual clock configuration logic is (or at least was) proprietary and Expressif never released this in source form, only as a binary library. If that library is downloaded and included in the build, then you can select any of the supported frequencies. I don't follow ESP32 closely, but this change does not look correct and I do not think that it should be incorporated. You should also look at TizenRT. Expressif took the NuttX ESP32 port and extended it in Tizen RT. You can bring those improvements in as you see fit, provided that we make sure that the Apache licensing is correct. See https://github.com/Samsung/TizenRT/tree/master/os/arch/xtensa. Since that code is supported by Expressif, that should be considered an authoritative source. |
do you mean non-CONFIG_SUPPRESS_CLOCK_CONFIG code can work? i don't think it even compile. i don't know how it was. but at this point the source code of the bootloader and hal are available. and they seem to hardcode 80MHz. TizenRT just uses "#define BOARD_CLOCK_FREQUENCY (2 * BOARD_XTAL_FREQUENCY)" unconditionally. |
in my opion this is the proper fix instead of hardcoding it |
@jerpelea why do you think it should be 2 * BOARD_XTAL_FREQUENCY? |
The frequency must match a clock source and if on the board is a 26MHZ quarts it it impossible to get 80MHZ. There may be 2 or more variants of the bootloader with different hardc oded frequencyes. |
@jerpelea |
@yamt please add the following change (same as TizenRT)so that I can merge the PR |
@patacongo yes I will |
@jerpelea i won't until i understand why it should be (2 * BOARD_XTAL_FREQUENCY). maybe i will try to ask espressif. |
Hi, @yamt
Could you tell us how to run nuttx for esp32 with qemu? |
On the ESP32, APB/CPU frequencies higher than the XTAL frequency are obtained using one of the two PLLs. So either of 26 or 40 MHz XTAL can be used as clock source for the PLL. PLL clock (320 or 480 MHz) is then internally divided to produce the CPU clock (80/160/240MHz) and the APB clock (80MHz). |
By the way, this line: #ifdef CONFIG_ESP32CORE_RUN_IRAM
# define BOARD_CLOCK_FREQUENCY (2 * BOARD_XTAL_FREQUENCY)
#else looks incorrect to me. As I understand, |
This is why I usggested that the change should be |
By request, I created this pull request after polishing some patches I did some days ago to ease running the ESP32 QEMU: #437 Hope it would be useful. Feedback and/or improvements are welcome. |
@jerpelea, sorry, i still don't understand why the BOARD_CLOCK_FREQUENCY should be exactly twice BOARD_XTAL_FREQUENCY. In the ESP32, the CPU frequency can be either of the following:
Note that 80/160/240 values are independent of the XTAL frequency, which can be 40 or 26 MHz. So in the specific case when XTAL frequency is 40 MHz, indeed the CPU frequency can be twice the XTAL frequency. But in theory you may have a 26MHz XTAL along with 80MHz CPU frequency. |
Tested on qemu.
I left CONFIG_ESP32CORE_RUN_IRAM case and the "Don't ask me" comment
as it is because I don't understand it or can test it.