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
Bootloader
Re: Bootloader
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
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
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.
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.
-
- Posts: 159
- Joined: 06 Feb 2010 15:01
- Location: Durban South Africa
Re: Bootloader
From what is suggested, the mE bootloader cannot issue a reset after a sucessful download. Is this correct?
Trevor
Trevor
Re: Bootloader
That is correct, however, we will change that in near future.TrevorDawes wrote:From what is suggested, the mE bootloader cannot issue a reset after a sucessful download. Is this correct?
-
- Posts: 159
- Joined: 06 Feb 2010 15:01
- Location: Durban South Africa
Re: Bootloader
I am looking forward to the enhancement.
Trevor
Trevor
Re: Bootloader
@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
Regards
Re: Bootloader
Ok, here is the scenario: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
- 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
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
Cheers
-
- Posts: 159
- Joined: 06 Feb 2010 15:01
- Location: Durban South Africa
Re: Bootloader
Thanks a million, I will give the watchdog time a try.
Cheers for now
Trevor
Cheers for now
Trevor
Re: Bootloader
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 ). 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.
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 ). 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.