PlatformIO Community

How to set crystal frequency in ESP32 [SOLVED]

I have a Heltec WiFi kit, and I am using the Remote Control peripheral to generate a PPM output pulse stream. As part of the configuration I set the clock divider to 80 which should give me a one microsecond tick size (80MHz clock), but instead I got a tick size of roughly 1.5us.

After much searching I learned that there is a parameter to set the crystal frequency, which can be either 40MHz or 26MHz. It seems mine is 26MHz variety, but the default is 40MHz, hence the discrepancy. I have also seen an error message in the output (after I changed the baud rate to 74880 (115200 * 26 / 40) as noted in an old post on the same topic). I also changed my clock divider to 52 (80 * 26 / 40) which gave me the required 1us tick size. So it works, bu it’s a workaround.

After more research I found that the frequency is defined in sdkconfig.h. I tried changing it in the files defined for the project, but it was immediately overwritten again next time I compiled the project, and reset to 40.

I found another sdkconfig.h file here ~/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/config/sdkconfig.h (but there isn’t one in framework-espidf, which is the framework I am using), and updated it to 26 there, but again the values in the sdkconfig.h files generated for the project were set to 40.

I have also installed the esp development tool, and used the idf.py menuconfig command to set the default frequence to 26. This has worked for the esp tool, as I can compile and upload the program, with a clock divider = 80, and it generates a 1us tick size as expected. I should mention that it also appears to work in PlatformIO using the arduinoespresiff32 framework, but I’ve run into some other problems there.

So how do I set the frequency to 26 when using the espidf framework?

Thanks, Ian

Possibly a silly question… but have you tried running menuconfig from the platformIO terminal to configure your project the native way (pio run -t menuconfig)? Maybe that makes the change changes stick?

Since ESP-IDF v4+ using CMake, the project configuration is slightly different… it uses a sdkconfig (note the extension is missing) in the root of the project, rather than the sdkconfig.h located in the src subfolder like how earlier versions did.

Ermmm… no, I didn’t know you could do that. I was wondering if it was possible to run idf.py from within PlatformIO, out of idle curiosity.

Main problem now though is that pio command is not found. Bit odd. Why would it not be there? Have I stuffed something up? (wouldn’t be the first time…)

:-\

EDIT so I got pio to work. Clicked on the PIO logo in the left hand bar and selected PlatformIO Core CLI. It ran pio and it worked. Now oliver sudden, pio works again.

Trying menuconfig now…

:slight_smile:

Try clicking the PIO Terminal button and trying again… VSCode has a nasty habit of opening its own terminal up first, which knows nothing about PlatformIO… the 2.0 extension should fix that well and truly when it releases soon™.

image

Have I stuffed something up? (wouldn’t be the first time…)

I’ve been there… :laughing:

Well it worked. I now have the correct crystal frequency set, and the clock_div 80 generates the correct tick size. What a palaver!

Thanks for you help, much appreciated.

Now I can go back to tearing out what little hair I have left trying to understand the rmt functions. They don’t seem to do the things I would expect them to based on their names… maybe it’s just me.

:slight_smile:

1 Like