Page 1 of 1

Compiler flag oprion to change CPU FREQ ?

Posted: Sun Nov 04, 2018 7:40 pm
by mikemoy
Is there a flag option "-DF_CPU=" that changes the CPU MHZ ?

I am having an issue using platformIO where their setting for changing the CPU MHZ is not taking affect.
At compile time they add this flag option "-DF_CPU=160000000L". Regardless if it's 160000000L or 240000000L does not affect the CPU speed.

Using this basic example to test this, and a scope to check it.

Code: Select all

#include <stdio.h>
#include "driver/gpio.h"
#include "sdkconfig.h"

#define BLINK_GPIO 4

void app_main()
{
    gpio_pad_select_gpio(BLINK_GPIO);
    gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);

    while(1)
    {
        gpio_set_level(BLINK_GPIO, 0);
        gpio_set_level(BLINK_GPIO, 1);
    }

}

Re: Compiler flag oprion to change CPU FREQ ?

Posted: Mon Nov 05, 2018 1:35 am
by WiFive
How about calling esp_clk_cpu_freq to check? Gpio speed may be bottlenecked by peripheral bus.

Re: Compiler flag oprion to change CPU FREQ ?

Posted: Mon Nov 05, 2018 1:46 am
by mikemoy
I have no way to change what they are doing. I wore just looking to see if "-DF_CPU=" was documented as a parameter to pass to the compiler, or it it changed to something else and its now outdated what they are using.

Re: Compiler flag oprion to change CPU FREQ ?

Posted: Mon Nov 05, 2018 2:42 am
by ESP_Angus
Hi mike,

The F_CPU macro is an Arduino thing, ESP-IDF doesn't use it. Platform.io might add some extra layers to support this, but you'd have to ask them (I suspect the answer is "no").

The official way to change the default CPU speed in ESP-IDF is to change it in menuconfig and rebuild the app. I don't know how this works in platform.io (might depend if you're using platform.io with Arduino-ESP32 platform.io or ESP-IDF, I'm not sure.)

The APB peripheral bus runs at 80MHz for CPU settings of 80, 160 & 240MHz, so the speed of toggling a GPIO may not change by a significant amount (although it might when calling gpio_set_level() function, due to the function call overhead).


Angus

Re: Compiler flag oprion to change CPU FREQ ?

Posted: Mon Nov 05, 2018 3:03 am
by mikemoy
Just for any who cares. The difference in toggling the IO in my example with CPU @ 240MHZ is 3.6MHZ, and when CPU is set to 160MHZ its 1.8MHZ