ATmega32u4 freeze at powerup

ChibiOS public support forum for topics related to the Atmel AVR family of micro-controllers.

Moderators: utzig, tfAteba

robomaniac
Posts: 3
Joined: Wed Sep 17, 2014 4:07 am

ATmega32u4 freeze at powerup

Postby robomaniac » Wed Sep 17, 2014 4:22 am

Hi Guys,

I tried to seek help from the Arduino forum but no luck.
http://forum.arduino.cc/index.php?topic=266485.0

I have been running a ChibiOS/NIL on an ATmega32u4. It was super easy to implement my code. The moment I remove the USB and plug it back in, I break the bootloader! I am finish developping my code so I want a standalone module so I plug it in 12V. The moment I do that, I corrupt the bootloader. When developping, the USB cable is plug in the Arduino and I can upload my code and to all my test. The moment I remove the USB and try to apply external power again(USB, 5V, 12V, Vin, etc) it can not start. I have to reloader the bootloader, I connect to the serial port of the bootloader and reload the blink sketch.

I do not get this problem with the ATmega328. The problem is the same with the Arduino Micro.

I suppose that would be related to ATmega32u4 bootloader (Caterina). I think it might be ISR or watchdog that is continually resetting.

Here is a video of what is happening.
https://www.youtube.com/watch?v=lVY_4SOJBtE

Thank you for you help.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: ATmega32u4 freeze at powerup

Postby Giovanni » Wed Sep 17, 2014 7:25 am

Moving in the AVR forum, this is AVR-specific.

Giovanni

robomaniac
Posts: 3
Joined: Wed Sep 17, 2014 4:07 am

Re: ATmega32u4 freeze at powerup

Postby robomaniac » Wed Sep 17, 2014 11:51 am

To be more specific, I am not using avr gcc. I am compiling and uploading with Arduino IDE. I have try ChibiOS_AVR, NilRTOS and leOS/leOS2 libraries.
The bootloader is the Caterina that is use with the Arduino Micro, Arduino Leonardo and the Esplora.

fred
Posts: 19
Joined: Wed Feb 27, 2013 4:32 pm

Re: ATmega32u4 freeze at powerup

Postby fred » Wed Sep 17, 2014 2:45 pm

This category of strange behavior tends to drive a developer insane ;)

Two things I can think of:

1. did you compile with the correct arch for Caterina? According to the source I found here there's at least some requirement to compile with a #define __AVR_ATmega32U4__ in your code. Maybe you forgot it?

2. When flashing, does the programmer also set the fuses? Check that you flash with the correct target.

robomaniac
Posts: 3
Joined: Wed Sep 17, 2014 4:07 am

Re: ATmega32u4 freeze at powerup

Postby robomaniac » Wed Sep 17, 2014 7:47 pm

BOOM!

Found my bug Fred!
I deleted all my serial println and was able to pin point my mistake!!

I wanted to make a #define DEBUG where I could remove all my serial printf from my code instantly! To save memory.

Code: Select all

#define DEBUG 1

#ifdef DEBUG
void SerialDebug(const char* sMsg){
     Serial.println(sMsg);
}
#endif


Then I use this

Code: Select all

 SerialDebug("thread1 thread initialize");



What killed the code is this: while (!Serial) {}

Code: Select all

 
void setup() {

  #ifdef DEBUG
    Serial.begin(9600);
    // wait for USB Serial
    while (!Serial) {}            <======= I deleted this line!
    SerialDebug("9600 baud rate");   
  #endif 
 
   
   
  // Start Nil RTOS.
  nilSysBegin();
 
  SerialDebug("Define is set");   
}




Thank you Fred.


Return to “AVR Support”

Who is online

Users browsing this forum: No registered users and 7 guests