Programmer is not responding

ive connected a SD-Card module, and uploaded a few sketches, and everything was fine. I used PlatformIO to upload the sketches, and it anyoed me, that i had always to press the reset button on the Arduino Leonardo, so i changed it in platformio to com4, and it compiled once and never again, i tried compiling an empty sketch from arduino to it but it dosnt work. I selected the board Arduino Leonardo and it is the correct port (COM4). If i press the reset button it will just log this (it also happens if i unplug the arduino):

Connecting to programmer: .avrdude: ser_recv(): read error: Der E/A-Vorgang wurde wegen eines Threadendes oder einer Anwendungsanforderung abgebrochen. (The I/O event was stopped due to thread termination)


avrdude: butterfly_recv(): programmer is not responding

avrdude: ser_recv(): read error: Das Ger�t erkennt den Befehl nicht. (the device cant recognize the command)


avrdude: butterfly_recv(): programmer is not responding
avrdude: ser_drain(): read error: Das Ger�t erkennt den Befehl nicht. (the device cant recognize the command)


avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Das Ger�t erkennt den Befehl nicht. (the device cant recognize the command)


avrdude: butterfly_recv(): programmer is not responding
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Das Ger�t erkennt den Befehl nicht. (the device cant recognize the command)


avrdude: butterfly_recv(): programmer is not responding
avrdude: ser_recv(): read error: Das Ger�t erkennt den Befehl nicht. (the device cant recognize the command)


avrdude: butterfly_recv(): programmer is not responding
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Das Ger�t erkennt den Befehl nicht.  (the device cant recognize the command)


avrdude: butterfly_recv(): programmer is not responding
Found programmer: Id = "�"; type = @
    Software Version = �.v; Hardware Version = �. 
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Das Ger�t erkennt den Befehl nicht.  (the device cant recognize the command)


avrdude: butterfly_recv(): programmer is not responding
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Das Ger�t erkennt den Befehl nicht.  (the device cant recognize the command)


avrdude: butterfly_recv(): programmer is not responding
avrdude: error: buffered memory access not supported. Maybe it isn't
a butterfly/AVR109 but a AVR910 device?
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Das Ger�t erkennt den Befehl nicht.  (the device cant recognize the command)


avrdude: butterfly_recv(): programmer is not responding
avrdude: error: programmer did not respond to command: leave prog mode
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Das Ger�t erkennt den Befehl nicht. (the device cant recognize the command)


avrdude: butterfly_recv(): programmer is not responding
avrdude: error: programmer did not respond to command: exit bootloader

avrdude done.  Thank you.

Than if i wait this happens:

Connecting to programmer: .avrdude: butterfly_recv(): programmer is not responding

avrdude: butterfly_recv(): programmer is not responding

(now i wait indefenetly)

i tied disconneting 5v and gnd before uploading but nothing helps

i hold reset until there was uploading, and it erased the code, but if i now do the same with platformio this error comes:

Uploading .pio\build\leonardo\firmware.hex
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x3f

avrdude done.  Thank you.

I can't help you with PlatformIO related issues.

That is usually an indication of a bug in your code. As a result the board is either not detected by the operating system or does not react on the software reset issued by the IDE just before the actual upload started.

That is not for a normal upload to a Leonardo. Is this the result of an upload using programmer?

I'm not using "Upload Using Programmer," just the normal upload method in PlatformIO. The correct upload protocol (arduino) is set in platformio.ini, and the port (COM4) is correct.

Resetting the Leonardo right before uploading didn't help either. The board works fine with the Arduino IDE, but in PlatformIO, it gets stuck at Uploading .pio\build\leonardo\firmware.hex and eventually fails with not in sync: resp=0x3f.

Could a bug in my code really cause this issue, even if it uploads fine with the Arduino IDE?
Or is this PlatformIO related?

Part of the code that is uploaded to boards with native USB (like the Leonardo) is for functionalities that are responsible for the board detection by the computer and for the reaction on the reset issued by the IDE (opening and closing the serial port with a baudrate of 1200 baud).

If your code has a bug, it can overwrite variables used by those functionalities.

For a Leonardo that is what I expect regardless of IDE (Arduino, PlatformIO).

For boards like Uno/Nano/Mega that is what I expect. Are you sure that you selected the correct board when PlatformIO generated the output of post #2?

I found out that upload_protocol = arduino in platformio.ini was causing the error. After removing it, the upload works fine. I have no idea why this caused the issue, but comparing my PlatformIO config with others led me to this solution.

Your explanation about how native USB boards handle reset and detection made a lot of sense! That might also explain why this issue happened in the first place. Thanks for your help—it really pointed me in the right direction!

I asked ChatGPT why this happened, and it turns out that the Leonardo uses a different upload mechanism than boards like the Uno or Mega. Unlike those boards, the Leonardo has a native USB controller and relies on the caterina bootloader instead of arduino as the upload protocol.
When upload_protocol = arduino was set, PlatformIO likely tried to use the wrong reset and upload method, which caused stk500_getsync() errors. Leonardo requires a 1200 baud reset sequence to enter the bootloader properly, and this might have been disrupted by the wrong setting.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.