CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Bootloader problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
fastlink30



Joined: 14 May 2007
Posts: 33

View user's profile Send private message

Bootloader problem
PostPosted: Wed Jun 20, 2007 12:55 pm     Reply with quote

i'm using this bootloader http://www.microchipc.com/PIC16bootload/
ccs 4.033
pic16f876

the problem is the continous reset of the pic, but only if i load the program with the booloader, if i load the program without the bootloader is all ok

the problem is the first 4 byte of code, if i try to see what happend in program memory i see the first lines for the bootloader correctly, but the first 4 lines of the program is disappeared overrides bt the bootlader.

is possible tell the compiler to not use the program memory from 0-4?
i tried with #org, but no luck
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 20, 2007 1:19 pm     Reply with quote

Are you sure that's the problem ? I remember using this bootloader
years ago, and I don't recall that there was a problem with using
interrupt routines in the application code.


I do remember that the default state for the bootloader HEX file
(and their ASM source code) was to have LVP enabled. You need
to set your programmer to disable LVP when you program the bootloader
code into your PIC.

They even have a FAQ question on this. Though, for a 16F876 the
PGM pin is on pin B3.
Quote:

Q Why does my circuit keep resetting? Or not start up at all?

By default, if you have Low Voltage Programming (LVP) enabled, touching pin RB4 will reset the micro. In the worst case, a bad logic level on RB4 will keep the micro in reset.


So, re-program the bootloader HEX file into the PIC, but disable LVP
in the Config bits options settings in your programmer.
Guest








PostPosted: Wed Jun 20, 2007 1:36 pm     Reply with quote

yes, i know about LVP, is disabled.

the problem is present only if i use the bootloader, otherwise all goes fine

watchdog & related interrupt are disabled

these are the first line of the bootloader only

NOP
BSF 0xa,0x3
BSF 0xa,0x4
GOTO 0x732

program:
NOP
MOVLW 0x8
MOVWF 0xa
GOTO 0
MOVWF 0x7f

these are the lines after load the program with bootloader
NOP
BSF 0xa,0x3
BSF 0xa,0x4
GOTO 0x732
MOVWF 0x7f

then... the program start anyway, but randomly the pic reset & return code 27 from reset_cause()

i have inserted a printf("AA"); in the main procedure, sometimes i see text, sometimes nothing
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 20, 2007 1:47 pm     Reply with quote

Post a little application program that demonstrates the problem.
Make the program be as small as possible. Make it be ten lines
of code, max. Post all #include, #use, #fuses statements.
fastlink30



Joined: 14 May 2007
Posts: 33

View user's profile Send private message

PostPosted: Thu Jun 21, 2007 1:18 am     Reply with quote

Code:

#include <16F876.h>
//#device icd=false
#use delay(clock=10000000)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#fuses NOWDT,HS, NOPUT, NOPROTECT, noBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG
#org 0x1F00, 0x1FFF void loader16F876(void) {} //protect bootloader code for the 8k 16F876/7


void main()
{
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   //port_b_pullups(false);
   printf("test");

   while(TRUE) {
      output_b(0);
      output_low(pin_a0);
      output_low(pin_a1);
      output_low(pin_a2);
      delay_ms(500);
      output_b(0xff);
      output_high(pin_a0);
      output_high(pin_a1);
      output_high(pin_a2);
      delay_ms(500);
   };

}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Jun 21, 2007 4:36 am     Reply with quote

Quote:
the problem is the first 4 byte of code, if i try to see what happend in program memory i see the first lines for the bootloader correctly, but the first 4 lines of the program is disappeared overrides bt the bootlader.

is possible tell the compiler to not use the program memory from 0-4?
i tried with #org, but no luck
Some background information: on power up the program starts execution at address 0, this is the reset vector.
The bootloader is located at a high address in memory and should be the first thing to start at power up. This is achieved by placing a long jump at address 0 - 4.
Now there is a conflict between the bootloader and your application as they both want to use these same 4 bytes.

Your suggestion of forcing your program not to use the first 4 addresses is one way to solve this conflict but has the disadvantage that you need two different versions of your program, one for standalone use and one version for use in combination with a bootloader.

Shane Tolmie uses a different approach for the address conflict which has the advantage that you don't have to change a thing to your program whether being used with or without a bootloader. On program writing the bootloader monitors the addresses to program. If the address range 0-4 is detected these four bytes are written to a reserved memory space inside the bootloader.
What happens at power up now is that the first 4 bytes contain a jump instruction to the bootloader. The bootloader executes normally and when finished executes the 4 bytes it has saved on flash writing time.
A nice and clean mechanism with only two minor drawbacks:
1) In order for this to work the first four bytes generated by the compiler must always contain a long jump. This is true for most compilers including CCS.
2) This only works reliable on processors where the flash memory can be programmed with single bytes. True for (most) PIC16 processors, but the PIC18 is written in blocks of 64 or more bytes.

Summary: The first four bytes of your program in memory are changed on purpose.

I checked your program in v3.249 to start with a long jump in the first 4 locations, this is true. I don't have v4.033 so can't check this for you.
Check the troubleshouting list at the bootloader's website for what a long jump looks like in assembly.
fastlink30



Joined: 14 May 2007
Posts: 33

View user's profile Send private message

PostPosted: Thu Jun 21, 2007 5:43 am     Reply with quote

first assembly lines of the program

Code:

CCS PCM C Compiler, Version 4.033, 6xxxx               21-giu-07 13.26

               Filename: C:\main.lst

               ROM used: 159 words (2%)
                         Largest free fragment is 2048
               RAM used: 8 (2%) at main() level
                         9 (2%) worst case
               Stack:    2 worst case (1 in main + 1 for interrupts)

*
0000:  MOVLW  00
0001:  MOVWF  0A
0002:  GOTO   023
0003:  NOP
.................... #include <16F876.h>
.................... //////// Standard Header file for the PIC16F876 device ////////////////
.................... #device PIC16F876
.................... #list
.................... 
.................... //#device icd=false
.................... #use delay(clock=10000000)
000E:  MOVLW  22
000F:  MOVWF  04
0010:  BCF    03.7
0011:  MOVF   00,W
0012:  BTFSC  03.2
0013:  GOTO   022
0014:  MOVLW  03
0015:  MOVWF  78
0016:  CLRF   77
0017:  DECFSZ 77,F
0018:  GOTO   017
0019:  DECFSZ 78,F
001A:  GOTO   016
001B:  MOVLW  3C
001C:  MOVWF  77
001D:  DECFSZ 77,F
001E:  GOTO   01D
001F:  GOTO   020
0020:  DECFSZ 00,F
0021:  GOTO   014
0022:  RETLW  00
.................... #use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
.................... 
.................... #fuses NOWDT,HS, NOPUT, NOPROTECT, noBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG
.................... #org 0x1F00, 0x1FFF void loader16F876(void) {} //protect bootloader code for the 8k 16F876/7
*
1F00:  RETLW  00
.................... 
.................... void main()
.................... {
*
0023:  CLRF   04
0024:  BCF    03.7
0025:  MOVLW  1F
0026:  ANDWF  03,F
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 21, 2007 12:01 pm     Reply with quote

Your code is doing a "long jump". It sets up PCLATH and then it does
a GOTO. I don't see a problem there.

But look at Shane's FAQ, here:
http://www.microchipc.com/PIC16bootload/PIC_bootloader_FAQ.php
In Section 4, he talks about the need for a long jump at the start.
He says:
Quote:
This section only applies to bootloader v6-52 and below.

So he must be doing something different now, because he's up v9-50.

I would read his FAQ in detail.
What programmer are you using to put the bootloader code into the PIC ?
He says there's a problem if you use ICD2. He wants you re-assemble
the bootloader ASM code.
fastlink30



Joined: 14 May 2007
Posts: 33

View user's profile Send private message

PostPosted: Thu Jun 21, 2007 1:52 pm     Reply with quote

i also read the faq, but no response

i'm using picstart+

i'm trying to make new bootloader to solve the problem
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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