ATMEGA32U4 apperas bricked after uploading a sketch -SOLVED

My standalone ATMEGA32U4 based board with an Arduino Micro bootloader was working fine with the code (part of which is shown below) until I decided to comment out the line WiFi.init(&Net); and uploaded the code again.

After that, i am unable to upload anything, the Serial Port is no longer detected and I cant even burn the bootloader with a programmer! The MCU oscillator is still working fine which was tested with an oscilloscope. The bad news is that I was even able to …replicate the above with a second board which is now also bricked!!

 #include <EEPROM.h>
 #include <avr/pgmspace.h>
 #include <pins_arduino.h>
 
 #include <SoftwareSerial.h>
 #include "Definitions.h"
 #include "WiFiEsp.h"
 
...
...

...



//  ********** WIFI Setup*********

 pinMode (esp8266Enable,OUTPUT);
 digitalWrite (esp8266Enable,HIGH);
 pinMode(esp8266Reset, OUTPUT);
 digitalWrite (esp8266Reset,HIGH);
 Net.begin (9600);
 WiFi.init(&Net);
...
...
...

I was just about to replace the MCU with a new one when I thought that someone out there might think of something else to try out before. :slight_smile:

Update: SOLVED!

Managed to burn the bootloader again and now everything is back in order.

Still not sure why the bootloader wouldn't burn before and most importantly how/why uploading a sketch resulted in bootloader corruption.

Since you only posted a fragment of your code, it’s hard to say for sure what’s in play but understand that it is easy to hose yourself with the 32U4.

If you use the USB/serial port in your code for something other than a dedicated port with which to communicate with the IDE, you lose your ability to use the bootloader. It appears like the bootloader is gone, but it is still there, it’s just being ignored since other code has exclusive use of the port.

This gotcha is why most of the Arduino 32U4 based USB demo programs provide a hardware method of disabling the user’s USB portion of the program, to restore bootloader functionality.

Reflashing the bootloader erases all of the devices flash - so the offending user program is wiped in the process and things return to normal, the user thinks it was a bad bootloader but that’s really not the case.

Thanks avr_fred for the input.

No am not using Serial for anything else other than commication with PC. I am however using 2 software serial ports as well as the serial1 hardware port.