Bootloader

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
TrevorDawes
Posts: 159
Joined: 06 Feb 2010 15:01
Location: Durban South Africa

Bootloader

#1 Post by TrevorDawes » 19 Oct 2010 05:20

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

KaranSoin
Posts: 130
Joined: 07 May 2010 22:27
Location: Melbourne, Australia

Re: Bootloader

#2 Post by KaranSoin » 19 Oct 2010 08:09

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

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: Bootloader

#3 Post by zristic » 19 Oct 2010 08:19

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.

TrevorDawes
Posts: 159
Joined: 06 Feb 2010 15:01
Location: Durban South Africa

Re: Bootloader

#4 Post by TrevorDawes » 19 Oct 2010 13:04

From what is suggested, the mE bootloader cannot issue a reset after a sucessful download. Is this correct?

Trevor

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: Bootloader

#5 Post by zristic » 19 Oct 2010 13:56

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.

TrevorDawes
Posts: 159
Joined: 06 Feb 2010 15:01
Location: Durban South Africa

Re: Bootloader

#6 Post by TrevorDawes » 19 Oct 2010 14:27

I am looking forward to the enhancement.

Trevor :D

KaranSoin
Posts: 130
Joined: 07 May 2010 22:27
Location: Melbourne, Australia

Re: Bootloader

#7 Post by KaranSoin » 19 Oct 2010 17:23

@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

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: Bootloader

#8 Post by zristic » 21 Oct 2010 10:50

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.

KaranSoin
Posts: 130
Joined: 07 May 2010 22:27
Location: Melbourne, Australia

Re: Bootloader

#9 Post by KaranSoin » 21 Oct 2010 13:39

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

TrevorDawes
Posts: 159
Joined: 06 Feb 2010 15:01
Location: Durban South Africa

Re: Bootloader

#10 Post by TrevorDawes » 21 Oct 2010 18:12

Thanks a million, I will give the watchdog time a try.

Cheers for now

Trevor

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: Bootloader

#11 Post by janni » 21 Oct 2010 23:07

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.

Post Reply

Return to “mikroBasic PRO for PIC General”