1

I am interested in learning how the Arduino IDE handles parameters in order to correctly upload hex files with avrdude.

I found this in boards.txt:

uno.name=Arduino/Genuino Uno

uno.vid.0=0x2341
uno.pid.0=0x0043
uno.vid.1=0x2341
uno.pid.1=0x0001
uno.vid.2=0x2A03
uno.pid.2=0x0043
uno.vid.3=0x2341
uno.pid.3=0x0243

uno.upload.tool=avrdude
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
uno.upload.maximum_data_size=2048
uno.upload.speed=115200

uno.bootloader.tool=avrdude
uno.bootloader.low_fuses=0xFF
uno.bootloader.high_fuses=0xDE
uno.bootloader.extended_fuses=0x05
uno.bootloader.unlock_bits=0x3F
uno.bootloader.lock_bits=0x0F
uno.bootloader.file=optiboot/optiboot_atmega328.hex

uno.build.mcu=atmega328p
uno.build.f_cpu=16000000L
uno.build.board=AVR_UNO
uno.build.core=arduino
uno.build.variant=standard

There is this in platform.txt:

# AVR Uploader/Programmers tools
# ------------------------------

tools.avrdude.path={runtime.tools.avrdude.path}
tools.avrdude.cmd.path={path}/bin/avrdude
tools.avrdude.config.path={path}/etc/avrdude.conf

tools.avrdude.upload.params.verbose=-v
tools.avrdude.upload.params.quiet=-q -q
tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} -p{build.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"

tools.avrdude.program.params.verbose=-v
tools.avrdude.program.params.quiet=-q -q
tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i"

tools.avrdude.erase.params.verbose=-v
tools.avrdude.erase.params.quiet=-q -q
tools.avrdude.erase.pattern="{cmd.path}" "-C{config.path}" {erase.verbose} -p{build.mcu} -c{protocol} {program.extra_params} -e -Ulock:w:{bootloader.unlock_bits}:m -Uefuse:w:{bootloader.extended_fuses}:m -Uhfuse:w:{bootloader.high_fuses}:m -Ulfuse:w:{bootloader.low_fuses}:m

tools.avrdude.bootloader.params.verbose=-v
tools.avrdude.bootloader.params.quiet=-q -q
tools.avrdude.bootloader.pattern="{cmd.path}" "-C{config.path}" {bootloader.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{runtime.platform.path}/bootloaders/{bootloader.file}:i" -Ulock:w:{bootloader.lock_bits}:m

This line is particularly interesting:

tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} -p{build.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"

It seems like these variables are corresponding:

{cmd.path} --> tools.avrdude.cmd.path
{config.path} --> tools.avrdude.config.path
{upload.verbose} --> tools.avrdude.upload.params.verbose
{build.mcu} --> uno.build.mcu
{upload.protocol} --> uno.upload.protocol
{serial.port} --> ?
{upload.speed} --> uno.upload.speed
{build.path} --> ?
{build.project_name} --> ?

It seems these are likely used in the Java code for the IDE. There are obviously a few I am unsure of. I would guess these are considered user inputs in the IDE. Though I am by no means a Java or JavaScript programmer.

Where are these variables explicitly defined in the Arduino library? (e.g. {runtime.tools.avrdude.path}, {path}, {cmd.path} ....) Or how do they get defined by IDE?

2
  • where can I find, Boards.txt Platform.txt programmers.txt file. I use - Mac Mojave 10.14.6 Arduino iDE - 1.8.12 When I run the data logger code (to save in SD card) I am getting /Users/placidafernando/Library/Caches/Homebrew Error. I reinstalled Brew and Avrdude. I. see it has installed under when I look via Terminal. Cannot see from MAC apple man /Users/myUserID/Library/Caches/Homebrew But my sketch and Arduino is in /Documents libraries Following message is due to IDE or Arduino-CLI unable to fine the avrdude.tar file in the current directory? I am npt a big mac user. How can I set the path Jan 31, 2021 at 7:30
  • @ShaunChristianFernando you should probably just ask your own question.
    – wgwz
    Feb 1, 2021 at 15:46

2 Answers 2

1

There are 3(or 4) places that you need to look at to know how to upload.
There is the boards.txt file and the platform.txt file.
You can consider a platform.txt file line

tools.avrdude.path={runtime.tools.avrdude.path}

as (in linux in windows replace ${xx} by %xx%)

set tools.avrdude.path ${runtime.tools.avrdude.path}

and the board.txt for the selected board like

uno.bootloader.tool=avrdude

as

set bootloader.tool avrdude

The arduino ide uses the following string to know the upload command environment variable

tools.${bootloader.tool}.upload.pattern

This way it knows the command to upload is

"{cmd.path}" "-C{config.path}" {upload.verbose} -p{build.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"

{cmd.path} is hardcoded as tools.${bootloader.tool}.cmd.path which equals {path}/bin/avrdude
where {path} is to be understood as tools.${bootloader.tool}.path wich equals {runtime.tools.avrdude.path}.
{runtime.tools.avrdude.path} is defined by the boardsmanager based n the json file and the location where the boardsmanager extracted the download.

So that makes 3 files: boards.txt, platform.txt and json file and some hard coding.

A 4th file comes into play when you use the "other upload commands". These are located in the programmers.txt file.

IMHO Arduino IDE core team did not opt for the simplest solution to define these things. They also change the way they work from time to time.
If you use a makefile know that a lot of people have done this already so it may be a good idea to "reuse other peoples work" instead of "reinventing the wheel". It is not so easy or straightforward.

Note I know all these things because I implemented the Arduino eclipse IDE. As far as I know none of this is documented.

-1

The Arduino library is about what runs on the target, while the "IDE" (not sure if it can still be called IDE, as now they try to do also command line) is about everything else.

But my impression is that if you are ready to ask these sort of question, you could consider dropping the IDE and moving to a more standard Makefile approach. Or Maybe Eclipse, where you still have the IDE, but you can define everything in a more standard way.

The Arduino approach is good to get people with little experienced started, but after a while one started to feel its limitations.

10
  • I've used a makefile approach. So I am now interested in finding out how and where the parameters that get sent to avrdude are defined. More specifically the variables involved in tools.avrdude.upload.pattern.
    – wgwz
    Nov 2, 2015 at 15:45
  • Not sure I understand you. Do you want to know how to invoke avrdude by replicating what the IDE does? Nov 2, 2015 at 17:08
  • I want to know how to choose the parameters that need to be sent to the avrdude program for a given board type. I have found where the flags are settools.avrdude.upload.pattern. I am unsure of how they are set. Please see the block in my post with arrows signifying "corresponding". All the variables prefixed with uno, I understand where those values come from (boards.txt). But the variables prefixed with tools and the ? marks, I am unsure of where those are defined. I would like to know where those are defined.
    – wgwz
    Nov 2, 2015 at 17:24
  • Ok, my bad, I should have asked an open question. Next try: what are you trying to achieve with this? Why do you want to know this? Nov 2, 2015 at 18:38
  • I want to know this because I want wrap the Arduino C library for use with Python. I want to know this because it is part of the design for how the wrapper would work, i.e. the upload process.
    – wgwz
    Nov 2, 2015 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.