Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Change CPU Frequency

    Scheduled Pinned Locked Moved Firmware
    esp32lopy
    14 Posts 5 Posters 3.5k Views 6 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      JuanMa
      last edited by

      Is it possible to change CPU frequency on Lopy4 from 160Mhz to 80MHz? I have tried to change
      #define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 160
      to
      #define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 80
      and
      #define CONFIG_ESP32_DEFAULT_CPU_FREQ_160 1
      to
      #define CONFIG_ESP32_DEFAULT_CPU_FREQ_80 1
      in sdkconfig.h file, but I still get 160Mhz when I call machine.freq().
      Am I leaving something behind?

      Thanks,

      JuanMa

      robert-hhR 1 Reply Last reply Reply Quote 1
      • robert-hhR Offline
        robert-hh @JuanMa
        last edited by

        @juanma changes to sdkconfig.h have no effect until you rebuild the libs in the esp-idf. There was a bug in the ESP32 (or the esp-idf), that you cannot drop directly with machine.frequency to 80 MHz. As far as I recall, you have to go down to 40 MHz first and then go up again.

        1 Reply Last reply Reply Quote 1
        • J Offline
          JuanMa
          last edited by

          Thanks!
          I have not realized that I have to rebuild the libs. I was aware of the ESP32 bug, but I don´t want to change the frequency dynamically, only to work on a lower frequency to save power.

          1 Reply Last reply Reply Quote 0
          • J Offline
            JuanMa
            last edited by

            @robert-hh Maybe I am doing something wrong. How can I rebuild the libs in the esp-idf? Thanks :)

            1 Reply Last reply Reply Quote 0
            • J Offline
              JuanMa
              last edited by

              @robert-hh Sorry for my ignorance, but how can I rebuildthe libs in the esp-idf in order to change the cpu frequency?

              robert-hhR 1 Reply Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @JuanMa
                last edited by

                @juanma Sorry, I had to dig for an old post first. So that's what I would do:
                That is a little bit tricky, since you have to rebuild lib/libesp32.a too. For that, I did the following:
                a) go into any of the pycom-esp-idf/examples. I choose. examples/wifi/scan
                b) run make. It will lead you through configure. Just exit there, and compiles a build. The configuration does not matter, since you will take that from the pycom directory in step c
                c) take skdconfig.h from pycom's esp32 directory and put that into pycom-esp-idf/examples/wifi/scan/build/include
                d) modify it to your needs and save it. It has a new modification date then-
                e) run make again on that example
                f) now there is a libesp32.a in pycom-esp-idf/examples/wifi/scan/build/esp32 with the intended modification
                g) copy that lib file back to pycom's esp32/lib. Don't forget to save the old version.- You will need that for pycom's devices.
                Then make your firmware again.

                C 2 Replies Last reply Reply Quote 0
                • T Offline
                  this.wiederkehr
                  last edited by this.wiederkehr

                  @JuanMa see here:
                  https://forum.pycom.io/topic/1349/how-to-build-micropython-from-source-incuding-esp-idf-components/5

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    JuanMa
                    last edited by

                    @robert-hh @this-wiederkehr Thanks!! I will try right now :)

                    1 Reply Last reply Reply Quote 0
                    • C Offline
                      combaindeft
                      last edited by

                      So, you have to compile a new firmware to lower the cpu-freq?

                      I thought you could do it "on the fly" by calling a function.

                      Could that be achived? Adding a fuction the the Machine Library?

                      robert-hhR 1 Reply Last reply Reply Quote 0
                      • robert-hhR Offline
                        robert-hh @combaindeft
                        last edited by

                        @combaindeft Other ports of micropython use machine.freq() for that purpose.

                        C 1 Reply Last reply Reply Quote 0
                        • C Offline
                          combaindeft @robert-hh
                          last edited by

                          @robert-hh IIRC, the LoPy's we have, do have the machine.freq() defined.

                          robert-hhR 1 Reply Last reply Reply Quote 0
                          • robert-hhR Offline
                            robert-hh @combaindeft
                            last edited by robert-hh

                            @combaindeft Yes, but only for telling the frequency, and not setting it. If you look at the esp32 port of micropython.org, you can use that method for setting the frequecy, or at least it is intended to do so. It accepts an argument, but does not call the idf function. Code below:

                            STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
                                if (n_args == 0) {
                                    // get
                                    return mp_obj_new_int(ets_get_cpu_frequency() * 1000000);
                                } else {
                                    // set
                                    mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
                                    if (freq != 80 && freq != 160 && freq != 240) {
                                        mp_raise_ValueError("frequency can only be either 80Mhz, 160MHz or 240MHz");
                                    }
                                    /*
                                    system_update_cpu_freq(freq);
                                    */
                                    return mp_const_none;
                                }
                            }
                            STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 1, machine_freq);
                            

                            Edit: This code does not work.

                            1 Reply Last reply Reply Quote 0
                            • C Offline
                              Colateral @robert-hh
                              last edited by

                              This post is deleted!
                              1 Reply Last reply Reply Quote 0
                              • C Offline
                                Colateral @robert-hh
                                last edited by

                                @robert-hh This is not working well. During make skdconfig.h is replaced by make GENCONFIG (that is using wifi/scan/sdkconfig). The best is to modify that config.

                                However moving the freq from 160 to 80 -> it saves only 7mA ... I expected to be more.
                                So LoPY+shield with Wifi disable is consuming 35mA.

                                1 Reply Last reply Reply Quote 0

                                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                With your input, this post could be even better 💗

                                Register Login
                                • 1 / 1
                                • First post
                                  Last post

                                Pycom on Twitter

                                Pycom