Hi, @MaximoEsfuerzo
Thank you.
The link is about arduino 1.x, but ... I want to use the arduino-cli, namely, the command line, to set the frequency of mcu.
Best regards.
Hi @wanggaoteng. My recommendation is to use the excellent "MiniCore" boards platform:
This 3rd party boards platform provides a board definition for the ATmega328P microcontroller with custom board options that allow you to set various configurations, including the clock source (internal or external) and speed. This means you can use a convenient user interface to configure the clock speed instead of having to adjust the F_CPU macro value using a lower level internal interface that was never intended to be used by the user.
The Arduino boards platform framework allows the platform developer to include "custom board options" in a board definition. These "custom board options" can be used by the user to adjust the configuration of that board definition (e.g., choosing the clock speed).
When using Arduino CLI, the custom board options are set via --board-options flags added to the arduino-cli commands.
The format of the flag is like this:
--board-options "<menu ID>=<option ID>"
(where <menu ID> and <option ID> are placeholders for the custom board options menu and menu option you are setting)
The value of the F_CPU macro you are modifying is only used by code that needs to know the clock frequency. It does not affect the clock source. That is done by the configuration fuses. So if your board has an external 16 MHz clock and the fuses are set to use that clock, then it will continue to do so even after you change the value of the F_CPU macro.
You can easily change the configuration fuses by running an arduino-cli burn-bootloader command with the MiniCore:avr:328 board and clock=8MHz_internal custom board option. In addition to flashing the bootloader, this command also sets the configuration fuses according to the board definition. The clock=8MHz_internal custom board option does three things:
Selects the configuration fuses for using the microcontroller's internal RC oscillator
Selects the bootloader that is compiled for an 8 MHz clock
Hi, @ptillisch
Thanks a lot for providing many informations.
I try to understand the information and use arduino-cli compile --fqbn MiniCore:avr:328 --board-options "clock=8MHz_internal"
But it returns that "can not find MiniCore:avr platform, the platform is not installed", I searched in the document of arduino-cli, but ... failed, how to solve it?
P.S. my computer os is win10.
Hi, @ptillisch
The information you provided is very clear and easy to understand, according to the instructions you provided, I solve all the problems and my board works very well.
By the way, I want to shield the information generated by the command:
namely, make all the information which generated after compiling, such as : xxx byte (xx%) used, the max rom is xxx byte. xxx byte (xx%) used, the max ram is xxx byte.
don't display in the command window.
The output of $(ArduinoC) compile --fqbn MiniCore:avr:328 --board-options "clock=8MHz_internal" $(PRG).ino --output-dir .
and $(SIZE) $(PRG).ino.elf
are duplicated, I want to sheild the output come from arduino-cli if .