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. Redirecting...

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.

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).

I had the same issue in Windows 11 + Visual Studio Code + Platformio and with upload_port = /dev/null it works with an arduino as isp. This is my platformio.ini:

[env:ATmega328P]
platform = atmelavr
board = ATmega328P
framework = arduino
board_build.mcu = atmega328p
board_build.f_cpu = 2000000L
upload_port = /dev/null
upload_command = avrdude -v -v -c avrisp -e -p atmega328p -P COM8 -b 19200 -U flash:w:$SOURCE:i

With upload_port = /dev/null:

Processing ATmega328P (platform: atmelavr; board: ATmega328P; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/ATmega328P.html
PLATFORM: Atmel AVR (4.2.0) > ATmega328P/PA
HARDWARE: ATMEGA328P 2MHz, 2KB RAM, 32KB Flash
DEBUG: Current (avr-stub) External (avr-stub, simavr)
PACKAGES:
 - framework-arduino-avr-minicore @ 2.2.2
 - tool-avrdude @ 1.70100.0 (7.1.0)
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 8 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio\build\ATmega328P\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.4% (used 9 bytes from 2048 bytes)
Flash: [          ]   2.7% (used 870 bytes from 32256 bytes)
Configuring upload protocol...
AVAILABLE: avrisp
CURRENT: upload_protocol = avrisp
Looking for upload port...
Using manually specified: /dev/null
Uploading .pio\build\ATmega328P\firmware.hex

avrdude: Version 7.1-arduino.1
         Copyright the AVRDUDE authors;
         see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

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

         Using Port                    : COM8
         Using Programmer              : avrisp
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : possible i/o
         RETRY pulse                   : SCK
         Serial program mode           : yes
         Parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                           Block Poll               Page                       Polled
           Memory Type Alias    Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom                 65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash                  65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
           hfuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
           efuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
           lock                    0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
           signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00
           calibration             0     0     0    0 no          1    1      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel AVR ISP
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.04s

avrdude: device signature = 0x1e950f (probably m328p)
avrdude: erasing chip
avrdude: reading input file .pio\build\ATmega328P\firmware.hex for flash
         with 870 bytes in 1 section within [0, 0x365]
         using 7 pages and 26 pad bytes
avrdude: writing 870 bytes flash ...

Writing | avrdude: padding flash [0x0300, 0x037f]
################################################## | 100% 1.21s

avrdude: 870 bytes of flash written
avrdude: verifying flash memory against .pio\build\ATmega328P\firmware.hex
avrdude: reading on-chip flash data ...

Reading | ################################################## | 100% 0.67s

avrdude: verifying ...
avrdude: 870 bytes of flash verified

avrdude done.  Thank you.

Without it:

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/ATmega328P.html
PLATFORM: Atmel AVR (4.2.0) > ATmega328P/PA
HARDWARE: ATMEGA328P 2MHz, 2KB RAM, 32KB Flash
DEBUG: Current (avr-stub) External (avr-stub, simavr)
PACKAGES:
 - framework-arduino-avr-minicore @ 2.2.2
 - tool-avrdude @ 1.70100.0 (7.1.0)
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 8 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio\build\ATmega328P\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.4% (used 9 bytes from 2048 bytes)
Flash: [          ]   2.7% (used 870 bytes from 32256 bytes)
Configuring upload protocol...
AVAILABLE: avrisp
CURRENT: upload_protocol = avrisp
Looking for upload port...
Auto-detected: COM8
Uploading .pio\build\ATmega328P\firmware.hex

avrdude: Version 7.1-arduino.1
         Copyright the AVRDUDE authors;
         see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

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

         Using Port                    : COM8
         Using Programmer              : avrisp
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : possible i/o
         RETRY pulse                   : SCK
         Serial program mode           : yes
         Parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                           Block Poll               Page                       Polled
           Memory Type Alias    Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom                 65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash                  65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
           hfuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
           efuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
           lock                    0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
           signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00
           calibration             0     0     0    0 no          1    1      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel AVR ISP
         Hardware Version: 2
         Firmware Version: 1.16
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.05s

avrdude: device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.05s

avrdude: device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.05s

avrdude: device signature = 0x000000
avrdude main() error: Yikes!  Invalid device signature.
avrdude main() error: expected signature for ATmega328P is 1E 95 0F
        Double check connections and try again, or use -F to override
        this check.


avrdude done.  Thank you.

*** [upload] Error 1