|
|
View previous topic :: View next topic |
Author |
Message |
Nick Guest
|
write_program_memory, software locks up when called |
Posted: Sun Sep 18, 2005 2:14 pm |
|
|
I'm trying to use loader.c as a boot loader, but after it trys and writes it stops responding
I'm pretty sure its locking up on the line
write_program_memory(addr, data, count);
count = 16
addr = 0
data should be correct because i dont get a checksum error
This chip is a pic16f876a. Please help |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 18, 2005 2:15 pm |
|
|
What is your version of the PCM compiler ? This will be a number
like 2.734, 3.191, or 3.234, etc. |
|
|
Nick Guest
|
|
Posted: Sun Sep 18, 2005 2:17 pm |
|
|
3.187 registered under nick tullos
and forgot to mention that I disabled the interupts before the call.
Nick |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 18, 2005 2:24 pm |
|
|
Quote: | 3.187 registered under nick tullos |
OK, I'll look at the code, but you don't have to give your name.
I don't work for CCS. I just like to do analysis on tech problems. |
|
|
nick Guest
|
|
Posted: Sun Sep 18, 2005 2:27 pm |
|
|
thank you very much.
I want to know if it its my problem or a CCS compiler problem. Thanks again
Nick |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 18, 2005 2:59 pm |
|
|
I looked at the .LST files for a small test program for PCM vs. 3.187
and 3.233, and there are some differences.
But before I do any more, I have to say that I noticed that CCS puts
the code that writes to flash memory at address 0x0004.
So in your example, you're writing 16 bytes to address 0, which
will clobber the very code that's doing the writing. |
|
|
Nick Guest
|
|
Posted: Sun Sep 18, 2005 3:25 pm |
|
|
thanks for the tip, that is probably where the problem is happening.
Nick |
|
|
Guest
|
|
Posted: Sun Sep 18, 2005 5:10 pm |
|
|
Code: |
CCS PCM C Compiler, Version 3.187, 25251
Filename: C:\Documents and Settings\nick\Desktop\SVN_New\BoostController\boost_alg_v3_7_boot.LST
ROM used: 6836 (83%)
Largest free fragment is 511
RAM used: 164 (45%) at main() level
243 (66%) worst case
Stack: 6 worst case (5 in main + 1 for interrupts)
*
0000: MOVLW 10
0001: MOVWF 0A
0002: GOTO 000
0003: NOP
0004: MOVWF 7F
0005: SWAPF 03,W
0006: CLRF 03
0007: MOVWF 21
0008: MOVF 0A,W
0009: MOVWF 20
000A: CLRF 0A
000B: MOVF 04,W
000C: MOVWF 22
000D: MOVF 77,W
000E: MOVWF 23
000F: MOVF 78,W
0010: MOVWF 24
0011: MOVF 79,W
0012: MOVWF 25
0013: MOVF 7A,W
0014: MOVWF 26
0015: MOVF 7B,W
0016: MOVWF 27
0017: BCF 03.7
0018: BCF 03.5
0019: MOVLW 8C
001A: MOVWF 04
001B: BTFSS 00.1
001C: GOTO 01F
001D: BTFSC 0C.1
001E: GOTO 032
001F: MOVF 22,W
0020: MOVWF 04
0021: MOVF 23,W
0022: MOVWF 77
0023: MOVF 24,W
0024: MOVWF 78
0025: MOVF 25,W
0026: MOVWF 79
0027: MOVF 26,W
0028: MOVWF 7A
0029: MOVF 27,W
002A: MOVWF 7B
002B: MOVF 20,W
002C: MOVWF 0A
002D: SWAPF 21,W
002E: MOVWF 03
002F: SWAPF 7F,F
0030: SWAPF 7F,W
0031: RETFIE
0032: BCF 0A.3
0033: BCF 0A.4
0034: GOTO 0FE
.................... //Current known problems
.................... //
.................... //
.................... //
.................... //
.................... //
.................... //////////////////////////////////////////
.................... // Defaults
.................... #DEFINE HVX 1
.................... #DEFINE HVY 0
.................... #DEFINE FVX 3
.................... #DEFINE FVY 3
.................... #DEFINE LOCKD 0
.................... #DEFINE HIGHB 175
.................... #DEFINE LOWB 160
.................... #DEFINE MAXB 183
.................... #DEFINE OVERPWM 85
.................... #DEFINE LOWSHIFTTIME 2
.................... #DEFINE HIGHSHIFTTIME 20
.................... #DEFINE SHIFTBUFFER 10
.................... #DEFINE SHIFTENABLE 1
.................... #DEFINE IDLEPWM 30
.................... #DEFINE LOWESTPWM 12
.................... #DEFINE UNDERBOOSTRCT 2
.................... #DEFINE OVERBOOSTRCT 1
.................... #DEFINE ENABLEUNDERBOOSTRCT 1
.................... #DEFINE ENABLEOVERBOOSTRCT 1
.................... //not used yet
.................... #DEFINE LOCKGAIN 0
.................... #DEFINE BOOSTGAIN 12
.................... #DEFINE ENABLEOVERBOOST 0
.................... #DEFINE ENABLEDYNAMICOVERBOOST 0
.................... #DEFINE GAINRESHIGH 2
.................... #DEFINE GAINRESLOW 0
.................... #DEFINE BOOSTADD 100
.................... #DEFINE BOOSTMULTI 80
....................
.................... //
.................... ///////////////////////////////////
.................... //
.................... //PORT assigments for Version 1.0
.................... //
.................... // B7 - Inside LED 2
.................... #DEFINE BOOSTLED PIN_B7
.................... // B6 - Inside LED 1
.................... #DEFINE ONLED PIN_B5
.................... // B5 - Outside LED 2
.................... // B4 - Outside LED 1
.................... // B3 - AUX FET
.................... // B2 - Main FET
.................... #DEFINE MAINFET PIN_B3
.................... // B1 - Switch
.................... #DEFINE BSWITCH PIN_B1
.................... // B0 - NA
.................... //
.................... // C7 - RS232
.................... // C6 - RS232
.................... //set fuses
....................
.................... //#fuses HS,NOWDT,NOPROTECT,NOLVP
....................
.................... #include <16F876A.h>
.................... //////// Standard Header file for the PIC16F876A device ////////////////
.................... #device PIC16F876A
.................... #list
....................
.................... #fuses HS,NOWDT,NOPROTECT,NOLVP
.................... #device *=16
.................... #use delay(clock=20000000)
*
01B8: MOVLW EB
01B9: MOVWF 04
01BA: BCF 03.7
01BB: MOVF 00,W
01BC: BTFSC 03.2
01BD: GOTO 1CB
01BE: MOVLW 06
01BF: MOVWF 78
01C0: CLRF 77
01C1: DECFSZ 77,F
01C2: GOTO 1C1
01C3: DECFSZ 78,F
01C4: GOTO 1C0
01C5: MOVLW 7B
01C6: MOVWF 77
01C7: DECFSZ 77,F
01C8: GOTO 1C7
01C9: DECFSZ 00,F
01CA: GOTO 1BE
01CB: RETLW 00
.................... #use rs232(baud=38400, xmit=PIN_C6, rcv=PIN_C7)
....................
....................
....................
.................... //#include <LOADER_enc2.c>
.................... #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. ////
.................... ///////////////////////////////////////////////////////////////////////////
....................
.................... #ifndef LOADER_END
....................
.................... #define LOADER_END getenv("PROGRAM_MEMORY")-1
....................
.................... #if defined(__PCM__)
.................... #define LOADER_SIZE 0x65F
.................... //#elif defined(__PCH__)
.................... // #define LOADER_SIZE 0x3FF
.................... //#endif
.................... //
.................... #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;
*
1B65: BSF 03.5
1B66: BCF 62.1
.................... int8 checksum, line_type;
.................... int16 l_addr,h_addr=0;
|
in my file it looks like flash code starts at 1B65, i could be reading the file wrong.
Nick[/code] |
|
|
Guest
|
|
Posted: Sun Sep 18, 2005 5:12 pm |
|
|
Code: |
CCS PCM C Compiler, Version 3.187, 25251
Filename: C:\Documents and Settings\nick\Desktop\SVN_New\BoostController\boost_alg_v3_7_boot.LST
ROM used: 6836 (83%)
Largest free fragment is 511
RAM used: 164 (45%) at main() level
243 (66%) worst case
Stack: 6 worst case (5 in main + 1 for interrupts)
*
0000: MOVLW 10
0001: MOVWF 0A
0002: GOTO 000
0003: NOP
0004: MOVWF 7F
0005: SWAPF 03,W
0006: CLRF 03
0007: MOVWF 21
0008: MOVF 0A,W
0009: MOVWF 20
000A: CLRF 0A
000B: MOVF 04,W
000C: MOVWF 22
000D: MOVF 77,W
000E: MOVWF 23
000F: MOVF 78,W
0010: MOVWF 24
0011: MOVF 79,W
0012: MOVWF 25
0013: MOVF 7A,W
0014: MOVWF 26
0015: MOVF 7B,W
0016: MOVWF 27
0017: BCF 03.7
0018: BCF 03.5
0019: MOVLW 8C
001A: MOVWF 04
001B: BTFSS 00.1
001C: GOTO 01F
001D: BTFSC 0C.1
001E: GOTO 032
001F: MOVF 22,W
0020: MOVWF 04
0021: MOVF 23,W
0022: MOVWF 77
0023: MOVF 24,W
0024: MOVWF 78
0025: MOVF 25,W
0026: MOVWF 79
0027: MOVF 26,W
0028: MOVWF 7A
0029: MOVF 27,W
002A: MOVWF 7B
002B: MOVF 20,W
002C: MOVWF 0A
002D: SWAPF 21,W
002E: MOVWF 03
002F: SWAPF 7F,F
0030: SWAPF 7F,W
0031: RETFIE
0032: BCF 0A.3
0033: BCF 0A.4
0034: GOTO 0FE
.................... //Current known problems
.................... //
.................... //
.................... //
.................... //
.................... //
.................... //////////////////////////////////////////
.................... // Defaults
.................... #DEFINE HVX 1
.................... #DEFINE HVY 0
.................... #DEFINE FVX 3
.................... #DEFINE FVY 3
.................... #DEFINE LOCKD 0
.................... #DEFINE HIGHB 175
.................... #DEFINE LOWB 160
.................... #DEFINE MAXB 183
.................... #DEFINE OVERPWM 85
.................... #DEFINE LOWSHIFTTIME 2
.................... #DEFINE HIGHSHIFTTIME 20
.................... #DEFINE SHIFTBUFFER 10
.................... #DEFINE SHIFTENABLE 1
.................... #DEFINE IDLEPWM 30
.................... #DEFINE LOWESTPWM 12
.................... #DEFINE UNDERBOOSTRCT 2
.................... #DEFINE OVERBOOSTRCT 1
.................... #DEFINE ENABLEUNDERBOOSTRCT 1
.................... #DEFINE ENABLEOVERBOOSTRCT 1
.................... //not used yet
.................... #DEFINE LOCKGAIN 0
.................... #DEFINE BOOSTGAIN 12
.................... #DEFINE ENABLEOVERBOOST 0
.................... #DEFINE ENABLEDYNAMICOVERBOOST 0
.................... #DEFINE GAINRESHIGH 2
.................... #DEFINE GAINRESLOW 0
.................... #DEFINE BOOSTADD 100
.................... #DEFINE BOOSTMULTI 80
....................
.................... //
.................... ///////////////////////////////////
.................... //
.................... //PORT assigments for Version 1.0
.................... //
.................... // B7 - Inside LED 2
.................... #DEFINE BOOSTLED PIN_B7
.................... // B6 - Inside LED 1
.................... #DEFINE ONLED PIN_B5
.................... // B5 - Outside LED 2
.................... // B4 - Outside LED 1
.................... // B3 - AUX FET
.................... // B2 - Main FET
.................... #DEFINE MAINFET PIN_B3
.................... // B1 - Switch
.................... #DEFINE BSWITCH PIN_B1
.................... // B0 - NA
.................... //
.................... // C7 - RS232
.................... // C6 - RS232
.................... //set fuses
....................
.................... //#fuses HS,NOWDT,NOPROTECT,NOLVP
....................
.................... #include <16F876A.h>
.................... //////// Standard Header file for the PIC16F876A device ////////////////
.................... #device PIC16F876A
.................... #list
....................
.................... #fuses HS,NOWDT,NOPROTECT,NOLVP
.................... #device *=16
.................... #use delay(clock=20000000)
*
01B8: MOVLW EB
01B9: MOVWF 04
01BA: BCF 03.7
01BB: MOVF 00,W
01BC: BTFSC 03.2
01BD: GOTO 1CB
01BE: MOVLW 06
01BF: MOVWF 78
01C0: CLRF 77
01C1: DECFSZ 77,F
01C2: GOTO 1C1
01C3: DECFSZ 78,F
01C4: GOTO 1C0
01C5: MOVLW 7B
01C6: MOVWF 77
01C7: DECFSZ 77,F
01C8: GOTO 1C7
01C9: DECFSZ 00,F
01CA: GOTO 1BE
01CB: RETLW 00
.................... #use rs232(baud=38400, xmit=PIN_C6, rcv=PIN_C7)
....................
....................
....................
.................... //#include <LOADER_enc2.c>
.................... #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. ////
.................... ///////////////////////////////////////////////////////////////////////////
....................
.................... #ifndef LOADER_END
....................
.................... #define LOADER_END getenv("PROGRAM_MEMORY")-1
....................
.................... #if defined(__PCM__)
.................... #define LOADER_SIZE 0x65F
.................... //#elif defined(__PCH__)
.................... // #define LOADER_SIZE 0x3FF
.................... //#endif
.................... //
.................... #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;
*
1B65: BSF 03.5
1B66: BCF 62.1
.................... int8 checksum, line_type;
.................... int16 l_addr,h_addr=0;
|
in my file it looks like flash code starts at 1B65, i could be reading the file wrong.
Nick[/code] |
|
|
Nick Guest
|
|
Posted: Sun Sep 18, 2005 5:13 pm |
|
|
Code: |
CCS PCM C Compiler, Version 3.187, 25251
Filename: C:\Documents and Settings\nick\Desktop\SVN_New\BoostController\boost_alg_v3_7_boot.LST
ROM used: 6836 (83%)
Largest free fragment is 511
RAM used: 164 (45%) at main() level
243 (66%) worst case
Stack: 6 worst case (5 in main + 1 for interrupts)
*
0000: MOVLW 10
0001: MOVWF 0A
0002: GOTO 000
0003: NOP
0004: MOVWF 7F
0005: SWAPF 03,W
0006: CLRF 03
0007: MOVWF 21
0008: MOVF 0A,W
0009: MOVWF 20
000A: CLRF 0A
000B: MOVF 04,W
000C: MOVWF 22
000D: MOVF 77,W
000E: MOVWF 23
000F: MOVF 78,W
0010: MOVWF 24
0011: MOVF 79,W
0012: MOVWF 25
0013: MOVF 7A,W
0014: MOVWF 26
0015: MOVF 7B,W
0016: MOVWF 27
0017: BCF 03.7
0018: BCF 03.5
0019: MOVLW 8C
001A: MOVWF 04
001B: BTFSS 00.1
001C: GOTO 01F
001D: BTFSC 0C.1
001E: GOTO 032
001F: MOVF 22,W
0020: MOVWF 04
0021: MOVF 23,W
0022: MOVWF 77
0023: MOVF 24,W
0024: MOVWF 78
0025: MOVF 25,W
0026: MOVWF 79
0027: MOVF 26,W
0028: MOVWF 7A
0029: MOVF 27,W
002A: MOVWF 7B
002B: MOVF 20,W
002C: MOVWF 0A
002D: SWAPF 21,W
002E: MOVWF 03
002F: SWAPF 7F,F
0030: SWAPF 7F,W
0031: RETFIE
0032: BCF 0A.3
0033: BCF 0A.4
0034: GOTO 0FE
.................... //Current known problems
.................... //
.................... //
.................... //
.................... //
.................... //
.................... //////////////////////////////////////////
.................... // Defaults
.................... #DEFINE HVX 1
.................... #DEFINE HVY 0
.................... #DEFINE FVX 3
.................... #DEFINE FVY 3
.................... #DEFINE LOCKD 0
.................... #DEFINE HIGHB 175
.................... #DEFINE LOWB 160
.................... #DEFINE MAXB 183
.................... #DEFINE OVERPWM 85
.................... #DEFINE LOWSHIFTTIME 2
.................... #DEFINE HIGHSHIFTTIME 20
.................... #DEFINE SHIFTBUFFER 10
.................... #DEFINE SHIFTENABLE 1
.................... #DEFINE IDLEPWM 30
.................... #DEFINE LOWESTPWM 12
.................... #DEFINE UNDERBOOSTRCT 2
.................... #DEFINE OVERBOOSTRCT 1
.................... #DEFINE ENABLEUNDERBOOSTRCT 1
.................... #DEFINE ENABLEOVERBOOSTRCT 1
.................... //not used yet
.................... #DEFINE LOCKGAIN 0
.................... #DEFINE BOOSTGAIN 12
.................... #DEFINE ENABLEOVERBOOST 0
.................... #DEFINE ENABLEDYNAMICOVERBOOST 0
.................... #DEFINE GAINRESHIGH 2
.................... #DEFINE GAINRESLOW 0
.................... #DEFINE BOOSTADD 100
.................... #DEFINE BOOSTMULTI 80
....................
.................... //
.................... ///////////////////////////////////
.................... //
.................... //PORT assigments for Version 1.0
.................... //
.................... // B7 - Inside LED 2
.................... #DEFINE BOOSTLED PIN_B7
.................... // B6 - Inside LED 1
.................... #DEFINE ONLED PIN_B5
.................... // B5 - Outside LED 2
.................... // B4 - Outside LED 1
.................... // B3 - AUX FET
.................... // B2 - Main FET
.................... #DEFINE MAINFET PIN_B3
.................... // B1 - Switch
.................... #DEFINE BSWITCH PIN_B1
.................... // B0 - NA
.................... //
.................... // C7 - RS232
.................... // C6 - RS232
.................... //set fuses
....................
.................... //#fuses HS,NOWDT,NOPROTECT,NOLVP
....................
.................... #include <16F876A.h>
.................... //////// Standard Header file for the PIC16F876A device ////////////////
.................... #device PIC16F876A
.................... #list
....................
.................... #fuses HS,NOWDT,NOPROTECT,NOLVP
.................... #device *=16
.................... #use delay(clock=20000000)
*
01B8: MOVLW EB
01B9: MOVWF 04
01BA: BCF 03.7
01BB: MOVF 00,W
01BC: BTFSC 03.2
01BD: GOTO 1CB
01BE: MOVLW 06
01BF: MOVWF 78
01C0: CLRF 77
01C1: DECFSZ 77,F
01C2: GOTO 1C1
01C3: DECFSZ 78,F
01C4: GOTO 1C0
01C5: MOVLW 7B
01C6: MOVWF 77
01C7: DECFSZ 77,F
01C8: GOTO 1C7
01C9: DECFSZ 00,F
01CA: GOTO 1BE
01CB: RETLW 00
.................... #use rs232(baud=38400, xmit=PIN_C6, rcv=PIN_C7)
....................
....................
....................
.................... //#include <LOADER_enc2.c>
.................... #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. ////
.................... ///////////////////////////////////////////////////////////////////////////
....................
.................... #ifndef LOADER_END
....................
.................... #define LOADER_END getenv("PROGRAM_MEMORY")-1
....................
.................... #if defined(__PCM__)
.................... #define LOADER_SIZE 0x65F
.................... //#elif defined(__PCH__)
.................... // #define LOADER_SIZE 0x3FF
.................... //#endif
.................... //
.................... #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;
*
1B65: BSF 03.5
1B66: BCF 62.1
.................... int8 checksum, line_type;
.................... int16 l_addr,h_addr=0;
|
in my file it looks like flash code starts at 1B65, i could be reading the file wrong.
Nick[/code] |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 18, 2005 6:00 pm |
|
|
First I should say that if you had registered and clicked the little box
that says "log me in automatically each visit", then you could have
deleted that extra post.
But anyway, your code shows the CCS interrupt dispatcher at address
0x0004 and it's checking for the Timer2 interrupt.
Do you have global interupts enabled while you're flashing the program
memory ? If so, a Timer2 interrupt could occur. What happens
when it tries to execute code in the interrupt dispatcher that's been
partially erased or re-programmed ? It probably crashes.
So I think you should disable Global interrupts before you call the
write_program_memory() function. |
|
|
Nick Guest
|
|
Posted: Sun Sep 18, 2005 6:12 pm |
|
|
Code: | ///////////////////////////////////////////////////////////////////////////
//// 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. ////
///////////////////////////////////////////////////////////////////////////
#ifndef LOADER_END
#define LOADER_END getenv("PROGRAM_MEMORY")-1
#if defined(__PCM__)
#define LOADER_SIZE 0x65F
//#elif defined(__PCH__)
// #define LOADER_SIZE 0x3FF
//#endif
//
#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;
#if getenv("FLASH_ERASE_SIZE")>2
int32 next_addr;
#endif
int8 dataidx, i, count;
int8 data[32];
#if defined(__PCM__)
//printf("test\r\n");
while (!done) // Loop until the entire program is downloaded
{
buffidx = 0; // Read into the buffer until 0x0D ('\r') is received or the buffer is full
do {
buffer[buffidx] = getc();
} while ( (buffer[buffidx++] != 0x0D) && (buffidx <= BUFFER_LEN_LOD) );
putchar (XOFF); // Suspend sender
do_ACKLOD = TRUE;
// Only process data blocks that start with ':'
if (buffer[0] == ':') {
// printf(":\n\r");
count = atoi_b16 (&buffer[1]); // Get the number of bytes from the buffer
// printf("atoi_b16\n\r");
// Get the lower 16 bits of address
l_addr = make16(atoi_b16(&buffer[3]),atoi_b16(&buffer[5]));
// printf("l_addr\n\r");
line_type = atoi_b16 (&buffer[7]);
printf("type =%u\n\r",line_type);
addr = make32(h_addr,l_addr);
#if defined(__PCM__) // PIC16 uses word addresses
addr /= 2;
#endif
// 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
checksum = 0; // Sum the bytes to find the check sum value
for (i=1; i<(buffidx-3); i+=2)
checksum += atoi_b16 (&buffer[i]);
checksum = 0xFF - checksum + 1;
if (checksum != atoi_b16 (&buffer[buffidx-3]))
do_ACKLOD = FALSE;
else {
if (line_type == 0) {
printf("storing data\n\r");
disable_interrupts(GLOBAL);
// 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)
data[dataidx++]=atoi_b16(&buffer[i]);
#if getenv("FLASH_ERASE_SIZE")>2
#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);
next_addr = addr + 1;
#endif
// printf("before write\n\r");
printf("addr = %ld , count = %u \n\r",addr,count);
write_program_memory(addr, data, count);
// enable_interrupts(GLOBAL);
printf("X\n\r");
}
else if (line_type == 4)
h_addr = make16(atoi_b16(&buffer[9]), atoi_b16(&buffer[11]));
}
}
}
if (do_ACKLOD)
putchar (ACKLOD);
putchar(XON);
}
printf("Rebooting\n\r");
putchar (ACKLOD);
putchar(XON);
//#ifndef _bootloader
reset_cpu();
//#endif
}
unsigned int atoi_b16(char *s) { // Convert two hex characters to a int8
unsigned int result = 0;
int i;
for (i=0; i<2; i++,s++) {
if (*s >= 'A')
result = 16*result + (*s) - 'A' + 10;
else
result = 16*result + (*s) - '0';
}
return(result);
}
#ORG default
#ORG LOADER_ADDR, LOADER_ADDR+9
void load_program(void)
{
real_load_program();
}
|
i disable the interupts before the memory write, I never make it to the printf ("x"); code.
Nick[/code] |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 18, 2005 6:52 pm |
|
|
On Monday, I'll test PCM vs. 3.187 with a 16F877A chip and see if
write_program_memory() works. |
|
|
Nick Guest
|
|
Posted: Mon Sep 19, 2005 9:23 am |
|
|
thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 19, 2005 1:28 pm |
|
|
I ran the test program below, and it failed with PCM vs. 3.187.
It only displays:
Start
It worked with PCM vs. 3.234. With that version, it displayed:
Start
Done
Code: |
#include <16F877A.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
int8 count = 0;
#int_timer2
void rtcc_isr(void)
{
count++;
}
//================================
main(void)
{
int8 count;
int16 addr;
int8 data[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int8 value;
setup_timer_2(T2_DIV_BY_1, 127, 1);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
printf("Start\n\r");
disable_interrupts(GLOBAL);
count = 16;
addr = 0;
write_program_memory(addr, data, count);
printf("Done\n\r");
while(1);
} |
|
|
|
|
|
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
|