Resets (exceptions)

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi!

What happens if an AVR faces an exception like stack overflow (return pointers are invalid), and illegal op-codes...

I get occasional "External Resets", but i made sure, that reset_ has no spikes or the like. I also verified the contents of the Flash ROM, to look if something went wrong during downloading...

The only case i wasn't able to fully exclude was a stack overflow (stack space grows into variable buffer and might get corrupted). Any ideas?

Regards

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello!

Yes! A stack overflow can most definitely cause a reset! If you get a stack overflow and the return address is popped from "thin air" it's very common to end up at the reset vector.

Have you set up your stack pointer correctly? This is only necessary when writing in Assembly; a compiler will do this for you. Normally, the stack pointer initially points to the end of the SRAM.

Morten, AVR tech. support, Atmel FAE

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The stack pointer gets initialized from the program right at the beginning, followed by a reset reason detection logic (and the clearing of these 2 bits). Are these bits changed by an Stack overflow?

I have written a rather time-critical application (software decoder for iebus protocol), all in assembler, and only reserved 16 bytes (8 calls) for the stack (should not get deeper than 4 calls).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello again,

OK. I see the phorum has some limitations... Could you mail your .asm code to this address and then I'll have a look at it.

Morten, AVR tech. support, Atmel FAE