PlatformIO Community

AVR standalone projects


#1

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)


#2

Output excerpts:

Standard Build
$ pio run
[Sun Feb 11 19:45:54 2018] Processing baremetal (upload_protocol: stk500v2; extra_scripts: pre:extra_script_pre.py, post:extra_script_post.py; upload_flags: -P usb -e -v;
 board_f_cpu: 8000000L; platform: atmelavr; board_mcu: atmega8; custom_option: hello; upload_port: -P usb)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
********************** pre:extra_script_pre.py ***********************
before

after
avrdude -Pusb -pm8 -cavrispmkii -U flash:w:$SOURCES:i
avrdude $UPLOADERFLAGS -Ulock:w:0x3F:m -Uhfuse:w:0xD9:m -Ulfuse:w:0xA4:m
********************** pre:extra_script_pre.py ***********************
Platform: Atmel AVR ::
System: ATMEGA8 8MHz
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
Modes: Finder/chain Compatibility/light
Collected 0 compatible libraries
Scanning dependencies...
No dependencies
********************** post:extra_script_post.py *********************
$UPLOADER $UPLOADERFLAGS -D -U flash:w:$SOURCES:i
avrdude $UPLOADERFLAGS -Ulock:w:0x3F:m -Uhfuse:w:0xD9:m -Ulfuse:w:0xA4:m
********************** post:extra_script_post.py *********************
Compiling .pioenvs/baremetal/src/main.o

You can see the differences between pre/post environment?

Fuses
$ pio run -t fuses

[Sun Feb 11 19:48:48 2018] Processing baremetal (upload_protocol: stk500v2; extra_scripts: pre:extra_script_pre.py, post:extra_script_post.py; upload_flags: -P usb -e -v
; board_f_cpu: 8000000L; platform: atmelavr; board_mcu: atmega8; custom_option: hello; upload_port: -P usb)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
********************** pre:extra_script_pre.py ***********************
before
after
avrdude -Pusb -pm8 -cavrispmkii -U flash:w:$SOURCES:i
avrdude $UPLOADERFLAGS -Ulock:w:0x3F:m -Uhfuse:w:0xD9:m -Ulfuse:w:0xA4:m
********************** pre:extra_script_pre.py ***********************
Platform: Atmel AVR ::
System: ATMEGA8 8MHz
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
Modes: Finder/chain Compatibility/light
Collected 0 compatible libraries
Scanning dependencies...
No dependencies
********************** post:extra_script_post.py *********************
$UPLOADER $UPLOADERFLAGS -D -U flash:w:$SOURCES:i
avrdude $UPLOADERFLAGS -Ulock:w:0x3F:m -Uhfuse:w:0xD9:m -Ulfuse:w:0xA4:m
********************** post:extra_script_post.py *********************
Looking for upload port...
Use manually specified: -P usb
*** [fuses] could not open port -P usb: **[Errno 2] No such file or directory: '-P usb'**
======================================================================= [ERROR] Took 0.47 seconds ===

Edited for better readability (02/15/18)


#3

Do you use --target program instead of --target upload?


#4

Yes, I use --target program, and that’s working fine, after my ATmega’s fuses are configured with avrdude externally.

The example above was only to show, that overwriting the upload target was not working.

However target --fuses, target --uploadeep are not working. I get the unspecified upload_port error *** [fuses] could not open port -P usb: [Errno 2] No such file or directory: ‘-P usb’(see above)

What I want to achieve its to provide fuse programming, flash and eprom programming as different targets, or even better as one target, but thats prio 2 :wink:


#5

Please file an issue here https://github.com/platformio/platform-atmelavr/issues and provide all details.


#6

Here we go: https://github.com/platformio/platform-atmelavr/issues/88