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 CCS Technical Support

yes, another bootloader question re: ccs bootloader

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



Joined: 22 Sep 2003
Posts: 119

View user's profile Send private message

yes, another bootloader question re: ccs bootloader
PostPosted: Tue Oct 26, 2004 9:34 am     Reply with quote

I have decided to explore the ccs provided bootloader and am using compiler ver 3.130. The code sample compiles ok but when I use the ICD to program a 16f877, MPLAB warns that the code is addressing beyond address 0x2000 ?? I programmed the part anyhow and the bootloader begins to operate but when the L is entered to invoke the loader and I send the hex file via the send text file nothing happens. I am using hyperterm set for Xon/Xoff at 9600 baud. Any suggestions would be welcome.

Thanks Dan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 26, 2004 12:13 pm     Reply with quote

The Config Word for a 16F877 is at address 0x2007.
Hex files use byte addresses, so this will be seen as 0x400E.
Example:
:02400E00713F00

Is it possible that your programmer is set to prevent the Config Bits
from being programmed ?
If you think code has been put at an address above 0x1FFF, then
check the HEX file.

With respect to the apparent lock-up, the CCS example doesn't
have the 'Errors' parameter in the #use rs232() statement. You
could add it. You'd still get the error, but at least it wouldn't lock
up the program.

One simple way to track the progress of the program is to put in
little putc() statements, such as putc('A'), putc('B'), putc('C'), etc.
and when it locks up, you can see right where it happened.
I don't know how much space is left in that loader to allow for adding
these debug statements. You should check the .LST file to see.
dan king



Joined: 22 Sep 2003
Posts: 119

View user's profile Send private message

PostPosted: Tue Oct 26, 2004 1:28 pm     Reply with quote

I have included the list file, it appears that the bootloader code is being overwritten? Shouldn't the majority of the code be located at the high end of program memory? I'm not used to reviewing LST files so I'm interpreting that the address is the left most column and it appears that a lot of the boot code is low in memory.

You mentioned that the hex file can be viewed to verify the addressing, can't the lst file be used as well? I am not familiar with the format for hex files, so I don't see the pattern in your Example :(

I believe the config bits are being programmed with the ICD programmer because I have been using a assembly version bootloader that someone gave me and that programs fine. I wanted to start using a C loader that I could understand a little better. Not having much success with that Smile

I don't think I'm getting lockups, I think the boot code is being overwritten because a reset on the board after a transfer attempt does absolutely nothing. I have to reprogram with the ICD to get the code to respond again.

I typically use your suggested method of tracing with messages by sending characters, just didn't get that far yet.


Thanks for your help so far.



Code:
CCS PCM C Compiler, Version 3.130, 17162

               Filename: D:\MICROC~1\BOOT\EX_LOAD.LST

               ROM used: 488 (6%)
                         Largest free fragment is 2048
               RAM used: 71 (41%) at main() level
                         136 (78%) worst case
               Stack:    3 locations

*
0000:  MOVLW  00
0001:  MOVWF  0A
0002:  GOTO   05F
0003:  NOP
....................  ///////////////////////////////////////////////////////////////////////// 
.................... ////                          EX_LOAD.C                              //// 
.................... ////                                                                 //// 
.................... ////  This program uses the loader driver to show how you can        //// 
.................... ////  read and write to an internal program memory.                  //// 
.................... ////                                                                 //// 
.................... ////  The LOADER.C will take an Intel 8-bit Hex file over RS232      //// 
.................... ////  and modify the flash program memory with the new code.         //// 
.................... ////                                                                 //// 
.................... ////  After each good line, the loader sends an ACK character.  The  //// 
.................... ////  driver uses XON/XOFF flow control.  Also, any buffer on the PC //// 
.................... ////  UART must be turned off, or to its lowest setting, otherwise it//// 
.................... ////  will miss data.                                                //// 
.................... ////                                                                 //// 
.................... ////  A program such as Hyper-Term may be used to simply transmit the//// 
.................... ////  .HEX file output from the compiler.                            //// 
.................... ////                                                                 //// 
.................... ////  This example will work with the PCM and PCH compilers.  The    //// 
.................... ////  following conditional compilation lines are used to include a  //// 
.................... ////  valid device for each compiler.  Change the device, clock and  //// 
.................... ////  RS232 pins for your hardware if needed.                        //// 
.................... ///////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2001 Custom Computer Services         //// 
.................... //// This source code may only be used by licensed users of the CCS  //// 
.................... //// C compiler.  This source code may only be distributed to other  //// 
.................... //// licensed users of the CCS C compiler.  No other use,            //// 
.................... //// reproduction or distribution is permitted without written       //// 
.................... //// permission.  Derivative programs created using this software    //// 
.................... //// in object code form are not restricted in any way.              //// 
.................... ///////////////////////////////////////////////////////////////////////// 
....................   
....................   
.................... #if defined(__PCM__) 
.................... #include <16f877.h>
....................  //////// Standard Header file for the PIC16F877 device //////////////// 
.................... #device PIC16F877 
.................... #list 
.................... 
.................... #fuses HS,NOWDT,NOPROTECT 
.................... #use delay(clock=4000000) 
*
0048:  MOVLW  62
0049:  MOVWF  04
004A:  MOVF   00,W
004B:  BTFSC  03.2
004C:  GOTO   05C
004D:  MOVLW  01
004E:  MOVWF  78
004F:  CLRF   77
0050:  DECFSZ 77,F
0051:  GOTO   050
0052:  DECFSZ 78,F
0053:  GOTO   04F
0054:  MOVLW  4A
0055:  MOVWF  77
0056:  DECFSZ 77,F
0057:  GOTO   056
0058:  NOP
0059:  NOP
005A:  DECFSZ 00,F
005B:  GOTO   04D
005C:  BCF    0A.3
005D:  BCF    0A.4
005E:  GOTO   071 (RETURN)
.................... #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12 
....................   
.................... #elif defined(__PCH__) 
.................... #include <18f452.h> 
.................... #fuses HS,NOPROTECT 
.................... #use delay(clock=20000000) 
.................... #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12 
.................... #endif 
....................   
.................... #include <loader.c>
....................  /////////////////////////////////////////////////////////////////////////// 
.................... ////                         loader.c                                  //// 
.................... ////                                                                   //// 
.................... //// This driver will take an Intel 8-bit Hex file over RS232 channels //// 
.................... //// and modify the flash program memory with the new code.  A proxy   //// 
.................... //// function is required to sit between the real loading function     //// 
.................... //// and the main code because the #org preprocessor command could     //// 
.................... //// possibly change the order of functions within a defined block.    //// 
.................... ////                                                                   //// 
.................... //// After each good line, the loader sends an ACKLOD character.  The  //// 
.................... //// driver uses XON/XOFF flow control.  Also, any buffer on the PC    //// 
.................... //// UART must be turned off, or to its lowest setting, otherwise it   //// 
.................... //// will miss data.                                                   //// 
.................... ////                                                                   //// 
.................... ////                                                                   //// 
.................... /////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services           //// 
.................... //// This source code may only be used by licensed users of the CCS C  //// 
.................... //// compiler.  This source code may only be distributed to other      //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction //// 
.................... //// or distribution is permitted without written permission.          //// 
.................... //// Derivative programs created using this software in object code    //// 
.................... //// form are not restricted in any way.                               //// 
.................... /////////////////////////////////////////////////////////////////////////// 
....................   
.................... #define LOADER_END      getenv("PROGRAM_MEMORY")-1 
....................   
.................... #if defined(__PCM__) 
....................    #define LOADER_SIZE   0x15F 
.................... #elif defined(__PCH__) 
....................    #define LOADER_SIZE   0x3FF 
.................... #endif 
....................   
.................... #define LOADER_ADDR LOADER_END-LOADER_SIZE 
.................... #define BUFFER_LEN_LOD 64 
....................   
.................... int  buffidx; 
.................... char buffer[BUFFER_LEN_LOD]; 
....................   
.................... #define ACKLOD 0x06 
.................... #define XON    0x11 
.................... #define XOFF   0x13 
....................   
.................... #SEPARATE 
.................... unsigned int atoi_b16(char *s); 
....................   
.................... #ORG LOADER_ADDR+10, LOADER_END auto=0 default 
.................... void real_load_program (void) 
.................... { 
....................    int1  do_ACKLOD, done=FALSE; 
....................    int8  checksum, line_type; 
....................    int16 l_addr,h_addr=0; 
....................    int32 addr,next_addr; 
....................    int8  dataidx, i, count; 
*
1EE5:  BCF    61.1
1EE6:  CLRF   66
1EE7:  CLRF   67
....................    int8  data[32]; 
....................   
....................    while (!done)  // Loop until the entire program is downloaded 
1EE8:  BTFSC  61.1
1EE9:  GOTO   7E8
....................    { 
....................       buffidx = 0;  // Read into the buffer until 0x0D ('\r') is received or the buffer is full 
1EEA:  CLRF   20
....................       do { 
....................          buffer[buffidx++] = getc(); 
1EEB:  MOVF   20,W
1EEC:  INCF   20,F
1EED:  ADDLW  21
1EEE:  MOVWF  04
1EEF:  BTFSS  0C.5
1EF0:  GOTO   6EF
1EF1:  MOVF   1A,W
1EF2:  MOVWF  00
....................       } while ( (buffer[buffidx-1] != 0x0D) && (buffidx <= BUFFER_LEN_LOD) ); 
1EF3:  MOVLW  01
1EF4:  SUBWF  20,W
1EF5:  ADDLW  21
1EF6:  MOVWF  04
1EF7:  MOVF   00,W
1EF8:  SUBLW  0D
1EF9:  BTFSC  03.2
1EFA:  GOTO   6FF
1EFB:  MOVF   20,W
1EFC:  SUBLW  40
1EFD:  BTFSC  03.0
1EFE:  GOTO   6EB
....................   
....................       putchar (XOFF);  // Suspend sender 
1EFF:  MOVLW  13
1F00:  BTFSS  0C.4
1F01:  GOTO   700
1F02:  MOVWF  19
....................         
....................       do_ACKLOD = TRUE; 
1F03:  BSF    61.0
....................   
....................       // Only process data blocks that start with ':' 
....................       if (buffer[0] == ':') { 
1F04:  MOVF   21,W
1F05:  SUBLW  3A
1F06:  BTFSS  03.2
1F07:  GOTO   7DD
....................          count = atoi_b16 (&buffer[1]);  // Get the number of bytes from the buffer 
1F08:  MOVLW  22
1F09:  BSF    03.5
1F0A:  MOVWF  43
1F0B:  BCF    03.5
1F0C:  CALL   6AA
1F0D:  MOVF   78,W
1F0E:  MOVWF  72
....................   
....................          // Get the lower 16 bits of address 
....................          l_addr = make16(atoi_b16(&buffer[3]),atoi_b16(&buffer[5])); 
1F0F:  MOVLW  24
1F10:  BSF    03.5
1F11:  MOVWF  43
1F12:  BCF    03.5
1F13:  CALL   6AA
1F14:  MOVF   78,W
1F15:  MOVWF  73
1F16:  MOVLW  26
1F17:  BSF    03.5
1F18:  MOVWF  43
1F19:  BCF    03.5
1F1A:  CALL   6AA
1F1B:  MOVF   78,W
1F1C:  MOVWF  74
1F1D:  MOVF   73,W
1F1E:  MOVWF  65
1F1F:  MOVF   74,W
1F20:  MOVWF  64
....................   
....................          line_type = atoi_b16 (&buffer[7]); 
1F21:  MOVLW  28
1F22:  BSF    03.5
1F23:  MOVWF  43
1F24:  BCF    03.5
1F25:  CALL   6AA
1F26:  MOVF   78,W
1F27:  MOVWF  63
....................   
....................          addr = make32(h_addr,l_addr); 
1F28:  MOVF   66,W
1F29:  MOVWF  6A
1F2A:  MOVF   67,W
1F2B:  MOVWF  6B
1F2C:  MOVF   64,W
1F2D:  MOVWF  68
1F2E:  MOVF   65,W
1F2F:  MOVWF  69
....................   
....................          #if defined(__PCM__)  // PIC16 uses word addresses 
....................             addr /= 2; 
1F30:  BCF    03.0
1F31:  RRF    6B,F
1F32:  RRF    6A,F
1F33:  RRF    69,F
1F34:  RRF    68,F
....................          #endif 
....................   
....................          // If the line type is 1, then data is done being sent 
....................          if (line_type == 1) { 
1F35:  DECFSZ 63,W
1F36:  GOTO   739
....................             done = TRUE; 
1F37:  BSF    61.1
....................          } else if (addr < LOADER_ADDR) { 
1F38:  GOTO   7DD
1F39:  MOVF   6B,F
1F3A:  BTFSS  03.2
1F3B:  GOTO   7DD
1F3C:  MOVF   6A,F
1F3D:  BTFSS  03.2
1F3E:  GOTO   7DD
1F3F:  MOVF   69,W
1F40:  SUBLW  1E
1F41:  BTFSS  03.0
1F42:  GOTO   7DD
1F43:  BTFSS  03.2
1F44:  GOTO   749
1F45:  MOVF   68,W
1F46:  SUBLW  9F
1F47:  BTFSS  03.0
1F48:  GOTO   7DD
....................             checksum = 0;  // Sum the bytes to find the check sum value 
1F49:  CLRF   62
....................             for (i=1; i<(buffidx-3); i+=2) 
1F4A:  MOVLW  01
1F4B:  MOVWF  71
1F4C:  MOVLW  03
1F4D:  SUBWF  20,W
1F4E:  SUBWF  71,W
1F4F:  BTFSC  03.0
1F50:  GOTO   75D
....................                checksum += atoi_b16 (&buffer[i]); 
1F51:  MOVLW  21
1F52:  ADDWF  71,W
1F53:  MOVWF  73
1F54:  BSF    03.5
1F55:  MOVWF  43
1F56:  BCF    03.5
1F57:  CALL   6AA
1F58:  MOVF   78,W
1F59:  ADDWF  62,F
1F5A:  MOVLW  02
1F5B:  ADDWF  71,F
1F5C:  GOTO   74C
....................             checksum = 0xFF - checksum + 1; 
1F5D:  MOVF   62,W
1F5E:  SUBLW  FF
1F5F:  ADDLW  01
1F60:  MOVWF  62
....................   
....................             if (checksum != atoi_b16 (&buffer[buffidx-3])) 
1F61:  MOVLW  03
1F62:  SUBWF  20,W
1F63:  ADDLW  21
1F64:  MOVWF  74
1F65:  BSF    03.5
1F66:  MOVWF  43
1F67:  BCF    03.5
1F68:  CALL   6AA
1F69:  MOVF   78,W
1F6A:  SUBWF  62,W
1F6B:  BTFSC  03.2
1F6C:  GOTO   76F
....................                do_ACKLOD = FALSE; 
1F6D:  BCF    61.0
....................             else   { 
1F6E:  GOTO   7DD
....................                if (line_type == 0) { 
1F6F:  MOVF   63,F
1F70:  BTFSS  03.2
1F71:  GOTO   7C7
....................                   // Loops through all of the data and stores it in data 
....................                   // The last 2 bytes are the check sum, hence buffidx-3 
....................                   for (i = 9,dataidx=0; i < buffidx-3; i += 2) 
1F72:  MOVLW  09
1F73:  MOVWF  71
1F74:  CLRF   70
1F75:  MOVLW  03
1F76:  SUBWF  20,W
1F77:  SUBWF  71,W
1F78:  BTFSC  03.0
1F79:  GOTO   78C
....................                      data[dataidx++]=atoi_b16(&buffer[i]); 
1F7A:  MOVF   70,W
1F7B:  INCF   70,F
1F7C:  ADDLW  A0
1F7D:  MOVWF  74
1F7E:  MOVLW  21
1F7F:  ADDWF  71,W
1F80:  MOVWF  75
1F81:  BSF    03.5
1F82:  MOVWF  43
1F83:  BCF    03.5
1F84:  CALL   6AA
1F85:  MOVF   74,W
1F86:  MOVWF  04
1F87:  MOVF   78,W
1F88:  MOVWF  00
....................   
....................                   #if getenv("FLASH_ERASE_SIZE")>2 
1F89:  MOVLW  02
1F8A:  ADDWF  71,F
1F8B:  GOTO   775
....................                      #if defined(__PCM__) 
....................                         if ((addr!=next_addr)&&(addr&(getenv("FLASH_ERASE_SIZE")-1)!=0)) 
....................                      #else 
....................                         if ((addr!=next_addr)&&(addr&(getenv("FLASH_ERASE_SIZE")/2-1)!=0)) 
....................                      #endif 
....................                            erase_program_eeprom(addr); 
....................                   #endif 
....................                   write_program_memory(addr, data, count); 
1F8C:  MOVF   68,W
1F8D:  BSF    03.6
1F8E:  MOVWF  0D
1F8F:  BCF    03.6
1F90:  MOVF   69,W
1F91:  BSF    03.6
1F92:  MOVWF  0F
1F93:  MOVLW  A0
1F94:  MOVWF  04
1F95:  BCF    03.6
1F96:  MOVF   72,W
1F97:  MOVWF  79
1F98:  RRF    79,F
1F99:  MOVF   00,W
1F9A:  BSF    03.6
1F9B:  MOVWF  0C
1F9C:  INCF   04,F
1F9D:  MOVF   00,W
1F9E:  MOVWF  0E
1F9F:  INCF   04,F
1FA0:  BSF    03.5
1FA1:  BSF    0C.7
1FA2:  BSF    0C.2
1FA3:  BCF    03.5
1FA4:  BCF    03.6
1FA5:  MOVF   0B,W
1FA6:  MOVWF  78
1FA7:  BCF    0B.7
1FA8:  BSF    03.5
1FA9:  BSF    03.6
1FAA:  MOVLW  55
1FAB:  MOVWF  0D
1FAC:  MOVLW  AA
1FAD:  MOVWF  0D
1FAE:  BSF    0C.1
1FAF:  NOP
1FB0:  NOP
1FB1:  BCF    03.5
1FB2:  BCF    03.6
1FB3:  BSF    03.5
1FB4:  BSF    03.6
1FB5:  BTFSS  0C.1
1FB6:  GOTO   7BA
1FB7:  BCF    03.5
1FB8:  BCF    03.6
1FB9:  GOTO   7B3
1FBA:  BCF    0C.2
1FBB:  BCF    03.5
1FBC:  BCF    03.6
1FBD:  MOVF   78,W
1FBE:  IORWF  0B,F
1FBF:  BSF    03.6
1FC0:  INCF   0D,F
1FC1:  BTFSC  03.2
1FC2:  INCF   0F,F
1FC3:  BCF    03.6
1FC4:  DECFSZ 79,F
1FC5:  GOTO   799
....................                } 
....................                else if (line_type == 4) 
1FC6:  GOTO   7DD
1FC7:  MOVF   63,W
1FC8:  SUBLW  04
1FC9:  BTFSS  03.2
1FCA:  GOTO   7DD
....................                      h_addr = make16(atoi_b16(&buffer[9]), atoi_b16(&buffer[11])); 
1FCB:  MOVLW  2A
1FCC:  BSF    03.5
1FCD:  MOVWF  43
1FCE:  BCF    03.5
1FCF:  CALL   6AA
1FD0:  MOVF   78,W
1FD1:  MOVWF  73
1FD2:  MOVLW  2C
1FD3:  BSF    03.5
1FD4:  MOVWF  43
1FD5:  BCF    03.5
1FD6:  CALL   6AA
1FD7:  MOVF   78,W
1FD8:  MOVWF  74
1FD9:  MOVF   73,W
1FDA:  MOVWF  67
1FDB:  MOVF   74,W
1FDC:  MOVWF  66
....................             } 
....................          } 
....................       } 
....................   
....................       if (do_ACKLOD) 
1FDD:  BTFSS  61.0
1FDE:  GOTO   7E3
....................          putchar (ACKLOD); 
1FDF:  MOVLW  06
1FE0:  BTFSS  0C.4
1FE1:  GOTO   7E0
1FE2:  MOVWF  19
....................   
....................       putchar(XON); 
1FE3:  MOVLW  11
1FE4:  BTFSS  0C.4
1FE5:  GOTO   7E4
1FE6:  MOVWF  19
....................    } 
1FE7:  GOTO   6E8
....................   
....................    putchar (ACKLOD); 
1FE8:  MOVLW  06
1FE9:  BTFSS  0C.4
1FEA:  GOTO   7E9
1FEB:  MOVWF  19
....................    putchar(XON); 
1FEC:  MOVLW  11
1FED:  BTFSS  0C.4
1FEE:  GOTO   7ED
1FEF:  MOVWF  19
....................    reset_cpu(); 
1FF0:  CLRF   0A
1FF1:  GOTO   000
1FF2:  RETLW  00
.................... } 
....................   
.................... unsigned int atoi_b16(char *s) {  // Convert two hex characters to a int8 
....................    unsigned int result = 0; 
*
1EAA:  BSF    03.5
1EAB:  CLRF   44
....................    int i; 
....................   
....................    for (i=0; i<2; i++,s++)  { 
1EAC:  CLRF   45
1EAD:  BCF    03.5
1EAE:  BSF    03.5
1EAF:  MOVF   45,W
1EB0:  SUBLW  01
1EB1:  BTFSC  03.0
1EB2:  GOTO   6B5
1EB3:  BCF    03.5
1EB4:  GOTO   6E0
1EB5:  BCF    03.5
....................       if (*s >= 'A') 
1EB6:  BSF    03.5
1EB7:  MOVF   43,W
1EB8:  MOVWF  04
1EB9:  MOVF   00,W
1EBA:  SUBLW  40
1EBB:  BTFSS  03.0
1EBC:  GOTO   6BF
1EBD:  BCF    03.5
1EBE:  GOTO   6CE
1EBF:  BCF    03.5
....................          result = 16*result + (*s) - 'A' + 10; 
1EC0:  BSF    03.5
1EC1:  SWAPF  44,W
1EC2:  MOVWF  46
1EC3:  MOVLW  F0
1EC4:  ANDWF  46,F
1EC5:  MOVF   43,W
1EC6:  MOVWF  04
1EC7:  MOVF   00,W
1EC8:  ADDWF  46,W
1EC9:  ADDLW  BF
1ECA:  ADDLW  0A
1ECB:  MOVWF  44
....................       else 
1ECC:  BCF    03.5
1ECD:  GOTO   6DA
....................          result = 16*result + (*s) - '0'; 
1ECE:  BSF    03.5
1ECF:  SWAPF  44,W
1ED0:  MOVWF  46
1ED1:  MOVLW  F0
1ED2:  ANDWF  46,F
1ED3:  MOVF   43,W
1ED4:  MOVWF  04
1ED5:  MOVF   00,W
1ED6:  ADDWF  46,W
1ED7:  ADDLW  D0
1ED8:  MOVWF  44
1ED9:  BCF    03.5
....................    } 
1EDA:  BSF    03.5
1EDB:  MOVF   45,W
1EDC:  INCF   45,F
1EDD:  INCF   43,F
1EDE:  BCF    03.5
1EDF:  GOTO   6AE
....................   
....................    return(result); 
1EE0:  BSF    03.5
1EE1:  MOVF   44,W
1EE2:  BCF    03.5
1EE3:  MOVWF  78
1EE4:  RETLW  00
.................... } 
....................   
.................... #ORG default 
....................   
....................   
.................... #ORG LOADER_ADDR, LOADER_ADDR+9 
.................... void load_program(void) 
.................... { 
....................    real_load_program(); 
*
1EA0:  CALL   6E5
1EA1:  RETLW  00
.................... } 
.................... 
....................   
....................   
.................... void main() 
.................... { 
*
005F:  CLRF   04
0060:  MOVLW  1F
0061:  ANDWF  03,F
0062:  MOVLW  07
0063:  BSF    03.5
0064:  MOVWF  1F
0065:  MOVLW  19
0066:  MOVWF  19
0067:  MOVLW  26
0068:  MOVWF  18
0069:  MOVLW  90
006A:  BCF    03.5
006B:  MOVWF  18
....................    //clears out the rs232 buffer 
....................    delay_ms (1000); 
006C:  MOVLW  04
006D:  MOVWF  61
006E:  MOVLW  FA
006F:  MOVWF  62
0070:  GOTO   048
0071:  DECFSZ 61,F
0072:  GOTO   06E
....................    while (kbhit()) 
0073:  BTFSS  0C.5
0074:  GOTO   079
....................       getc(); 
0075:  BTFSS  0C.5
0076:  GOTO   075
0077:  MOVF   1A,W
0078:  GOTO   073
....................   
....................    do { 
....................       printf("\r\nSoftware Version A!\r\n"); 
*
0004:  BCF    0A.0
0005:  BCF    0A.1
0006:  BCF    0A.2
0007:  ADDWF  02,F
0008:  RETLW  0D
0009:  RETLW  0A
000A:  RETLW  53
000B:  RETLW  6F
000C:  RETLW  66
000D:  RETLW  74
000E:  RETLW  77
000F:  RETLW  61
0010:  RETLW  72
0011:  RETLW  65
0012:  RETLW  20
0013:  RETLW  56
0014:  RETLW  65
0015:  RETLW  72
0016:  RETLW  73
0017:  RETLW  69
0018:  RETLW  6F
0019:  RETLW  6E
001A:  RETLW  20
001B:  RETLW  41
001C:  RETLW  21
001D:  RETLW  0D
001E:  RETLW  0A
001F:  RETLW  00
*
0079:  CLRF   61
007A:  MOVF   61,W
007B:  CALL   004
007C:  INCF   61,F
007D:  MOVWF  77
007E:  BTFSS  0C.4
007F:  GOTO   07E
0080:  MOVWF  19
0081:  MOVLW  17
0082:  SUBWF  61,W
0083:  BTFSS  03.2
0084:  GOTO   07A
....................       printf("Press L to download new software.\r\n"); 
*
0020:  BCF    0A.0
0021:  BCF    0A.1
0022:  BCF    0A.2
0023:  ADDWF  02,F
0024:  RETLW  50
0025:  RETLW  72
0026:  RETLW  65
0027:  RETLW  73
0028:  RETLW  73
0029:  RETLW  20
002A:  RETLW  4C
002B:  RETLW  20
002C:  RETLW  74
002D:  RETLW  6F
002E:  RETLW  20
002F:  RETLW  64
0030:  RETLW  6F
0031:  RETLW  77
0032:  RETLW  6E
0033:  RETLW  6C
0034:  RETLW  6F
0035:  RETLW  61
0036:  RETLW  64
0037:  RETLW  20
0038:  RETLW  6E
0039:  RETLW  65
003A:  RETLW  77
003B:  RETLW  20
003C:  RETLW  73
003D:  RETLW  6F
003E:  RETLW  66
003F:  RETLW  74
0040:  RETLW  77
0041:  RETLW  61
0042:  RETLW  72
0043:  RETLW  65
0044:  RETLW  2E
0045:  RETLW  0D
0046:  RETLW  0A
0047:  RETLW  00
*
0085:  CLRF   61
0086:  MOVF   61,W
0087:  CALL   020
0088:  INCF   61,F
0089:  MOVWF  77
008A:  BTFSS  0C.4
008B:  GOTO   08A
008C:  MOVWF  19
008D:  MOVLW  23
008E:  SUBWF  61,W
008F:  BTFSS  03.2
0090:  GOTO   086
....................    } while (getc()!='L'); 
0091:  BTFSS  0C.5
0092:  GOTO   091
0093:  MOVF   1A,W
0094:  SUBLW  4C
0095:  BTFSS  03.2
0096:  GOTO   079
....................   
....................    load_program (); 
0097:  BSF    0A.4
0098:  BSF    0A.3
0099:  CALL   6A0
009A:  BCF    0A.4
009B:  BCF    0A.3
.................... } 
.................... 
009C:  SLEEP
dan king



Joined: 22 Sep 2003
Posts: 119

View user's profile Send private message

PostPosted: Tue Oct 26, 2004 2:11 pm     Reply with quote

I found a good app note from microchip (AN732) detailing the hex format. Thanks for the direction, I understand your previous example now and can verify that I don't have code above the max program limit.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 26, 2004 2:29 pm     Reply with quote

Before we go any farther, can you do these two things ?
1. Put NOLVP at the end of the #fuses statement.
2. Put ERRORS at the end of the #use rs232() statement.
The changes are shown in bold, below.

#if defined(__PCM__)
#include <16f877.h>
#fuses HS,NOWDT,NOPROTECT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
dan king



Joined: 22 Sep 2003
Posts: 119

View user's profile Send private message

PostPosted: Tue Oct 26, 2004 2:44 pm     Reply with quote

Ok, I added the lines you requested but I still get the same response. When I typed my initial post I stated that when I pressed the 'L' nothing happened when I attempted to send the hex file. At that time I had the ending program address for the ICD set to 1EFF, not sure why so I changed it to 1FFF. Since then I get one black spade returned when I attempt to send the hex code. After that, nothing as in I have to reload the bootloader with the ICD because I believe the bootloader was overwritten. This is still the same results after the modifications you requested I make.

Do I need to add a #ORG to the code to be downloaded with the bootloader to prevent the new code from overwriting the bootloader?
Jeff King



Joined: 20 Oct 2003
Posts: 43
Location: Hillsdale, Michigan USA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Oct 26, 2004 3:53 pm     Reply with quote

Dan:

Try SIOW.EXE which is available via the "TOOLS" window of the CCS compilier for your uploaded. Under the file menu pulldown, there should be a selection for "Download Software". In developing a client app for the bootloader, I used SIOW as my reference, and it always seemed to work if things where OK with the bootloader.

Also see my recent posting on the bootloader example. Not heard back from CCS but I wouldn't assume things are kosher in the bootloader.

Looking at your code you have:

Code:
....................          // If the line type is 1, then data is done being sent 
....................          if (line_type == 1) { 
1F35:  DECFSZ 63,W
1F36:  GOTO   739
....................             done = TRUE; 
1F37:  BSF    61.1
....................          } else if (addr < LOADER_ADDR) { 



Where as the listing for loader.c was:
Code:

// If the line type is 1, then data is done being sent
         if (line_type == 1) {
            done = TRUE;
         #if defined(__PCM__)
         } else if ((addr < LOADER_ADDR || addr > LOADER_END) && addr < 0x2000){
         #elif defined(__PCH__)
         } else if ((addr < LOADER_ADDR || addr > LOADER_END) && addr < 0x300000){
         #endif


and what I think you should have is:


Code:
         } else if ((addr > LOADER_END) && addr < 0x2000){


This will keep the bootloader from overwriting itself, the reset vectors and the config bits.

(and the difference between this and the example bootloader was the basis for my question yesterday).

Let me know how it goes as I have similar concerns.

-Jeff
dan king



Joined: 22 Sep 2003
Posts: 119

View user's profile Send private message

PostPosted: Thu Nov 04, 2004 9:52 am     Reply with quote

Jeff,

I guess my rev of loader.c is older than yours because the code snippet you included in your previous post is not quite the same in mine.

Either way, I don't think your suggested change will work because Loader_end is the max address in program memory and we just want to check that the new code won't over write the boot code, so checking to verify that addr > loader_end isn't valid. The sample code I have checks for the code address to be < LOADER_ADDR which is valid because that is the start of the bootloader code and as long as we're less than that we should be OK.

One of the several problems I found with the CCS example is that too much code is resident in low memory and gets overwritten with user code which then renders the bootloader useless. The LST file uncovers this problem.

FWIW: I gave up on the CCS bootloader because it needed too many additions to get it to a point of being really useful. A better start is to check out the bootloader code from theByteFactory.com - codeloader_m.c That application works well and covers a lot of the bases for error checking and relocating the reset vector.

Thanks for your input.

Dan
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