Hi,
my first post - prologue: many years ago I did my last Atmel projects with WinAVR in the Windows world. The last years I moved to macOS and spent some time with Raspberries, ESP8266 and discovered atom.io with the PlatformIO package. I also played a little bit with an Arduino uno. However some things a easier for me with “traditional” gcc Atmel programming.
I have atom set up on my Mac with PIO and the needed platforms (Atmel AVR and Espressif 8266). I can run a blink LED on my arduino or do the Sonoff S20 Tasmota software and everything is fine.
This weekend I tried to set up PlatformIO for standalone Atmel development. For programming I use an Atmel AVR ISP mkII (usb) programmer on my mac.
I’ve checked the physical toolchain with a parallels Windows / Atmel Studio 7 - everything fine and working.
Then I did my first blink LED from the examples on a ATmega8. I soon learned that I have to use the ‘program’ target for flash programming. After some struggling with the fuse fix in avrdude on the mega8 (programming was OK, but error messages due to missing efuse…) I read the documentation about extra_scripts and tried to follow the examples. However it ends up with two problems, when I try to replace the ‘upload’ target, or set up a ‘uploadeep’ or ‘fuses’ target, following the documentation or some other posts here.
When calling ‘pio run -t fuses’ the process stops because I have either not specified ‘upload_port’ or ‘-P usb’ has not be opened.
I also have seen that the modified environment settings for UPLOADHEXCMD or FUSESCMD seem only to live inside the external script?!
Any hints?
Some excerpts from my files an the corresponding output:
platformio.ini
[platformio]
env_default = baremetal
[common_env_data]
platform = atmelavr
board_mcu = atmega8
board_f_cpu = 8000000L
[env:baremetal]
extra_scripts = pre:extra_script_pre.py, post:extra_script_post.py
custom_option = hello
platform = ${common_env_data.platform}
board_mcu = ${common_env_data.board_mcu}
board_f_cpu = ${common_env_data.board_f_cpu}
upload_protocol = stk500v2
upload_flags = -P usb -e -v
upload_port = -P usb
extra_script_pre.py
Import('env')
print " ********************** pre:extra_script_pre.py ***********************"
print "before"
#print env["UPLOADHEXCMD"]
#print env["FUSESCMD"]
#env.Replace(UPLOADHEXCMD="$UPLOADER $UPLOADERFLAGS -U flash:w:$SOURCES:i")
env.Replace(UPLOADHEXCMD="avrdude -Pusb -pm8 -cavrispmkii -U flash:w:$SOURCES:i")
env.Replace(FUSESCMD="avrdude $UPLOADERFLAGS -Ulock:w:0x3F:m -Uhfuse:w:0xD9:m -Ulfuse:w:0xA4:m")
print "after"
# uncomment line below to see environment variables
#print " ********************** pre:extra_script_pre.py ***********************"
print env["UPLOADHEXCMD"]
print env["FUSESCMD"]
#print "-"
#print env.Dump()
print " ********************** pre:extra_script_pre.py ***********************"
extra_script_post.py
Import('env')
#env.Replace(UPLOADHEXCMD='$UPLOADER $UPLOADERFLAGS -U flash:w:$SOURCES:i');
#env.Replace(FUSESCMD="avrdude $UPLOADERFLAGS -Ulock:w:0x3F:m -Uhfuse:w:0xD9:m -Ulfuse:w:0xA4:m");
# uncomment line below to see environment variables
print " ********************** post:extra_script_post.py *********************"
print env["UPLOADHEXCMD"]
print env["FUSESCMD"]
#print "-"
#print env.Dump()
print " ********************** post:extra_script_post.py *********************"
Output excerpts: follow…
Edited for better readability (02/15/18)