PlatformIO Community

Dragon_isp programming

Hello, I have an AVR dragon board and would like to use that to program my chip. I have the project working with a usbtiny that I have so I believe the project is setup properly except for the configuration for the programmer. I created a new environment for the dragon and this is what I came up with:

[env:bare_dragon]
platform = atmelavr
board_build.mcu = atmega328p
board_build.f_cpu = 1000000L
upload_protocol = dragon_isp
upload_flags = -Pusb

when I try to run pio run -t upload it gives the error:

Error: Please specify upload_port for environment or use global --upload-port option.

If I specify the port (instead of upload_flags):

[env:bare_dragon]
platform = atmelavr
board_build.mcu = atmega328p
board_build.f_cpu = 1000000L
upload_protocol = dragon_isp
upload_port = usb

I get this error:

Looking for upload port…
Use manually specified: usb
*** [upload] could not open port usb: [Errno 2] No such file or directory: ‘usb’

If I run avrdude directly, this works:

./avrdude -C ../avrdude.conf -c dragon_isp -p m328p -P usb -U flash:w:firmware.hex

I’m running PlatformIO IDE on Visual Studio on Mac OS 10.15.5 but have recreated the problem on the command line using pio version 4.3.4.

Is it possible to use the avr dragon board? If so, I would appreciate tips on the proper configuration.

Thanks
Jay

The problem here is that PIO still wants to attempt to use a upload disk / serial with a -P switch.

What happens when you set upload_port = COM1 for fun, even if it’s not existing?

1 Like
CURRENT: upload_protocol = dragon_isp
Looking for upload port...
Use manually specified: COM1
*** [upload] could not open port COM1: [Errno 2] No such file or directory: 'COM1'

Okay not that easy to trick. Let me look for a better solution.

Can you again try it with a COM port that actually exists on the machine (see Windows device manageR). Again this just a workaround for a bug…

…and to anticipate your next question, I tried port /dev/null which does exist:

CURRENT: upload_protocol = dragon_isp
Looking for upload port...
Use manually specified: /dev/null
Uploading .pio/build/junk/firmware.hex
avrdude: ser_open(): can't set attributes for device "/dev/null": Inappropriate ioctl for device

In this case, it passes my -P from upload flags and -P/dev/null to avrdude.

Can you please add to the platformio.ini:

board_upload.require_upload_port = false

(or False maybe) and remove any previous upload_port = .. directive.

[env:testing]
platform = atmelavr
board_build.mcu = atmega328p
board_build.f_cpu = 1000000L
upload_protocol = dragon_isp
board_upload.require_upload_port = false
upload_flags = -Pusb

I tried false and False. I got the same error for both:

Error: Please specify upload_port for environment or use global --upload-port option.

Thanks
Jay

It seems I’m the only one who wants to do this. But some day, someone will want to know how to do it, so here is what I came up with:

[env:bare_dragon]
platform = atmelavr
board_build.mcu = atmega328p
board_build.f_cpu = 1000000L
upload_protocol = dragon_isp
upload_port = /dev/null

upload_flags =
    -e
    -C
    $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
    -p
    atmega328p
    -P
    usb
    -c
    dragon_isp
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

You should get the same effect as upload_port = /dev/null with upload_port = custom FWIW.

Do you have more luck if you use the programmer specific target? i.e. -t program ?

Thank you. Where is upload_port = custom documented? I read the documentation and didn’t see that option but maybe I looked in the wrong place. I’ll try it at some point.

I don’t know what you mean by more luck. Does -t program use different configuration than what’s in the platformio.ini file?

Since custom, is well, custom, it’s not with the normal documentation, since you’re not supposed to use it unless you’re basically overriding all the upload commands. https://docs.platformio.org/en/latest/projectconf/advanced_scripting.html#custom-upload-tool

It -t program target doesn’t using a different configuration, it just behaves differently. There is no need to specify upload_port (which this there is with the upload target, since that expects you to be working with serial, i.e. atmega328p bootloader), or even upload_flags if you don’t want them to be different from what is used by default.

e.g.

avrdude -v -p atmega328p -C C:\Users\Peter\.platformio\packages\tool-avrdude\avrdude.conf -c dragon_isp -U flash:w:.pio\build\testing\firmware.hex:i

In other words, since -D is not specified (it is for upload, but not for program), you don’t need -e, the -C config path is auto-generated, the part is specified automatically, the programmer port is filled, I’m not sure if the -P is needed in this instance. If it isn’t , you don’t need anything more than upload_protocol = dragon_isp in the platformio.ini since avrdude uses the usb port by default for that programmer configuration. If you need to add flags to the upload/program command, that’s when you can add upload_flags again.

I still don’t see in the documentation link you gave me where custom is a special value for upload_port.

I’m going to leave my configuration the way it is since it works and it works with the platformIO ide without changing the upload task to program and all that.

Feel free to delete this thread so people don’t configure things incorrectly like I’m doing if you like.

Thanks
Jay

No, there’s no need to delete any threads.

That was my mistake there… that documentation link was for upload_protocol, not upload_port.

For upload port, it needs to be a valid value for the avrdude -P parameter.

If it works for you, great. I’m just suggesting that’s the hard way to do it. :wink: With just

[env:testing]
platform = atmelavr
board_build.mcu = atmega328p
board_build.f_cpu = 1000000L
upload_protocol = dragon_isp

using the program target, instead of upload, avrdude tries to run, but since I don’t have a dragon_isp, it can’t find it.

image

Again, but in verbose mode so you can see the command used to run avrdude, and the output from it:

E:\Projects\PlatformIO\atmelAvr\ledBlinker>pio run -t program -v
Processing testing (platform: atmelavr; board_build.mcu: atmega328p; board_build.f_cpu: 1000000L; upload_protocol: dragon_isp)
-------------------------------------------------------------------------------------------------------------------------------------------

HARDWARE: ATMEGA328P 1MHz,
PACKAGES:
 - tool-avrdude 1.60300.190424 (6.3.0)
 - tool-micronucleus 1.200.4 (2.0)
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
MethodWrapper(["checkprogsize"], [".pio\build\testing\firmware.elf"])
<lambda>(["program"], [".pio\build\testing\firmware.hex"])
AVAILABLE: dragon_isp
CURRENT: upload_protocol = dragon_isp
avrdude -v -p atmega328p -C C:\Users\Peter\.platformio\packages\tool-avrdude\avrdude.conf -c dragon_isp -U flash:w:.pio\build\testing\firmware.hex:i

avrdude: Version 6.3, compiled on Sep 12 2016 at 17:24:16
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Peter\.platformio\packages\tool-avrdude\avrdude.conf"

         Using Port                    : usb
         Using Programmer              : dragon_isp
avrdude: usbdev_open(): did not find any USB device "usb" (0x03eb:0x2107)

avrdude done.  Thank you.

*** [program] Error 1
======================================================= [FAILED] Took 2.05 seconds =======================================================

I tried this and it works if I select Upload using Programmer. Can you tell me how to change the upload arrow in the bottom of the IDE to be Upload using Programmer? It would be very helpful if the IDE worked the same way in this project as it does in other projects.

Thanks
Jay

I don’t know how (if you can) to do that. If you want that behaviour, better to stick with your prior configuration. The same could be done with an extra-script, but that’s unnecessary complexity, and don’t give any extra benefit in this instance.

This is where it’s probably unfortunate that two separate targets exist, instead of perhaps upload_type = (dfu|serial|programmer|other).