Sunday, November 21, 2021

Arduino Pro Micro (Atmega32U4) - Can't Upload Sketch - Board Bricked

Problem: 

I recently purchased some pro micro clone boards with HID support. I was able to upload to the first board without a problem, but then I was unable to upload to the same board with a new sketch or any of the other boards I purchased in that bundle. It turned out to be a few things including a timing issue. 

Solution: 

There are really two parts of this solution required to actually make this work and it is a bit of a pain if you have to do it often, but it worked for me and hopefully will help you. 

Problem 1 & Solution: The com port while the board was plugged in was always different then the one used while the bootloader was running. For example, when the board sketch was running it would show up as COM9.


When the board was first plugged in and the bootloader was reset, it would show up as COM8. Since we want to upload a new sketch to the board, we need to do this while the board is on the bootloader serial port COM8. First, let's get the bootloader to reset and stall for ~8 seconds so we can determine the bootloader serial port (your ports are likely different than mine). To do this with my board and unplugged from the USB, I had to connect RST and GND together with a wire, and then plug in the USB cable. After a moment, pull the wire out of either pin and then immediately in the Arduino IDE go to the Tools -> Port menu and choose the bootloader port now showing: 


Once you have done this, Arduino IDE should remember that serial port for next time. If you waited too long, you won't see the Arduino connected to any other port, so make sure you are quick. 

Problem 2 & Solution: The second part of the problem is that we need to compile and upload the new sketch before the bootloader times out. This is a challenge if you are trying to manage everything above, compile the sketch and upload it at once which is why we break it into parts. With the Arduino IDE still pointing to the bootloader serial port (COM8 for me), we need to again reset the bootloader on the Arduino to allow the new sketch to be uploaded. We do this by unplugging the USB, reconnecting our wire between RST and GND, and then plugging the USB cable back in. While the wire is still connected between RST and GND, begin compile and upload in the Arduino IDE. Once you see the sketch storage information print in the output, 


pull the wire out of either pin (RST or GND). The IDE should see the device connect on port COM8 as the bootloader goes into the ~8 second stall and then begin uploading the already compiled sketch. 

If you are successful, you will see Done uploading and your new sketch is uploaded to the board. 

Good luck!


Sources: 

With a lot of various information online, these were the resources most helpful to me with finding a solution: 

https://forum.arduino.cc/t/solved-completely-resetting-arduino-pro-micro/671721/2

https://learn.sparkfun.com/tutorials/qwiic-pro-micro-usb-c-atmega32u4-hookup-guide#troubleshooting-and-faq

https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/troubleshooting-and-faq#ts-reset

https://config.qmk.fm/#/test (my sketch was using function keys that are not typically on keyboards and I wanted to test and make sure shorting a pin (a button press) would produce the right keycode)


No comments: