Can't upload sketch to custom Atmega32u4 with Arduino Leonardo bootloader

Hey all!

I’ve created my own PCB using an Atmega32u4. I have successfully uploaded the Arduino Leonardo bootloader using an USBasp, and it also pops up as an Arduino Leonardo (Com11) in the device manager.

If I try to upload the blink sketch (or any other I guess) I get the following error:

Arduino: 1.8.12 (Windows 10), Board: "Arduino Leonardo"

Sketch uses 3524 bytes (12%) of program storage space. Maximum is 28672 bytes.
Global variables use 167 bytes (6%) of dynamic memory, leaving 2393 bytes for local variables. Maximum is 2560 bytes.
PORTS {COM1, COM7, } / {COM1, COM7, } => {}
PORTS {COM1, COM7, } / {COM1, COM7, } => {}
PORTS {COM1, COM7, } / {COM1, COM7, COM12, } => {COM12, }
Found upload port: COM12
C:\Users\mrsab\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\mrsab\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega32u4 -cavr109 -PCOM12 -b57600 -D -Uflash:w:C:\Users\mrsab\AppData\Local\Temp\arduino_build_963620/sketch_mar01a.ino.hex:i 

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\mrsab\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"

         Using Port                    : COM12
         Using Programmer              : avr109
         Overriding Baud Rate          : 57600
avrdude: ser_open(): can't open device "\\.\COM12": Zugriff verweigert



avrdude done.  Thank you.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

avrdude: ser_open(): can’t open device “\.\COM12”: Zugriff verweigert (Access denied)

After some research I found out that a lot of people have problems because their Leonardo does not reset correctly. I suspect that mine does. The following happens when I upload the sketch:

  1. Upload to COM11
  2. As soon as “Uploading” appears the device managers shows Arduino Leonardo Bootloader (COM12) and the RX & TX leds blink a few times
  3. Error appears in Arduino IDE

I also reuploaded the bootloader a couple of times without any success.

I’ve attached my schematic so you can review it.

I hope that I provided enough information for you, if not please let me know!

Best regards,
Fabian

Okay strange things happened. After I burnt the bootloader again I was able to upload a sketch to it, but now every time I try to open the serial monitor or try to upload another sketch I get the error Port busy.

Any thoughts?

Maybe I could try to flash Sparkfuns Pro Micro bootloader instead of the Arduino one, I don't know if that would increase my success rate though :smiley:

Do you have something else that's grabbing onto the port, by any chance? Those errors suggest that some other program has the port open already - maybe something is grabbing onto any port for a moment when it becomes visible? "modem managers" that do this exist, assuming any serial port has a modem connected to it...

DrAzzy:
Do you have something else that's grabbing onto the port, by any chance? Those errors suggest that some other program has the port open already - maybe something is grabbing onto any port for a moment when it becomes visible? "modem managers" that do this exist, assuming any serial port has a modem connected to it...

I would have answered that question with a no, but as it seems like there was something going on with that port indeed.

I've closed any program and the upload worked!
(Tip: type something into notepad but do not save it. Shutdown your pc and when it tells you that notepad is blocking the system from shutting down select cancel. This way you can make sure that most of the times every other program is shut down.)

I will try to reflash the bootloader now once again to make sure that it works multiple times! (wish me luck lol)

It worked! Thanks again for the heads up, that will be the first thing I'm going to check if I have this error again.

Those damned modem manager things are the devil. They ceased to be relevant years ago, nobody uses modems anymore, and even if they do, they're not connected via a serial port! And they're always installed without the knowledge of the person using the computer...

Really, computer manufacturers don't give a damn about people like us - they only care about the mass market. So what if a few maker types are inconvenienced?