Inconsistent Problems uploading to an Adafruit M4

Most of the time I can’t upload to an Adafruit M4. I am able to upload without issue to an Adafruit M0. I see previous issues were with the M0, but that seems fixed older post on M0

Currently my issue is with the M4, which is a samd51. There is code inthe .platformio/platforms/atmelsam/builder/main.py that refers to the Adafruit M4:

if board.get("build.core") in ("adafruit", "seeed", "sparkfun") and board.get(
        "build.mcu").startswith(("samd51", "same51")):
    # special flags for the latest bossac tool
    env.Append(
        UPLOADERFLAGS=[
        "-U", "--offset", board.get("upload.offset_address")])

This code is getting selected, I tried changing “samd51” to “blah” and then it dies right away. So the intended uploader seems to be selected, but most of the time the upload is not successful. It hangs after 50-85%. Here is some verbose upload info:

<lambda>(["upload"], [".pio/build/adafruit_itsybitsy_m4/firmware.bin"])
AVAILABLE: atmel-ice, jlink, sam-ba
CURRENT: upload_protocol = sam-ba
BeforeUpload(["upload"], [".pio/build/adafruit_itsybitsy_m4/firmware.bin"])
Use manually specified: /dev/cu.usbmodem14101
Forcing reset using 1200bps open/close on port /dev/cu.usbmodem14101
Waiting for the new upload port...
bossac --info --debug --port "cu.usbmodem14201" --write --verify --reset -U --offset 0x4000 .pio/build/adafruit_itsybitsy_m4/firmware.bin
Set binary mode
version()=v1.1 [Arduino:XYZ] Nov  2 2018 22:52:55
Connected at 921600 baud
readWord(addr=0)=0x2000d6a0
readWord(addr=0xe000ed00)=0x410fc241
readWord(addr=0x4)=0x58d
readWord(addr=0x41002018)=0x60060307
write(addr=0x20004000,size=0x34)
writeWord(addr=0x20004030,value=0x80)
writeWord(addr=0x20004020,value=0x20008000)
version()=v1.1 [Arduino:XYZ] Nov  2 2018 22:52:55
readByte(addr=0x804000)=0x39
readByte(addr=0x804001)=0x92
readByte(addr=0x804008)=0xff
readByte(addr=0x804009)=0xff
readByte(addr=0x80400a)=0xff
readByte(addr=0x80400b)=0xff
Device       : ATSAMD51x19
Version      : v1.1 [Arduino:XYZ] Nov  2 2018 22:52:55
Address      : 0x0
Pages        : 1024
Page Size    : 512 bytes
Total Size   : 512KB
Planes       : 1
Lock Regions : 32
Locked       : none
Security     : false
BOD          : false
BOR          : true
Write 47440 bytes to flash (93 pages)

[                              ] 0% (0/93 pages)write(addr=0x20004034,size=0x1000)
writeWord(addr=0x41004014,value=0x4000)
readByte(addr=0x41004012)=0x11
readByte(addr=0x41004013)=0xd
writeWord(addr=0x41004004,value=0xa501)
readByte(addr=0x41004012)=0x11
readByte(addr=0x41004013)=0xd
readByte(addr=0x41004010)=0x1
readByte(addr=0x41004011)=0
writeBuffer(scr_addr=0x20004034, dst_addr=0x4000, size=0x1000)

[==                            ] 8% (8/93 pages)write(addr=0x20004034,size=0x1000)
writeBuffer(scr_addr=0x20004034, dst_addr=0x5000, size=0x1000)

[=====                         ] 17% (16/93 pages)write(addr=0x20004034,size=0x1000)
writeWord(addr=0x41004014,value=0x6000)
readByte(addr=0x41004012)=0x11
readByte(addr=0x41004013)=0xd
writeWord(addr=0x41004004,value=0xa501)
readByte(addr=0x41004012)=0x11
readByte(addr=0x41004013)=0xd
readByte(addr=0x41004010)=0x1
readByte(addr=0x41004011)=0
writeBuffer(scr_addr=0x20004034, dst_addr=0x6000, size=0x1000)

[=======                       ] 25% (24/93 pages)write(addr=0x20004034,size=0x1000)
writeBuffer(scr_addr=0x20004034, dst_addr=0x7000, size=0x1000)

[==========                    ] 34% (32/93 pages)write(addr=0x20004034,size=0x1000)
writeWord(addr=0x41004014,value=0x8000)
readByte(addr=0x41004012)=0x11
readByte(addr=0x41004013)=0xd
writeWord(addr=0x41004004,value=0xa501)
readByte(addr=0x41004012)=0x11
readByte(addr=0x41004013)=0xd
readByte(addr=0x41004010)=0x1
readByte(addr=0x41004011)=0
writeBuffer(scr_addr=0x20004034, dst_addr=0x8000, size=0x1000)

[============                  ] 43% (40/93 pages)write(addr=0x20004034,size=0x1000)
writeBuffer(scr_addr=0x20004034, dst_addr=0x9000, size=0x1000)

[===============               ] 51% (48/93 pages)write(addr=0
x2000SAM-BA operation failed
4034,size=0x1000)
*** [upload] Error 1

Is there anyone else able to or not able to upload to an Adafruit M4 with Platform IO?

Solved: Damn. What an idiot. At some point I was having issues and had added the flag
upload_port = /dev/cu.usbmodem14101
I removed that and it just works now. Ugg.

1 Like