Program Arduino with USB CDC as VirtualCOM

Hi folks,

I have a Arduino Mega 2560 without the programmer, the Atmega 16U2 died. I know how to program it by using another Arduino, USBASP or some FTDI converter, but I'm trying to "revive" the programmer using a STM32F042F4Px (and some circuit modifications).

I can make the computer recognize the STM32 as an VirtualCOM device, but I'm not sure how to make it program an Arduino. It is possible to do that, without having to write a new bootloader?

Regards,
F813

It should be possible to upload some firmware to the STM32 that makes it act as a "serial passthrough", receiving the serial data from the computer from the virtual COM port, then writing it to a UART, which is connected to pins 0 and 1 on the Mega. The baud rate for that communication is 115200.

That should be all that's necessary to do an upload, but you'll need to press the reset button on the Mega at the start of the upload (after compilation in the Arduino IDE finishes) to activate the bootloader on the ATmega2560. If you want the reset to be automatic, as it was on the Mega originally, you'll need to connect one of the STM32's pins to the reset pin on the Mega and modify the STM32's firmware so that it sends a low pulse at the start of the upload to reset the ATmega2560.

Thanks for the insight. Although I still haven't got the setup working, at least when I try to upload, the Arduino Mega stays with the LED D13 on (I think it indicates that the bootloader is waiting for the packets).