Page 1 of 1

Bootloader

Posted: 19 Oct 2010 05:20
by TrevorDawes
Hi all, how can I make the bootloader reset the MCU after download?
If this is possible, please advise.

Many millions of thank you's

Trevor

Re: Bootloader

Posted: 19 Oct 2010 08:09
by KaranSoin
either a

asm GOTO 0x0000

or

have the watchdog timer enabled and wiggled all the time and stop wiggling it when you want a reset.



cheers

Re: Bootloader

Posted: 19 Oct 2010 08:19
by zristic
GOTO 0x00 can cause serious problems with stack overflow, do not use that for reset.

One option is to connect a free pin to MCLR pin and to drive that pin low when reset is needed.
Another option is to use the RESET assembly command for PIC18.

Re: Bootloader

Posted: 19 Oct 2010 13:04
by TrevorDawes
From what is suggested, the mE bootloader cannot issue a reset after a sucessful download. Is this correct?

Trevor

Re: Bootloader

Posted: 19 Oct 2010 13:56
by zristic
TrevorDawes wrote:From what is suggested, the mE bootloader cannot issue a reset after a sucessful download. Is this correct?
That is correct, however, we will change that in near future.

Re: Bootloader

Posted: 19 Oct 2010 14:27
by TrevorDawes
I am looking forward to the enhancement.

Trevor :D

Re: Bootloader

Posted: 19 Oct 2010 17:23
by KaranSoin
@zristic: Did'nt know that. could you explain a bit more. I have been using goto 0, and this could explain some unexplained ghosts in my code.

Regards

Re: Bootloader

Posted: 21 Oct 2010 10:50
by zristic
KaranSoin wrote:@zristic: Did'nt know that. could you explain a bit more. I have been using goto 0, and this could explain some unexplained ghosts in my code.

Regards
Ok, here is the scenario:
- Imagine you have RoutineA and RoutineB
- RoutineA is calling RoutineB
- When CALL is performed in RoutineA, PIC will push on stack the return address,
- Once RETURN is executed in RoutineB, PIC pops the return address from the stack
- If you GOTO 0 from routine B, the RETURN instruction will not execute and PIC stack will not be popped, i.e. it will overflow.

To remind you, stack depth on PIC16 is only 8.
PIC18 have the RESET command which clears the stack.
WatchDog timer clears the stack on both PIC18 and PIC16.

I hope it helps.

Re: Bootloader

Posted: 21 Oct 2010 13:39
by KaranSoin
ha, of course, the stack pointer is not being reset when doing a goto 0x0000. Thanks zristic, I think I just figured out where some of the ghosts in my programs were coming from.

Cheers

Re: Bootloader

Posted: 21 Oct 2010 18:12
by TrevorDawes
Thanks a million, I will give the watchdog time a try.

Cheers for now

Trevor

Re: Bootloader

Posted: 21 Oct 2010 23:07
by janni
Actually, the hardware stack in mid-range PIC16s is circular (it may wrap around, but it doesn't exactly 'overflow'). Use of GOTO 0 is quite safe in PIC16s if one wants to start over (at least in real devices, simulators may get hiccups :) ).

In PIC18s or the enhanced mid-range MCUs (16F1xxx), one should indeed use the RESET instruction instead (though mE compilers still use GOTO 0 there as a fill-in for empty ISRs :wink: ). One may also reset the stack by clearing the stack pointer and then jump to code beginning (or any other point in top layer of code ).

Waiting for watchdog reset (in infinite loop) is common practice in all PIC families, if the application does no require instantaneous response.