platformio / platform-atmelmegaavr

Atmel megaAVR: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelmegaavr
Apache License 2.0
29 stars 22 forks source link

Add AVR-Dx support to fuses.py script #20

Closed MCUdude closed 2 years ago

MCUdude commented 3 years ago

This is a work in progress and has not yet been tested properly due to #18 hasn't been merged or considered merged yet. I'm submitting this PR to hopefully speed up AVR-DA/DB integration.

MCUdude commented 2 years ago

@valeros I've now reviewed the script again and added support for the multi-voltage IO support fuse present on AVR-DB's. Please review so this can hopefully be merged.

MCUdude commented 2 years ago

There's one thing that would be nice to resolve though.

In #34 one can't use the on-board programmer on the Nano Every to set fuses, since it requires a 1200bps touch to enable programming mode, and the fuses.py script doesn't currently support this. How can this be accomplished "properly"?

As a proof of concent, I've added the following code at the bottom of the script, right before the Avrdude command gets invoked. @valeros please let me know if there is a better way!

from platformio.util import get_serial_ports

#...
#...
#...

print_fuses_info(fuse_values, fuse_names, lock_fuse)

upload_options = env.BoardConfig().get("upload", {})

if upload_options.get("use_1200bps_touch", False):
    before_ports = get_serial_ports()
    env.AutodetectUploadPort()
    env.Append(UPLOADERFLAGS=["-P", '"$UPLOAD_PORT"'])
    env.TouchSerialPort("$UPLOAD_PORT", 1200)
    if upload_options.get("wait_for_upload_port", True):
        env.Replace(UPLOAD_PORT=env.WaitForNewSerialPort(before_ports))

fuses_action = env.VerboseAction("$SETFUSESCMD", "Setting fuses...")

Return("fuses_action")
MCUdude commented 2 years ago

I guess this PR can be merged as it is, and the 1200bps touch issue can be solved as a separate issue/PR

valeros commented 2 years ago

Thanks for the PR, please do open a separate topic.