Software reset in AVR GCC

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

I'm trying to make my XMEGA reset when I type a command. I tried

asm("reset");

 but it said it doesn't exist.

Then I tried doing stack underflow, but the MCU would go to bootloader, then wouldn't respond to me at all :(

I tried doing

asm(".DB 0x9588");

which is the opcode for sleeping in hex form and it said 

unknown pseudo-op: `.db'

About connecting a spare pin to the reset pin, I've read somewhere that that is a bad idea.

 

Am I forced to not have such a trivial option like reset???

 

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

Which xmega ???
AFAIK no AVR8 has a 'reset' opcode.
The xmega64A has a software reset which will do a reset if you write to the SWRST bit in the RST CTRL register.
Another option would be to jump to address 0x0000 or the start of the bootloader.

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

ATXMEGA128A1. I'll check for that reset register.

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

There are 3 ways to get a "reset";

 

1) JMP 0 (or whatever the usual entry address is). This isn't really a reset because all peripherals and interrupt sources remain enabled but it does "restart" the code.

 

2) force a watchog reset. Just turn on the watchdog then "while(1)" until it does a restart. This sets all peripherals and interrupt sources back to power on defaults (basically nothing active).

 

3) As Mike says the Xmega added a control register that allows the code to have the same, immediate affect as (2). (RST.STATUS  / RST.CTRL)

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

I tried using RST.STATUS / RST.CTRL, but it didn't work

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

Did you read the datasheet about it?

Quote:
Bit 0 – SWRST: Software Reset
When this bit is set, a software reset will occur. The bit is cleared when a reset is issued. This bit is protected by
the configuration change protection mechanism.
For details, refer to “Configuration Change Protection” on page
13.
Did you write the correct signature to CPP right before the write to RST.CTRL?

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

Thanks, it worked!

int MP_cmd_reset()
{
	CPU_CCP=0xD8;
	RST_CTRL=RST_SWRST_bm;
	return 0;
}