AVRISP mk II config query

Hi, I am using PlatformIO and vsscode and with help from you folks got my arduino projects up and running. So now I’m exploring programming the ATMEL328 PU directly without arduino, following some projects in Elliot Williams MAKE AVR Programming. I’m right in the early chapters…I used an Evil Mad Science board to set the chip up ready for programming and installed WINAVR.

I have purchased a waveshare AVRISP Mk II to program the chip and looked at the PlO help pages for how to configure it and found the content below, to which I’ve added some numbered questions. Thank you for help with this.

[env:program_via_AVRISP_mkII]
platform = atmelavr
framework = arduino // 1 -why do I need arduino now? Should I put something else?
upload_protocol = custom
upload_port = usb
upload_flags =
-C
; use “tool-avrdude-megaavr” for the atmelmegaavr platform
$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
-p
$BOARD_MCU // 2 - presumably I substitute ATMEL328 instead of BOARD_MCU ?
-P
$UPLOAD_PORT // 3 - I’d put COM6 here do I leave the $ sign in place?
-c
stk500v2 // 4 - this is a development board, should I leave it in?
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i // 5 -do I need to change this?

Only if using the Arduino Language. If you are following Elliot’s examples, delete the framework line altogether.

I used the following to define my boards:

platform = atmelavr 
board = 328p16m
...

On the avrdude command line, the $BOARD_MCU will get replaced – it’s a macro. Don’t touch it.

Leave it alone. It’s another macro.

The -c option tells avrdude the type of programmer you have. Mine is “usbtiny”. I’m not sure which protocol your uses, sorry.

No.

Good luck.

Cheers,
Norm.

Thanks Norm, I’m getting errors whilst trying to compile the simple blinkled program, any ideas?
I’ll paste the blinkled code too if it helps, but I’m thinking it’s not to do with that)
P.S. I haven’t connected the AVRISP yet, perhaps I need to do that before it will compile?
thanks for help,
Paul

Platformio.ini contents:

; PlatformIO Project Configuration File


[env:ATmega328]
platform = atmelavr
board = ATmega328

[env:program_via_AVRISP_mkII]
upload_protocol = custom
upload_port = usb
upload_flags =
-C
; use “tool-avrdude-megaavr” for the atmelmegaavr platform
$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
-p
$BOARD_MCU 
-P
$UPLOAD_PORT 
-c
stk500v2 
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

Compile output:

> Executing task: C:\Users\Paul\.platformio\penv\Scripts\pio.exe run <

Traceback (most recent call last):
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\__main__.py", line 109, in main
    cli()  # pylint: disable=no-value-for-parameter
  File "c:\users\paul\.platformio\penv\lib\site-packages\click\core.py", line 829, in __call__     
    return self.main(*args, **kwargs)
  File "c:\users\paul\.platformio\penv\lib\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\commands\__init__.py", line 44, in invoke
    return super(PlatformioCLI, self).invoke(ctx)
  File "c:\users\paul\.platformio\penv\lib\site-packages\click\core.py", line 1256, in invoke
    Command.invoke(self, ctx)
  File "c:\users\paul\.platformio\penv\lib\site-packages\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\paul\.platformio\penv\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "c:\users\paul\.platformio\penv\lib\site-packages\click\decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\__main__.py", line 63, in cli
    maintenance.on_platformio_start(ctx, force, caller)
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\maintenance.py", line 45, in on_platformio_start
    telemetry.on_command()
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\telemetry.py", line 292, in on_command
    resend_backuped_reports()
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\telemetry.py", line 443, in resend_backuped_reports
    tm = app.get_state_item("telemetry", {})
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\app.py", line 187, in get_state_item
    with State() as state:
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\app.py", line 90, in __init__
    self.path = join(get_project_core_dir(), "appstate.json")
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\project\helpers.py", line 51, in get_project_core_dir
    join(get_project_dir(), "platformio.ini")
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\project\config.py", line 441, in get_instance
    instance = {"mtime": mtime, "config": ProjectConfig(path)}
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\project\config.py", line 102, in __init__
    self.read(path, parse_extra)
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\project\config.py", line 114, in read
    self._parser.read(path)
  File "C:\Users\Paul\.platformio\python3\lib\configparser.py", line 696, in read
    self._read(fp, filename)
  File "C:\Users\Paul\.platformio\python3\lib\configparser.py", line 1014, in _read
    for lineno, line in enumerate(fp, start=1):
  File "C:\Users\Paul\.platformio\python3\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 604: character maps to <undefined>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Paul\.platformio\python3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\Paul\.platformio\python3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Paul\.platformio\penv\Scripts\pio.exe\__main__.py", line 7, in <module>
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\__main__.py", line 115, in main
    maintenance.on_platformio_exception(e)
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\maintenance.py", line 89, in on_platformio_exception
    telemetry.on_exception(e)
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\telemetry.py", line 322, in on_exception
    send_exception(description, is_fatal)
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\telemetry.py", line 394, in send_exception
    mp = MeasurementProtocol()
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\telemetry.py", line 74, in __init__
    self["cid"] = app.get_cid()
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\app.py", line 252, in get_cid
    cid = get_state_item("cid")
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\app.py", line 187, in get_state_item
    with State() as state:
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\app.py", line 90, in __init__
    self.path = join(get_project_core_dir(), "appstate.json")
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\project\helpers.py", line 51, in get_project_core_dir
    join(get_project_dir(), "platformio.ini")
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\project\config.py", line 441, in get_instance
    instance = {"mtime": mtime, "config": ProjectConfig(path)}
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\project\config.py", line 102, in __init__
    self.read(path, parse_extra)
  File "c:\users\paul\.platformio\penv\lib\site-packages\platformio\project\config.py", line 114, in read
    self._parser.read(path)
  File "C:\Users\Paul\.platformio\python3\lib\configparser.py", line 696, in read
    self._read(fp, filename)
  File "C:\Users\Paul\.platformio\python3\lib\configparser.py", line 1014, in _read
    for lineno, line in enumerate(fp, start=1):
  File "C:\Users\Paul\.platformio\python3\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 604: character maps to <undefined>
The terminal process "C:\Users\Paul\.platformio\penv\Scripts\pio.exe 'run'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

Are there any weird or UTF8 characters in your username, path or folder/file names by any chance?

That is usually the cause of this error message, and compilation problems.

I’ve edited your post (moderator privilege!) To wrap listings and errors in three backticks:

```
Like this...
```

It makes it easier to read and prevents bits of text going missing.

Can you also post the code file that’s failing to compile please. Thanks.

Cheers,
Norm.

thanks Norm, I have recreated platformio from scratch by retyping from the keyboard into notepad (no cut and paste at all) and saving this as platformio.ini in the project folder. This has ceratinly improved things in terms of the volume of errors. Previously I had cut and pasted the platformio contents from the helpfile web page into the vscode editor, so that’s where the odd chars came from.
thanks,
Paul

Compiler output:

Executing task: C:\Users\Paul\.platformio\penv\Scripts\pio.exe run <

Error: Invalid 'C:\Users\Paul\Documents\PlatformIO\Projects\Blink-LED-AVR\platformio.ini' (project configuration file): 'Source contains parsing errors: 'C:\\Users\\Paul\\Documents\\PlatformIO\\Projects\\Blink-LED-AVR\\platformio.ini'
        [line 11]: '-C\n'
        [line 12]: '$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf\n'
        [line 13]: '-p\n'
        [line 14]: '$BOARD_MCU\n'
        [line 15]: '-p\n'
        [line 16]: '$UPLOAD_PORT\n'
        [line 17]: '-c\n'
        [line 18]: 'stk500v2\n''
The terminal process "C:\Users\Paul\.platformio\penv\Scripts\pio.exe 'run'" terminated with exit code: 1.

platformio.ini content:

;platformio configuration file saved from notepad

[env:ATmega328]

platform = atmelavr

board = ATmega328p

[env:program_via_AVRISP_mkII]

upload_protocol= custom

upload_port = usb

upload_flags = 

-C

$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf

-p

$BOARD_MCU

-p

$UPLOAD_PORT

-c

stk500v2

upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i 

program code:

                                                       /* Blinker Demo */

// ------- Preamble -------- //
#include <avr/io.h>                        /* Defines pins, ports, etc */
#include <util/delay.h>                     /* Functions to waste time */


int main(void) {

  // -------- Inits --------- //
  DDRB = 0b00000001;            /* Data Direction Register B:
                                   writing a one to the bit
                                   enables output. */

  // ------ Event loop ------ //
  while (1) {

    PORTB = 0b00000001;          /* Turn on first LED bit/pin in PORTB */
    _delay_ms(1000);                                           /* wait */

    PORTB = 0b00000000;          /* Turn off all B pins, including LED */
    _delay_ms(1000);                                           /* wait */

  }                                                  /* End event loop */
  return 0;                            /* This line is never reached */
}

Hi @paulskirk53,

In your platformio.ini, are the various options foravrdude, indented by 4 spaces? If not, they should be.

All options that can be spread over many lines must be indented. I’ve fallen foul of that myself.

Cheers,
Norm.

o.k., if I format platformio.ini as below (which is not the way it is formatted in the helpfile here:

https://docs.platformio.org/en/latest/platforms/atmelavr.html?highlight=avrisp#examples

it works

;platformio configuration file

[env:ATmega328]
platform = atmelavr
board = ATmega328p

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

It woud be really helpful if in the helpfile, a statement could be added to inform users about the four space rule :slightly_smiling_face:

Thanks for your help Norm, I would never have guessed this one, there’s no logic!
best
Paul

This hit me once before. There are docs on this spacing but not in the logical place. It’s documented on this page: “platformio.ini” (Project Configuration File) — PlatformIO latest documentation but not mentioned under the individual config settings themselves.

And it’s 2 spaces minimum it seems! (I use 4.)

Anyway, glad we got it sorted.

Edit Just checked Atmel AVR — PlatformIO latest documentation and the avrisp examples are indented.

Cheers,
Norm.

Hi Paul,

by the way, you can save a few bytes in your blink as follows. Replace your loop:

while (1) {

    PORTB = 0b00000001;          /* Turn on first LED bit/pin in PORTB */
    _delay_ms(1000);                                           /* wait */

    PORTB = 0b00000000;          /* Turn off all B pins, including LED */
    _delay_ms(1000);                                           /* wait */

  }

with this instead:

while (1) {

    PINB |= 0b00000001;          /* TOGGLE first LED bit/pin in PORTB */
    _delay_ms(1000);                                           /* wait */
  }

:grin:

Cheers,
Norm.

Thanks Norm, you’re right it is documented, but it would be helpful for newcomers like me to PIO to just have a comment in the examples e.g. ‘Note indentation by at least two spaces is required’, because usually spacing/ indents are good practise rather than requirements. It’s only a little thing but with a significant impact.

best wishes
Paul

1 Like

yes you’re right, I guess Elliot is catering for a wide range of experience with the examples. I have a good deal of programming experience across a number of languages, so I’ll probably skip the practicalities of the examples, I’m more interested in the coding environment for AVR, but moving away from the abstraction of Arduino. The blinkled is great for getting everything setup to the point where code upload is successful. It was all so seamless with the Arduino bootloader - connect a USB and press a button.

I’m an amateur astronomer and built my own observatory dome controlled by Arduino interfaced via the ASCOM standard to client programs, which manage observing sessions. I’ve done most of the programming including the client interface driver. Most of the arduino stuff was built on breadboard and hosted in cardboard project boxes (a nice example of how ‘temporary’ becomes permanent…). I now have to move the observatory to a new location, so I’m taking the opportunity to remodel the control stuff onto evil mad science boards and program the AVRs without Arduino. Hence the move to PIO from Arduino IDE.
thanks again for your help,
Paul

Sounds like fun to me. Astronomy is fascinating.

Have fun, take care.

Cheers,
Norm.

Hello again Norm, trying to upload code now and have this error. I checked that the avrdude.conf file does exist in the directory specified. I’ve also opened the avrdude.conf file with notepad++

thanks for help,
Paul

> Executing task: C:\Users\Paul\.platformio\penv\Scripts\pio.exe run --target upload <

Processing program_via_AVRISP_mkII (platform: atmelavr; board: ATmega328p)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/ATmega328p.html
PLATFORM: Atmel AVR (3.1.0) > ATmega328P/PA
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 32KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
 - tool-avrdude 1.60300.200527 (6.3.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
Checking size .pio\build\program_via_AVRISP_mkII\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.0% (used 0 bytes from 2048 bytes)
Flash: [          ]   0.5% (used 178 bytes from 32768 bytes)
Configuring upload protocol...
AVAILABLE: custom
CURRENT: upload_protocol = custom
Uploading .pio\build\program_via_AVRISP_mkII\firmware.hex
avrdude: can't open config file " C:\Users\Paul\.platformio\packages/tool-avrdude/avrdude.conf": Invalid argument
avrdude: error reading system wide configuration file " C:\Users\Paul\.platformio\packages/tool-avrdude/avrdude.conf"
*** [upload] Error 1
================================================================================================== [FAILED] Took 0.70 seconds ==================================================================================================
The terminal process "C:\Users\Paul\.platformio\penv\Scripts\pio.exe 'run', '--target', 'upload'" terminated with exit code: 1.

Hi Paul,

On Linux I’d be asking if the file existed or was a sym link. I recently had problems when the file was a sym link, it couldn’t be read. Then I remembered/noticed that you are on Windows. :frowning_face:

This is what I have been using to program my Duemilanove (aka 2009) with my usbTiny:

[env:2009_programmer] 
platform = atmelavr 
board = diecimilaatmega328 
framework = arduino 

;uploader = usbtinyisp 
upload_protocol = usbtiny

No command line necessary, and it worked fine. Prior to version 4.0.1, the commented out uploader line was necessary.

Do you get any further if you comment out the upload_flags and upload_command and change upload_protocol to stk500v2 instead?

I’ve noticed under v5.x.x that the docs changed to add in the new stuff, but I’ve been working with bootloaders for ages and haven’t used the programmer with the new parameters yet.

(I’m not near my laptop ATM, I’m visiting my mother in law in a care home!)

Cheers,
Norm.

thanks again Norm

I think I’ve made progress with what you’ve indicated and the error I now have may be due to the fact that the board isn’t powered. I’ll try that next. I have a LED and resistor across Vcc and ground and that’s not lit when I connect the avrisp mkII

> Executing task: C:\Users\Paul\.platformio\penv\Scripts\pio.exe run --target upload <

Processing program_via_AVRISP_mkII (platform: atmelavr; board: ATmega328p)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/ATmega328p.html
PLATFORM: Atmel AVR (3.1.0) > ATmega328P/PA
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 32KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
 - tool-avrdude 1.60300.200527 (6.3.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
Checking size .pio\build\program_via_AVRISP_mkII\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.0% (used 0 bytes from 2048 bytes)
Flash: [          ]   0.5% (used 178 bytes from 32768 bytes)
Configuring upload protocol...
AVAILABLE: avrispmkII
CURRENT: upload_protocol = avrispmkII
Looking for upload port...
Use manually specified: usb
Uploading .pio\build\program_via_AVRISP_mkII\firmware.hex

avrdude done.  Thank you.

*** [upload] Error 1

Aye, the board needs to be powered.

Cheers,
Norm.

I’ve never seen it output that less. If Norman’s suggestion doesn’t help, please run the “Advanced → Verbose Upload” upload task for possibly more output.

Thanks Max and Norm, the error remained when I powered the board, here’s a verbose output, followed by the current platformio.ini

PS C:\Users\Paul\Documents\PlatformIO\Projects\Blink-LED-AVR> C:\Users\Paul\.platformio\penv\Scripts\pio.exe run --target upload  --verbose   
Processing program_via_AVRISP_mkII (platform: atmelavr; board: ATmega328p; upload_protocol: avrispmkII; upload_port: usb; upload_flags: -C $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf, -p $BOARD_MCU, -p $UPLOAD_PORT, -c avrispmkII)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/ATmega328p.html
PLATFORM: Atmel AVR (3.1.0) > ATmega328P/PA
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 32KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
 - tool-avrdude 1.60300.200527 (6.3.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\program_via_AVRISP_mkII\firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.0% (used 0 bytes from 2048 bytes)
Flash: [          ]   0.5% (used 178 bytes from 32768 bytes)
.pio\build\program_via_AVRISP_mkII\firmware.elf  :

section                    size      addr

.data                         0   8388864

.text                       178         0

.comment                     48         0

.note.gnu.avr.deviceinfo     64         0

.debug_info                1524         0

.debug_abbrev              1442         0

.debug_line                  26         0

.debug_str                  520         0

Total                      3802
<lambda>(["upload"], [".pio\build\program_via_AVRISP_mkII\firmware.hex"])
AVAILABLE: avrispmkII
CURRENT: upload_protocol = avrispmkII
BeforeUpload(["upload"], [".pio\build\program_via_AVRISP_mkII\firmware.hex"])
Use manually specified: usb
avrdude "-C C:\Users\Paul\.platformio\packages/tool-avrdude/avrdude.conf" "-p atmega328p" "-p usb" "-c avrispmkII" -v -p atmega328p -C C:\Users\Paul\.platformio\packages\tool-avrdude\avrdude.conf -c avrispmkII -b 115200 -D -P "usb" -U flash:w:.pio\build\program_via_AVRISP_mkII\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\Paul\.platformio\packages\tool-avrdude\avrdude.conf"

         Using Port                    : usb
         Using Programmer              : avrispmkII
         Overriding Baud Rate          : 115200
avrdude: usbdev_open(): did not find any USB device "usb" (0x03eb:0x2104)

avrdude done.  Thank you.

*** [upload] Error 1

Platformio.ini:

;platformio configuration file saved from notepad

;[env:ATmega328]
;platform = atmelavr
;board = ATmega328p

[env:program_via_AVRISP_mkII]
platform = atmelavr
board = ATmega328p
upload_protocol= avrispmkII
upload_port = usb
upload_flags = 
    -C $PROJECT_PACKAGES_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

It can’t find your AVRISP mk II USB device in the system.

  1. Is the device plugged in?
  2. Do you see in the Windows device manager that looks like the programmer?
  3. In the “details” of that device and “Hardware IDs”, what are the VID and PID? Random example:
    grafik
    ==> VID=0x1022 and PID=0x145F.
  4. If the device is found has the expected VID:PID pair as shown in the log message above, can you try and use https://zadig.akeo.ie/ to load some LibUSB / WinUSB driver for that device? (Options → List all devices should be checked). Example with some random device

grafik

Also this is kinda wrong but doesn’t currently explain the error. By commenting the upload_command your upload_flags have an additive effect and you end up doubling flags. Also the -p $UPLOAD_PORT is wrong, if you want to specify the upload port it must be capital -P $UPLOAD_PORT. -p is part(number), your MCU, one above.

avrdude “-C C:\Users\Paul.platformio\packages/tool-avrdude/avrdude.conf” “-p atmega328p” “-p usb” “-c avrispmkII” -v -p atmega328p -C C:\Users\Paul.platformio\packages\tool-avrdude\avrdude.conf -c avrispmkII -b 115200 -D -P “usb” -U flash:w:.pio\build\program_via_AVRISP_mkII\firmware.hex:i