atmega32u4 bootloader

Hi,

I am doing project with chinese Arduino pro micro board which should be fully compatible with Arduino leonardo. I also upload standard "catherina-leonardo" bootloader into this module. Everythinks was working fine until I enable watchdog by "wdt_enable()" function in my code. Now It is not possible to upload new sketches via USB CDC serial port. I looks like processor do not wait in bootloader after software reset and jump to main program immediatly. Only way that restore processor from this state is erasing whole chip and upload new bootloader by external ISP programer. I think this is problem in bootloader. I need to use watchdog. Is there any fix or alternative bootloader for arduino leonardo?

Peter.

@Peter,

I suggest using the SparkFun Pro Micro bootloader. Procedure

Ray

I already try sparkfun booloader. It looks like there only some changes with bootloader timing but the main problem with watchdog is not solved.

pjanco: I already try sparkfun booloader. It looks like there only some changes with bootloader timing but the main problem with watchdog is not solved.

Have you tried the original Leonardo firmware? If you can get the chip burned (bootloader or ISP) then the bootloader should leave the uC in the correct registry configuration for your sketch to function. Yea, it may be a bummer if the botloader does not allow serial, but ISP should be do-able.

Ray

pjanco: Hi,

I am doing project with chinese Arduino pro micro board which should be fully compatible with Arduino leonardo. I also upload standard "catherina-leonardo" bootloader into this module. Everythinks was working fine until I enable watchdog by "wdt_enable()" function in my code. Now It is not possible to upload new sketches via USB CDC serial port. I looks like processor do not wait in bootloader after software reset and jump to main program immediatly. Only way that restore processor from this state is erasing whole chip and upload new bootloader by external ISP programer. I think this is problem in bootloader. I need to use watchdog. Is there any fix or alternative bootloader for arduino leonardo?

Peter.

Instead of using auto reset during upload, connect a button between RST and GND and manually reset the Pro Micro to get the bootloader to run. When the Arduino IDE changes from Compiling to Uploading, just tap the button to reset.

I probably did not express very clearly. I can fix "bricked" arduino by external ISP programmer. It it easier connect USBASP than soldering some reset button.

I have a problem with watchdog. After I turn on watchdog in my application code then it is not possible jump into bootloader by software reset via USB CDC (open and close serial port od 1200baud). Everythink works fine if watchdog is off.

I think that this is a problem in bootloader code but maybe it is not so. I know that a similar problem with a watchdog had the original bootloader for Arduino Pro Mini with ATmega328 processor. But in that case main application never start and processor stay in bootloader loop. In my case main application code starts normally.

My question is, why activation of watchdog cause malfunction of sotware reset function via USB?

I don’t know about the 32U4. I was reading yesterday about the bootloader for the Uno and if the watchdog is enabled, the bootloader skips most of the usual bootloader process and nearly immediately jumps to the application code.

This might be the same here.

Arduino Uno has different bootloader then Arduino pro mini. Original Arduino Uno bootloader does not have this problem with watchdog reset. Has anyone successfully used watchdog in original Arduino leonardo board?

My thoughts:

  1. You don’t have to use a bootloader at all. A bootloader is all about uploading without using a programmer, but since you are using programmer to reload the bootloader and then using the bootloader to load a program one time, skip some of that and just use the programmer to upload your sketch. The IDE has an Upload Using Programmer function.

  2. You can use the Optiboot bootloader if it does what you want, and upload via the serial pins with an FTDI or bluetooth adapter, instead of uploading via USB. Uploading via an FTDI adapter does a hardware reset via the DTR signal. Google “optiboot pro micro” or “optiboot leonardo” and you will find my Instructable. I don’t know for sure if Optiboot on ATmega32U4 would behave as you want, you would have to try it.

Hi, it looks like the bug is not in bootloader code but in the arduino core library code in file "hardware\arduino\cores\arduino\CDC.cpp". There is probably should be inifine loop in auto-reset algorithm.

if (1200 == _usbLineInfo.dwDTERate) {
  // We check DTR state to determine if host port is open (bit 0 of lineState).
  if ((_usbLineInfo.lineState & 0x01) == 0) {
  *(uint16_t *)0x0800 = 0x7777;
  wdt_enable(WDTO_120MS);
  while(1);//my bug fix
 } else {
  // Most OSs do some intermediate steps when configuring ports and DTR can
  // twiggle more than once before stabilizing.
  // To avoid spurious resets we set the watchdog to 250ms and eventually
  // cancel if DTR goes back high.

  wdt_disable();
  wdt_reset();
  *(uint16_t *)0x0800 = 0x0;
 }
}

so , how to fix wdt_enable issue with leonardo/micro ?

is optiboot will help ?