avrispmkII error

hello, as a newbe i need help in finding solution to this error when i try to upload simple avr code that already compliled success in platformio
but upon uploading i encounter this error :

 Looking for upload port...
Error: Please specify `upload_port` for environment or use global `--upload-port` option.
For some development platforms it can be a USB flash drive (i.e. /media/<user>/<device name>)
*** [upload] Explicit exit, status 1  "
 and this 
" Configuring upload protocol...
AVAILABLE: custom
CURRENT: upload_protocol = custom
Uploading .pio\build\program_via_AVRISP_mkII\firmware.hex
avrdude: can't open config file " /tool-avrdude/avrdude.conf": No such file or directory
avrdude: error reading system wide configuration file " /tool-avrdude/avrdude.conf"
*** [upload] Error 1
========================================== [FAILED] Took 2.84 seconds ==========================================

Environment              Status    Duration
-----------------------  --------  ------------
ATmega16                 FAILED    00:00:05.967
program_via_AVRISP_mkII  FAILED    00:00:02.835
===================================== 2 failed, 0 succeeded in 00:00:08.803 =====================================

here is my .ini file

[env:ATmega16]
platform = atmelavr
board = ATmega16

[env:program_via_AVRISP_mkII]
platform = atmelavr
board = ATmega16
upload_protocol = custom
upload_port = usb
upload_flags = 
    -C $PROJECT_PACKAGE_DIR/tool-avrdude/avrdude.conf
    -p $BOARD_MCU
    -p $UPLOAD_PORT
    -c avrispmkII
    -c stk500v2
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i 

i check the avrdude.conf in the directory (c:users/…tool-avrdude/avrdude.conf)and it is there but why platformio say no such file ?

Check your Env Variable PROJECT-PACKAGE-DIR.
May be it is empty. see line with can’t open… " /tool-avrdude…"
In .ini file you specify -C with this variable. try with the full path of this conf file.

You have a simple typo, this variable is called

hence the variable you access is empty, leading to a /tool-avrdude/avrdude.conf path.

hi max,
i think the avr_dude problem solved by providing full path, thanks.
but still get the “upload port error” here is the complete terminal

Processing ATmega16 (platform: atmelavr; board: ATmega16)
------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/ATmega16.html
PLATFORM: Atmel AVR (4.2.0) > ATmega16
HARDWARE: ATMEGA16 16MHz, 1KB RAM, 16KB Flash
DEBUG: Current (simavr) External (simavr)
PACKAGES:
 - tool-avrdude @ 1.60300.200527 (6.3.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 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio\build\ATmega16\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.0% (used 0 bytes from 1024 bytes)   
Flash: [          ]   0.8% (used 138 bytes from 16384 bytes)
Configuring upload protocol...
AVAILABLE: arduino
CURRENT: upload_protocol = arduino
Looking for upload port...
Error: Please specify `upload_port` for environment or use global `--upload-port` option.
For some development platforms it can be a USB flash drive (i.e. /media/<user>/<device name>)
*** [upload] Explicit exit, status 1
=========================================== [FAILED] Took 5.01 seconds ===========================================
Environment    Status    Duration
-------------  --------  ------------
ATmega16       FAILED    00:00:05.008
===================================== 1 failed, 0 succeeded in 00:00:05.008 ===================================== 

 *  The terminal process "C:\Users\awadjafar\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload', '--environment', 'ATmega16'" terminated with exit code: 1.

my platformio.ini already specify p

[env:ATmega16]
platform = atmelavr
board = ATmega16

[env:program_via_AVRISP_mkII]
platform = atmelavr
board = ATmega16
upload_protocol = custom
upload_port = usb
upload_flags = 
    -C \Users\awadjafar\.platformio\packages\tool-avrdude\avrdude.conf 
    -p $BOARD_MCU
    -p $UPLOAD_PORT 
    -c avrispmkII
    -c stk500v2
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

when i check “windows device manager” the avrispmk2 connected and works.
why i get upload_port error above ?
thanks

How can that be two protocols at the same time? That doesn’t make sense. It’s either an avrispmkii or a stk500v2.

As you can see when you set board = ATmega16 it pulls the upload settings from

and it requires an upload port in its default configuration. Now if you have a USB programmer that does not show up as a COM port but only as some USB HID device or whatever, then it doesn’t make sense to wait for a COM port. So just add

board_upload.require_upload_port = no

to the platformio.ini to override that.

hi max,
thanks for the help, as a newbie here, i am confuse how should my platformio.ini looks like because don’t know where to put the command “board_upload.require_upload_port = no” , i have tried different places but still get error

[env:program_via_AVRISP_mkII]
platform = atmelavr
board = ATmega16
upload_protocol = custom
upload_port = usb
board_upload.require_upload_port = no
upload_flags = 
    -C \Users\awadjafar\.platformio\packages\tool-avrdude\avrdude.conf 
    -p $BOARD_MCU
    -p $UPLOAD_PORT 
    -c avrispmkII
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

i also try to remove “upload_port = usb” and “-p $upload_port” but still get the error.
thanks

The same error? Can you post it in full?

hi max, here is my .ini file

[env:ATmega16]
platform = atmelavr
board = ATmega16

[env:program_via_AVRISP_mkII]
platform = atmelavr
board = ATmega16
upload_protocol = custom
upload_port = usb
board_upload.require_upload_port = no
upload_flags = 
    -C 
    \Users\awadjafar\.platformio\packages\tool-avrdude\avrdude.conf 
    -p 
    $BOARD_MCU
    -p 
    $UPLOAD_PORT 
    -c 
    avrispmkII
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

and here is the error that i get

Processing ATmega16 (platform: atmelavr; board: ATmega16)
---------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/ATmega16.html
PLATFORM: Atmel AVR (4.2.0) > ATmega16
HARDWARE: ATMEGA16 16MHz, 1KB RAM, 16KB Flash
DEBUG: Current (simavr) External (simavr)
PACKAGES:
 - tool-avrdude @ 1.60300.200527 (6.3.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 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio\build\ATmega16\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.2% (used 2 bytes from 1024 bytes)    
Flash: [=         ]  10.6% (used 1730 bytes from 16384 bytes)
Configuring upload protocol...
AVAILABLE: arduino
CURRENT: upload_protocol = arduino
Looking for upload port...
Error: Please specify `upload_port` for environment or use global `--upload-port` option.
For some development platforms it can be a USB flash drive (i.e. /media/<user>/<device name>)
*** [upload] Explicit exit, status 1
============================================ [FAILED] Took 4.74 seconds ============================================ 

Processing program_via_AVRISP_mkII (platform: atmelavr; board: ATmega16)
---------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/ATmega16.html
PLATFORM: Atmel AVR (4.2.0) > ATmega16
HARDWARE: ATMEGA16 16MHz, 1KB RAM, 16KB Flash
DEBUG: Current (simavr) External (simavr)
PACKAGES:
 - tool-avrdude @ 1.60300.200527 (6.3.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 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio\build\program_via_AVRISP_mkII\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.2% (used 2 bytes from 1024 bytes)
Flash: [=         ]  10.6% (used 1730 bytes from 16384 bytes)
Configuring upload protocol...
AVAILABLE: custom
CURRENT: upload_protocol = custom
Uploading .pio\build\program_via_AVRISP_mkII\firmware.hex
avrdude: AVR Part "usb" not found.

Valid parts are:
  uc3a0512 = AT32UC3A0512
  c128     = AT90CAN128
  c32      = AT90CAN32
  c64      = AT90CAN64
  pwm2     = AT90PWM2
  pwm216   = AT90PWM216
  pwm2b    = AT90PWM2B
  pwm3     = AT90PWM3
  pwm316   = AT90PWM316
  pwm3b    = AT90PWM3B
  1200     = AT90S1200
  2313     = AT90S2313
  2333     = AT90S2333
  2343     = AT90S2343
  4414     = AT90S4414
  4433     = AT90S4433
  4434     = AT90S4434
  8515     = AT90S8515
  8535     = AT90S8535
  usb1286  = AT90USB1286
  usb1287  = AT90USB1287
  usb162   = AT90USB162
  usb646   = AT90USB646
  usb647   = AT90USB647
  usb82    = AT90USB82
  m103     = ATmega103
  m128     = ATmega128
  m1280    = ATmega1280
  m1281    = ATmega1281
  m1284    = ATmega1284
  m1284p   = ATmega1284P
  m1284rfr2 = ATmega1284RFR2
  m128rfa1 = ATmega128RFA1
  m128rfr2 = ATmega128RFR2
  m16      = ATmega16
  m161     = ATmega161
  m162     = ATmega162
  m163     = ATmega163
  m164a    = ATmega164A
  m164p    = ATmega164P
  m164pa   = ATmega164PA
  m168     = ATmega168
  m168p    = ATmega168P
  m168pb   = ATmega168PB
  m169     = ATmega169
  m16u2    = ATmega16U2
  m2560    = ATmega2560
  m2561    = ATmega2561
  m2564rfr2 = ATmega2564RFR2
  m256rfr2 = ATmega256RFR2
  m32      = ATmega32
  m324a    = ATmega324A
  m324p    = ATmega324P
  m324pa   = ATmega324PA
  m324pb   = ATmega324PB
  m325     = ATmega325
  m3250    = ATmega3250
  m328     = ATmega328
  m328p    = ATmega328P
  m328pb   = ATmega328PB
  m329     = ATmega329
  m3290    = ATmega3290
  m3290p   = ATmega3290P
  m329p    = ATmega329P
  m32m1    = ATmega32M1
  m32u2    = ATmega32U2
  m32u4    = ATmega32U4
  m406     = ATMEGA406
  m48      = ATmega48
  m48p     = ATmega48P
  m48pb    = ATmega48PB
  m64      = ATmega64
  m640     = ATmega640
  m644     = ATmega644
  m644a    = ATmega644A
  m644p    = ATmega644P
  m644pa   = ATmega644PA
  m644rfr2 = ATmega644RFR2
  m645     = ATmega645
  m6450    = ATmega6450
  m649     = ATmega649
  m6490    = ATmega6490
  m64rfr2  = ATmega64RFR2
  m8       = ATmega8
  m8515    = ATmega8515
  m8535    = ATmega8535
  m88      = ATmega88
  m88p     = ATmega88P
  m88pb    = ATmega88PB
  m8u2     = ATmega8U2
  t10      = ATtiny10
  t11      = ATtiny11
  t12      = ATtiny12
  t13      = ATtiny13
  t13a     = ATtiny13a
  t15      = ATtiny15
  t1634    = ATtiny1634
  t167     = ATtiny167
  t20      = ATtiny20
  t2313    = ATtiny2313
  t24      = ATtiny24
  t25      = ATtiny25
  t26      = ATtiny26
  t261     = ATtiny261
  t28      = ATtiny28
  t4       = ATtiny4
  t40      = ATtiny40
  t4313    = ATtiny4313
  t43u     = ATtiny43u
  t44      = ATtiny44
  t441     = ATtiny441
  t45      = ATtiny45
  t461     = ATtiny461
  t48      = ATtiny48
  t5       = ATtiny5
  t84      = ATtiny84
  t841     = ATtiny841
  t85      = ATtiny85
  t861     = ATtiny861
  t87      = ATtiny87
  t88      = ATtiny88
  t9       = ATtiny9
  x128a1   = ATxmega128A1
  x128a1d  = ATxmega128A1revD
  x128a1u  = ATxmega128A1U
  x128a3   = ATxmega128A3
  x128a3u  = ATxmega128A3U
  x128a4   = ATxmega128A4
  x128a4u  = ATxmega128A4U
  x128b1   = ATxmega128B1
  x128b3   = ATxmega128B3
  x128c3   = ATxmega128C3
  x128d3   = ATxmega128D3
  x128d4   = ATxmega128D4
  x16a4    = ATxmega16A4
  x16a4u   = ATxmega16A4U
  x16c4    = ATxmega16C4
  x16d4    = ATxmega16D4
  x16e5    = ATxmega16E5
  x192a1   = ATxmega192A1
  x192a3   = ATxmega192A3
  x192a3u  = ATxmega192A3U
  x192c3   = ATxmega192C3
  x192d3   = ATxmega192D3
  x256a1   = ATxmega256A1
  x256a3   = ATxmega256A3
  x256a3b  = ATxmega256A3B
  x256a3bu = ATxmega256A3BU
  x256a3u  = ATxmega256A3U
  x256c3   = ATxmega256C3
  x256d3   = ATxmega256D3
  x32a4    = ATxmega32A4
  x32a4u   = ATxmega32A4U
  x32c4    = ATxmega32C4
  x32d4    = ATxmega32D4
  x32e5    = ATxmega32E5
  x384c3   = ATxmega384C3
  x384d3   = ATxmega384D3
  x64a1    = ATxmega64A1
  x64a1u   = ATxmega64A1U
  x64a3    = ATxmega64A3
  x64a3u   = ATxmega64A3U
  x64a4    = ATxmega64A4
  x64a4u   = ATxmega64A4U
  x64b1    = ATxmega64B1
  x64b3    = ATxmega64B3
  x64c3    = ATxmega64C3
  x64d3    = ATxmega64D3
  x64d4    = ATxmega64D4
  x8e5     = ATxmega8E5
  ucr2     = deprecated, use 'uc3a0512'

*** [upload] Error 1
============================================ [FAILED] Took 2.81 seconds ============================================ 

Environment              Status    Duration
-----------------------  --------  ------------
ATmega16                 FAILED    00:00:04.739
program_via_AVRISP_mkII  FAILED    00:00:02.807
======================================= 2 failed, 0 succeeded in 00:00:07.546 =======================================

Part is -p, Port is -P. replace the second -p with -P. You can also see that in the documentation.

hi max,
I get BSOD and reset my PC after i change

    -p 
    $BOARD_MCU
    -P 
    $UPLOAD_PORT

propably problem with some sort of DLL.