EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Software reset or alike

Started by Guillermo Prandi January 30, 2006
Hi. What would be the software sequence the most similar to a
hardware reset? I am aware that certain things cannot be changed from
software, like the watchdog, once it is started, but perhaps there's
something closer to a reset than:

msr CPSR_c,#MODE_SVC|I_BIT|F_BIT
b 0

This would not work if in user mode, for instance, for I cannot
change CPSR from that mode, I guess.

I am using LPC2138/LPC2148 in my board. Perhaps the IAP/ISP code
could be useful somehow?

I've been thinking on reusing an existing exception to start
such "software reset", like Undefined or something, but I rather use
it to detect the true exception if I can manage. I would like to
write a solid piece of software, so I want all the bases covered,
whenever possible.

Any ideas?

Guille

An Engineer's Guide to the LPC2100 Series

Guillermo,

From past experience, the best way to "soft" reset a microcontroller
is to use some form of hardware reset. I haven't heard of any issues
with any of the LPC2000 series peripherals, but on some micros, it is
possible for some of the peripherals to get latched into states that
can't be recoevered by software (that is, you can't reliably re-
configure them). Because of this, some form of hardware reset is
usually best to get the system into a known, initial, state.

Two suggestions:

1. If you can spare an I/O pin, use an o/p pin to feed-back into the
reset line (i.e. self-reset). Advantage: simple. Disadvantage: need
h/w.

2. Use the watchdog: configure it for a very short time, and then
spin round (or goto idle state) without feeding it. Advantage:
reasonably simple, no hardware required. Disadvantage: you may
already be using the watchdog, and if so, may need additional code to
distinguish a real watchdog (unexpected) reset from an intended soft
reset.

I'm sure there's plenty of other ways too.

Brendan
Thanks, Brendan. Yes, I thought of a hardware reset, but modifying
the board is no longer an option at this stage. However, I would like
to -by software- do my best effort to handle this, although I know I
can't really cover all bases.

About the watchdog, I am concerned about such a short timer. Since
there is no way I can turn the watchdog off by software, couldn't my
reset procedure be continually called by the watchdog, with not
enough time to reset it properly? The LPC2138 user manual doesn't say
if the watchdog is stopped after triggered (or at least I couldn't
find a word about it). In fact, once the watchdog is set up, what
attributes am I allowed to change from it afterwards?

Another way that just occurred to me is the following:

1) Disable all interrupts
2) Relocate the interrupt vectors into RAM (I was using ROM vectors)
3) Place a dummy SWI at the SWI vector
4) Produce a SWI
5) Inside the SWI handler (now in supervisor mode!),
relocate the interrupt vectors into ROM again and perform "b 0".

Too messy for my liking, but it is the only sure way to enter
supervisor mode from user mode without wasting an exception mode.
(Currently SWI is being used by the FreeRTOS port to perform a Yield).

Guille
I still think the best way is to create a reset routine that will reset the
processor using the watchdog timer, as someoe else mentioned. I've
encountered this issue many times over years, and using the watchdog was
always the best way.
I'm rather sure that once the processor is reset, you have to re-enable it
for your application (as you do normally on powerup). It shouldn't stay
enabled across reset.

--
Jim Parziale
nuncio.bitis@nunc...
Malden, MA
Hi,

The watchdog, if it underflows, does a reset of the system. According
to the manual (I'm looking at the LPC213x User Manual), and I see no
reason to doubt it, there's very few differences between an internal
(watchdog) reset and an external (reset pin) reset.

The watchdog mode register description in tne same manual shows that
the reset value of the enabled flags is 0 (i.e. not enabled). I'd
take that to mean that there's no danger of what you're concerned
about (i.e. an infinite loop of watchdog resets).

Bottom line: if you trust the manual contents, it should be OK for
your purposes (indeed, I hope that it is, as it's exactly what we do
for a "soft" reset). As you point out, attempting to do it in
software can get messy very fast, if you want something general
purpose.

Regards
Brendan
You are right, Brendan, Jim. I just tested and the watchdog, once
triggered, won't trigger again until it is set up again. So I will
use the watchdog with a pretty short timer (minimum = 0xff) and then
enter an endless "enter idle mode" loop. It looks like interrupts can
take you out of idle mode even if they are disabled.

Thank you all.

Guille

Memfault Beyond the Launch