Avrdude: stk500v2_ReceiveMessage(): timeout error while uploading blink program, after a successful bootloader

I am currently uploading bootloader to a custom-made marlin board that uses atmega2560. This board is being used for a 3d - printer. I use Arduino UNO as the ISP to the board and I followed all the initial steps which are:

  • Give Board connections between UNO and the marlin board (The connections are the same as that of a Mega board)
    I followed the steps according to this website: Arduino-er: Arduin Uno as ISP to burn Bootloader to Mega 2560

  • Selected port, set the board as UNO, and selected programmer as AVRISP mkll.

  • Selected the Arduino ISP from the example programs and uploaded it to the UNO and selected programmer to Arduino as ISP

  • Changed the board to Arduino Mega or Mega 2560 and started the burn bootloader option

The bootloader is successfully burnt and when I try to dump a blink code, it starts the timeout error
At first, I figured out from other forums that the timeout was due to a small error in the boards.txt where the stk500v2 must be changed to wiring.
But the error didn't stop and I am not able to figure out what's wrong here. Please help me out with this!

Please provide a detailed description of how you did that.

  1. I first connect the USB to the Arduino UNO and follow these steps:

    • Select the port.
    • Select the programmer to 'AVRISP mkll'.
    • Select the ArduinoISP program from the examples.
    • Upload it to the Arduino UNO.
  2. After the above steps I connect the UNO to the target which has the following connections:

    10(SS) > RESET, 11(MOSI) > MOSI, 12(MISO) > MISO, 13(SCK) > SCK

  3. Now, I select programmer > Arduino as ISP, Board > Arduino mega or mega 2560 and now burn the bootloader which is successful.

  4. Finally to verify if the board is boot loaded, I dump the blink code and this is where I get the timeout error.

I used this website for my purpose:

Is that AFTER you plug in the custom-board's USB or Serial port and change the Port setting in the IDE to the new port?

yes!

Do you have an auto-reset circuit (DTR or RTS --> capacitor --> RESET) ?

yes

Do you have an "L" LED? Does it blink three times after the "upload" should have reset it?

Are you sure RX->TX and TX-RX rather than RX->RX? (a common mistake on "custom" designs.)

should it blink three times after the upload or during the upload?

At the very beginning of the upload attempt, immediately after the reset.

No it doesn't blink

Does it blink if you hit the reset manually?

nope!

Apparently I'm mistaken about the way the 2560 bootloader blinks (or doesn't blink) the LED on reset. :frowning: It looks like it only blinks once.

I see that over on avrfreaks you posted an actual schematic, and it includes a 16u2 as the USB/Serial chip. Are you sure that the 16u2 has been programmed with "correct" firmware? (you didn't mention programming it, but ... it wouldn't show up as a "port" if it was empty...)

do we use flip software for programming the 16u2? If yes, I did it when I first connected the custom board. If no, please enlighten me with the procedures!

Here's the schematic from AVRFreaks...

I'm not sure. I didn't think you could use FLIP until AFTER the 16u2 had been programmed with it's initial firmware. (it can upgrade/replace the USB/Serial part of the firmware, but it needs a USB bootloader in there to do that, and it's controlled by jumpers. So you have to have at least the bootloader part of the code loaded in the 16u2 for that to work, and I don't think it comes with a bootloader pre-loaded, so that has to be programmed with something like Arduino as ISP (but it doesn't have an "easy" method like "burn bootloader.")
I have never programmed or re-programmed a 16u2.
I think normally you use a programmer to load a .hex file that contains both the 16u2 bootloader AND the USB/Serial code ( ...hardware/avr/1.8.4/firmwares/atmegaxxu2/Arduino-COMBINED-dfu-usbserial-atmega16u2-Mega2560-Rev3.hex or similar)

Can you tell me a method where I can upload the hex file to the 16u2 through the icsp pins? I tried uploading through the usb, but I get the same timeout error!

looks OK. If you're making your own hardware, you might be better off learning more of the details of how to use avrdude directly.

  1. Connect your programmer to the ISP port of the 16u2 (SERIAL_PROG) in your schematic)
  2. Burn correct fuses (using avrdude) (um... -U efuse:w:0xF4:m -U hfuse:w:0xD9:m -U lfuse:w:0xFF:m )
  3. Burn the combined .hex file for your board type.