Compiler flag oprion to change CPU FREQ ?

mikemoy
Posts: 599
Joined: Fri Jan 12, 2018 9:10 pm

Compiler flag oprion to change CPU FREQ ?

Postby mikemoy » Sun Nov 04, 2018 7:40 pm

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);
    }

}

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Compiler flag oprion to change CPU FREQ ?

Postby WiFive » Mon Nov 05, 2018 1:35 am

How about calling esp_clk_cpu_freq to check? Gpio speed may be bottlenecked by peripheral bus.

mikemoy
Posts: 599
Joined: Fri Jan 12, 2018 9:10 pm

Re: Compiler flag oprion to change CPU FREQ ?

Postby mikemoy » Mon Nov 05, 2018 1:46 am

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.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Compiler flag oprion to change CPU FREQ ?

Postby ESP_Angus » Mon Nov 05, 2018 2:42 am

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

mikemoy
Posts: 599
Joined: Fri Jan 12, 2018 9:10 pm

Re: Compiler flag oprion to change CPU FREQ ?

Postby mikemoy » Mon Nov 05, 2018 3:03 am

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

Who is online

Users browsing this forum: No registered users and 159 guests