|
|
View previous topic :: View next topic |
Author |
Message |
jds-pic Guest
|
bootloader re-entry STILL NOT working |
Posted: Mon May 26, 2003 3:35 pm |
|
|
<font face="Courier New" size=-1>gang,
i'm at wits end here. :^
in
<a href="http://www.pic-c.com/forum/general/posts/14366.html" TARGET="_blank">http://www.pic-c.com/forum/general/posts/14366.html</a>
i describe how i'm trying to programatically re-enter the the microchipc-sourced bootloader (www.microchipc.com). i've been working at it, among other things, for a week now and still i'm stumped. what i have done is a) set all of the 16F876's registers to power-up conditions, and 2) use MPLAB to step through and make sure program flow is as expected. but despite many trials and lots of error, still no joy. the behavior right now is that the user code exits into the bootloader, the bootloader does NOT request new code from the serial port, and then the user program is GOTO'd by the bootloader, restarting user code execution. it would appear that the bootloader code is being tripped up by something but i've attempted to cover all bases and still it's unappreciated by the bootloader. :*)
so i was wondering out loud (again) if anyone knows the magic to re-entering the bootloader from userland code. any help or suggestions very much appreciated. (note that it is not possible for me to use a WDT-based scheme. my widget sleeps all of the time to conserve battery, and enabling the WDT is a good way to keep waking up). my current non-working setup looks like this:
// user requested device reboot;
if (!INPUT(PIN_PB_SWITCH)) {
disable_interrupts(GLOBAL);
display_message(MSG_FWUPDATE, TIMEOUT_FWUPDATE);
delay_ms(250);
TMR0 = 0x00;
STATUS = 0x18;
FSR = 0x00;
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PCLATH = 0x18;
INTCON = 0x00;
PIR1 = 0x00;
PIR2 = 0x00;
TMR1L = 0x00;
TMR1H = 0x00;
T1CON = 0x00;
TMR2 = 0x00;
T2CON = 0x00;
SSPCON = 0x00;
RCSTA = 0x00;
OPTION_REG = 0xff;
TRISA = 0x3f;
TRISB = 0xff;
TRISC = 0xff;
PIE1 = 0x00;
PR2 = 0xff;
SSPADD = 0x00;
SSPSTAT= 0x00;
TXSTA = 0x02;
SPBRG = 0x00;
ADCON = 0x00;
TMR0 = 0x00;
STATUS = 0x18;
// bootloader should run now.
#asm // toggle att'd LED so we know we got here.
BSF 03.5
BCF 05.0
BCF 03.5
BCF 05.0
#endasm
//#asm // tried this
//nop
//BSF PCLATH, 0x3
//BSF PCLATH, 0x4
//GOTO 0x732 //
//#endasm;
goto_address(BOOTLOADER_ENTRY); // = 0x1f32 or 0x1f34
// reset_cpu(); // tried this
}
all that amounts to
.................... TMR0 = 0x00;
1474: CLRF 01
.................... STATUS = 0x18;
1475: MOVLW 18
1476: MOVWF 03
.................... FSR = 0x00;
1477: CLRF 04
.................... PORTA = 0x00;
1478: CLRF 05
.................... PORTB = 0x00;
1479: CLRF 06
.................... PORTC = 0x00;
147A: CLRF 07
.................... PCLATH = 0x18;
147B: MOVWF 0A
.................... INTCON = 0x00;
147C: CLRF 0B
.................... PIR1 = 0x00;
147D: CLRF 0C
.................... PIR2 = 0x00;
147E: CLRF 0D
.................... TMR1L = 0x00;
147F: CLRF 0E
.................... TMR1H = 0x00;
1480: CLRF 0F
.................... T1CON = 0x00;
1481: CLRF 10
.................... TMR2 = 0x00;
1482: CLRF 11
.................... T2CON = 0x00;
1483: CLRF 12
.................... SSPCON = 0x00;
1484: CLRF 14
.................... RCSTA = 0x00;
1485: CLRF 18
.................... OPTION_REG = 0xff;
1486: MOVLW FF
1487: BSF 03.5
1488: MOVWF 01
.................... TRISA = 0x3f;
1489: MOVLW 3F
148A: MOVWF 05
.................... TRISB = 0xff;
148B: MOVLW FF
148C: MOVWF 06
.................... TRISC = 0xff;
148D: MOVWF 07
.................... PIE1 = 0x00;
148E: CLRF 0C
.................... PR2 = 0xff;
148F: MOVWF 12
.................... SSPADD = 0x00;
1490: CLRF 13
.................... SSPSTAT= 0x00;
1491: CLRF 14
.................... TXSTA = 0x02;
1492: MOVLW 02
1493: MOVWF 18
.................... SPBRG = 0x00;
1494: CLRF 19
.................... ADCON = 0x00;
1495: CLRF 1F
.................... TMR0 = 0x00;
1496: BCF 03.5
1497: CLRF 01
.................... STATUS = 0x18;
1498: MOVLW 18
1499: MOVWF 03
.................... // bootloader should run now.
.................... //#asm
.................... //nop
.................... //BSF PCLATH, 0x3
.................... //BSF PCLATH, 0x4
.................... //GOTO 0x732
.................... //#endasm;
.................... #asm // toggle att'd LED so we know we got here.
.................... BSF 03.5
149A: BSF 03.5
.................... BCF 05.0
149B: BCF 05.0
.................... BCF 03.5
149C: BCF 03.5
.................... BCF 05.0
.................... #endasm
149D: BCF 05.0
....................
....................
.................... goto_address(BOOTLOADER_ENTRY);
149E: MOVLW 1F
149F: MOVWF 0A
14A0: MOVLW 31
14A1: MOVWF 02
.................... reset_cpu();
14A2: CLRF 0A
14A3: GOTO 000
.................... }</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514766 |
|
|
Tomi Guest
|
Re: bootloader re-entry STILL NOT working |
Posted: Tue May 27, 2003 1:07 am |
|
|
Check out the PCON register. Its bit#1 indicates the power-on reset. You have to set this bit after power-up. So I use something like this:
#byte PCON = 0x8E
In main():
if (!bit_test(PCON,1)) { // power-on reset
DoPowerUp();
bit_set(PCON,1); // PON reset is over
}
At "reset" command in the command dispatcher:
case BReset:
if (myflags & wrenab) { // if a generic write is enabled
myflags &= ~wrenab; // clear write enable flag
bit_clear(PCON,1); // tell to PIC: it is a power-on reset
SPOWER = 1; // turn off the external devices
while (1) ; // watchdog does it for me
}
break;
Note that I use the watchdog and my application is battery-based, too. This is not a problem. My board draws cca. 40uA from 12V (incl. the 12V-5V stabilizer).
I use a counter "toSleep". If this counter is zero, the PIC goes to sleep immediately right after wakeup. This means cca. 20usec active time in every seconds. If there is incoming data from the PC or the PIC needs extra time then this "toSleep" is extended, e.g. writing 5 means 5 seconds ("toSleep" is decremented in the Timer1 IT handler).
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514769 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|