Hi,
This is not an urgent request, because after some days I found a culprit (USB driver issue). I want to share anyway, because maybe this helps someone. Improvement suggestions below
I am using a custom PCB with an Atmega 328pb and the avrispmkII ISP, Windows 10. For mostly idiot-proofed device bringup, I like to use platformio for initially setting the fuses, burning a custom bootloader and finally uploading the initial firmware.
Following the docs on platformio.ini and the platformio guide of MCUdude the file looks currently like this:
[platformio]
# based on this example: https://github.com/MCUdude/MiniCore/blob/master/PlatformIO.md
# and https://docs.platformio.org/en/stable/platforms/atmelavr.html
# and https://github.com/platformio/platform-atmelavr/tree/develop/builder (main.py, fuses.py, bootloader.py)
#
# pio commands
# Lists targets and environments pio run --list-targets
# set fuses pio run -v -t fuses -e DIN_Relay_v2_Up_AVRISPmkII
# burn bootloader pio run -v -t bootloader -e DIN_Relay_v2_Up_AVRISPmkII
# Upload program pio run -v -t upload -e DIN_Relay_v2_Up_AVRISPmkII
#common settings
[env]
platform = atmelavr
framework = arduino
; board specifiy settings
board = atmega328pb
board_build.f_cpu = 8000000L ;# internal. select 1 or 8 MHz
# this parameters are parsed in fuses.py
board_hardware.oscillator = internal ; Oscillator type
; DIN RAIL v2: uart0 is connected to CAN Bus, uart1 to SPI (and the pin header)
board_hardware.uart = uart1 ; Set UART to use for serial upload. Must match board_bootloader.file
board_hardware.bod = 2.7v ; Set brown-out detection
board_hardware.eesave = yes ; Preserve EEPROM when uploading using programmer
board_hardware.ckout = no ; "yes" enables clock output on pin PB0
board_hardware.cfd = yes ; Enable clock failure detection. The internal 1 MHz oscillator will kick in if the external oscillator fails (only available on ATmega328PB).
board_bootloader.speed = 38400 ; Using MCUdudes recommended baud rate for 8 Mhz clock
;board_fuses.lock_bits = 0xFF ; used for target "fuses" to override these standard values: 0xFF for targets without bootloader (e.g., atmega48x, attiny...) and 0x0F for other targets
;board_bootloader.lock_bits = 0xFF ; used for target "bootloader" to override these standard values: 0xFF for targets without bootloader (e.g., atmega48x, attiny...) and 0x0F for other targets
;board_bootloader.unlock_bits = 0x3F ; used for target "bootloader" to override standard value 0x3F
; board_bootloader.file = bootloader/optiboot_flash_atmega328pb_UART1_115200_8000000L_B5.hex ; define custom bootloader file to upload. If not set, precompiled optiboot bootloaders are used based on parameters above
board_upload.speed = 38400 ; Using MCUdudes recommended baud rate for 8 Mhz clock
; use this for additional avr dude upload flags
; use up to 4x -v to increase the verbosity
; -n: No-write - disables actually writing data to the MCU (useful for debugging AVRDUDE).
; use the correct parameterisation: board_upload.extra_flags ="-n -v -v -v -v" (I don't know why this has to be like this...)
board_upload.extra_flags = "-n -v -v -v -v" # TODO: -n is activated here, so avrdude runs in simulation mode and won't change anything!!!
; BUILD OPTIONS
build_unflags = -flto ; this was in the MCUDudes example. Not sure if beneficial or required :)
build_flags =
lib_deps =
; https://github.com/mysensors-wired/MySensors#rs485_development
https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library
; https://github.com/mathertel/OneButton
monitor_port = ${env:Upload_UART.upload_port} ; Serial monitor port defined in the Upload_UART environment
monitor_speed = 38400 ; Serial monitor baud rate, depends on the baud rate for Serial in application code
[Upload_UART]
upload_protocol = stk500v1
upload_port = COM4
;upload.speed = 38400 duplicate here, or is the definition above sufficient?
[Upload_AVRISP_mkII]
upload_protocol = avrispmkII
upload_port = usb
; #build configurations
[DIN_Relay_v1]
#extend build flags from common env, otherwise they are overriden
build_flags =
-D${env.build_flags}
-DDIN_RELAY_V1_0
#extend build flags from common env, otherwise they are overriden
[DIN_Relay_v2]
build_flags =
-D${env.build_flags}
-DDIN_RELAY_V2_0
##############
# IMPORTANT! #
##############
# keep in mind the last extended env overrides all (maybe) previously set flags, so order of occurrence matters!
#ToDo: add v1 variants...
[env:DIN_Relay_v2_Up_AVRISPmkII]
extends = Upload_AVRISP_mkII, DIN_Relay_v2
[env:DIN_Relay_v2_Up_UART]
extends = Upload_UART, DIN_Relay_v2
I encountered some issues when I tried to program the fuses via
pio run -v --target fuses --environment DIN_Relay_v2_Up_AVRISPmkII
Output:
Selected fuses: [lfuse = 0xe2, hfuse = 0xd6, efuse = 0xfd]
avrdude -p atmega328pb -C "C:\Users\mkaiser\.platformio\packages\tool-avrdude\avrdude.conf" -e -c avrispmkII -Ulock:w:0x0f:m -Uhfuse:w:0xd6:m -Ulfuse:w:0xe2:m -Uefuse:w:0xfd:m
avrdude done. Thank you.
*** [fuses] Error 1
No useful error message
Then I used the avrdude version shipped with avrdudess 2.14 with the result that, version 6.3 (Sep 2016, shipped with pio) fails, but version 7.0 (current) works
Output avrdude 6.3 (pio) with verbose options
C:\Users\mkaiser\.platformio\packages\tool-avrdude> .\avrdude -v -v -v -v -p atmega328pb -C "C:\Users\mkaiser\.platformio\packages\tool-avrdude\avrdude.conf" -e -c avrispmkII -Ulock:w:0x0f:m -Uhfuse:w:0xd6:m -Ulfuse:w:0xe2:m -Uefuse:w:0xfd:m
avrdude.exe: 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\mkaiser\.platformio\packages\tool-avrdude\avrdude.conf"
Using Port : usb
Using Programmer : avrispmkII
avrdude.exe: usbdev_open(): did not find any USB device "usb" (0x03eb:0x2104)
avrdude.exe done. Thank you.
Output avrdude 7.0 (my AvrDudess installation)
E:\FFS\git_ffs\tools\AVRDUDESS-2.14-portable> .\avrdude -v -v -v -v -p atmega328pb -C "C:\Users\mkaiser\.platformio\packages\tool-avrdude\avrdude.conf" -e -c avrispmkII -Ulock:w:0x0f:m -Uhfuse:w:0xd6:m -Ulfuse:w:0xe2:m -Uefuse:w:0xfd:m
sys_config = C:\Users\mkaiser\.platformio\packages\tool-avrdude\avrdude.conf
sys_config_found = false
avrdude.exe: Version 7.0
Copyright (c) Brian Dean, http://www.bdmicro.com/
Copyright (c) Joerg Wunsch
System wide configuration file is "C:\Users\mkaiser\.platformio\packages\tool-avrdude\avrdude.conf"
Using Port : usb
Using Programmer : avrispmkII
avrdude.exe: usbdev_open(): Found AVRISP mkII, serno: 000200129078
avrdude.exe: Sent: . [01]
avrdude.exe: Recv: . [01] . [00] . [0a] A [41] V [56] R [52] I [49] S [53] P [50] _ [5f] M [4d] K [4b] 2 [32]
avrdude.exe: stk500v2_getsync(): found AVRISP mkII programmer
AVR Part : ATmega328PB
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PC2
RESET disposition : dedicated
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 :
Then I changed the USB driver of the AVR ISP mkii to libusb-win32 with zadig and the old avrdude 6.0 version worked
Now my conclusions / suggestiosn:
-
Does it make sense to upgrade the shipped avr dude within pio? Or are there known side effects?
-
Does it hurt to add some flags similar to the board_upload.extra_flags for setting fuses and flashing the bootloader? This would be helpful for debugging, e.g., to pass the --verbose arguments and maybe the “don’t touch -n flag” to avrdude
-
In my platformio.ini I passed some extra parameters for the upload configuration: board_upload.extra_flags = “-n -v -v -v -v”
Is there a way to pass these arguments in a line-by-line form (see “build_flags =”)
BR
Martin