Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/25/08 09:12
Modified:
  09/25/08 09:44

Read: times


 
#158587 - IAP for P89C51RC2FA (Erase sector problem)
I've encountered problems, some moth ago, while erasing a sector in IAP mode with a Philips P89C51RC2FA.
When the stack pointer was initialized with a lot of memory reserved, the call to the PGM_MTP ROM entry point never returned.
http://www.8052.com/forum/rea...>

I fixed the problem using fewer variables, so the stack was less filled. The erase process work well and also return.
Mr Jan Waclawek told me to look at the stack usage to find the real problem.
It’s what I’ve done when I had time to do it (months after, I know :) ).

Here is here for information what I’ve found:

The call for the erase code block use 26 bytes in the stack (including return address). The Stack pointer defines where the memory will be used.
Until there no problem; but where it’s interesting, it’s that 3 others bytes are using a fixed location in memory!
It’s addresses 0x50 to 0x52.

So the SP can’t be to a value upper of 0x35 before calling the Erasing process in ISP entry point.

Here is the code I used to view the RAM with a RS235 terminal:
A baud rate detection followed by an erasing of sector 1, and the send of the Stack the serial port.
(asm code generated by compiler since C and asm are mixed)

    80: ?C_STARTUP:     LJMP STARTUP1 
C:0x0000    020007   LJMP     STARTUP1(C:0007)
    22:           JMP   Boot 
    23: ; #pragma endasm 
    24: ; }               ; SOURCE LINE # 7 
C:0x0003    020050   LJMP     BOOT(C:0050)
    25:         RET      
C:0x0006    22       RET      
   139:                 MOV     SP,#?STACK-1 
C:0x0007    758107   MOV      SP(0x81),#0x07
   140:                 LJMP    ?C_START 
C:0x000A    02000D   LJMP     main(C:000D)
     6: main() 
C:0x000D    80F4     SJMP     asmBoot(C:0003)

    25: MOV     SP,#0x35 
    26:  
    27:  
    28: ; Détecte et configure le baudrate 
    29: ; La mesure utilise T2 qui à une horloge de fosc/2 
    30: Detect: 
C:0x0050    758135   MOV      SP(0x81),#0x35
    31:         MOV      TMOD,#0x02 
C:0x0053    758902   MOV      TMOD(0x89),#0x02
    32:         MOV      T2CON,#0x30 
C:0x0056    75C830   MOV      T2CON(0xC8),#0x30
    33:         CLR      A 
C:0x0059    E4       CLR      A
    34:         MOV      TH2,A 
C:0x005A    F5CD     MOV      TH2(0xCD),A
    35:         MOV      TL2,A 
C:0x005C    F5CC     MOV      TL2(0xCC),A
    36:         JNB      RXD,$ 
C:0x005E    30B0FD   JNB      RXD(0xB0.0),C:005E
    37:         JB       RXD,$ 
C:0x0061    20B0FD   JB       RXD(0xB0.0),C:0061
    38:         SETB     TR2 
C:0x0064    D2CA     SETB     TR2(0xC8.2)
    39:         JNB      RXD,$ 
C:0x0066    30B0FD   JNB      RXD(0xB0.0),C:0066
    40:         CLR      TR2 
    41: ; Charge le Timer avec 65536 - tm/16 
C:0x0069    C2CA     CLR      TR2(0xC8.2)
    42:         MOV      A,TL2 
C:0x006B    E5CC     MOV      A,TL2(0xCC)
    43:         SWAP     A 
    44:         ; Arrondi au demi; le carry contient l'incrément si un arrondi supérieur est nécessaire 
C:0x006D    C4       SWAP     A
    45:         RLC      A      ; Mémorise l'arrondi 
C:0x006E    33       RLC      A
    46:         RR       A 
C:0x006F    03       RR       A
    47:         ANL      A,#0x0F 
C:0x0070    540F     ANL      A,#0x0F
    48:         MOV      R0,A 
C:0x0072    F8       MOV      R0,A
    49:         MOV      A,TH2 
C:0x0073    E5CD     MOV      A,TH2(0xCD)
    50:         SWAP     A 
C:0x0075    C4       SWAP     A
    51:         ANL      A,#0xF0 
C:0x0076    54F0     ANL      A,#B(0xF0)
    52:         ORL      A,R0 
C:0x0078    48       ORL      A,R0
    53:         ADDC     A,#0   ; Ajoute le carry 
C:0x0079    3400     ADDC     A,#0x00
    54:         MOV      R0,A 
C:0x007B    F8       MOV      R0,A
    55:         MOV      A,TH2 
C:0x007C    E5CD     MOV      A,TH2(0xCD)
    56:         SWAP     A 
C:0x007E    C4       SWAP     A
    57:         ANL      A,#0x0F 
C:0x007F    540F     ANL      A,#0x0F
    58:         ADDC     A,#0   ; Ajoute le report de l'addition précédente 
C:0x0081    3400     ADDC     A,#0x00
    59:         MOV      R1,A 
    60:         ; compl. à 2 
C:0x0083    F9       MOV      R1,A
    61:         CLR      C 
C:0x0084    C3       CLR      C
    62:         CLR      A 
C:0x0085    E4       CLR      A
    63:         SUBB     A,R0 
C:0x0086    98       SUBB     A,R0
    64:         MOV      TL2,A 
C:0x0087    F5CC     MOV      TL2(0xCC),A
    65:         MOV      RCAP2L,A 
C:0x0089    F5CA     MOV      RCAP2L(0xCA),A
    66:         CLR      A 
C:0x008B    E4       CLR      A
    67:         SUBB     A,R1 
C:0x008C    99       SUBB     A,R1
    68:         MOV      TH2,A 
C:0x008D    F5CD     MOV      TH2(0xCD),A
    69:         MOV      RCAP2H,A 
C:0x008F    F5CB     MOV      RCAP2H(0xCB),A
    70:         SETB     TR2 
C:0x0091    D2CA     SETB     TR2(0xC8.2)
    71:         MOV      SCON,#0x52      
    72:  
    73: Wait_Uchar: 
    74: ; Attend le 1er caractère 
C:0x0093    759852   MOV      SCON(0x98),#0x52
    75:         JNB      RI,$ 
C:0x0096    3098FD   JNB      RI(0x98.0),WAIT_UCHAR(C:0096)
    76:         CLR      RI 
C:0x0099    C298     CLR      RI(0x98.0)
    77:         MOV      A,SBUF 
    78:         ; Dans la valeur reçue, les 2 LSB n'on pas été pris car on les a déjà utilisé pour la detection du baudrate 
C:0x009B    E599     MOV      A,SBUF(0x99)
    79:         CLR      C 
C:0x009D    C3       CLR      C
    80:         RLC      A 
C:0x009E    33       RLC      A
    81:         SETB     C 
C:0x009F    D3       SETB     C
    82:         RLC      A 
    83: ; Renvoie le caractère 
C:0x00A0    33       RLC      A
    84:         JNB      TI,$ 
C:0x00A1    3099FD   JNB      TI(0x98.1),C:00A1
    85:         CLR      TI 
C:0x00A4    C299     CLR      TI(0x98.1)
    86:         MOV      SBUF,A 
    87:  
C:0x00A6    F599     MOV      SBUF(0x99),A
    88:         MOV      R0,#2  ; Nombre de relecture avant de recommancer une détection 
    89: Detect_tst: 
    90: ; Check to see if uppercase "U" 
C:0x00A8    7802     MOV      R0,#0x02
    91:         CJNE     A,#'U',Not_U   ; Check to see if uppercase "U" 
C:0x00AA    B45502   CJNE     A,#0x55,NOT_U(C:00AF)
    92:         JMP      Intel_Hex 
    93: Not_U: 
C:0x00AD    8019     SJMP     INTEL_HEX(C:00C8)
    94:         DJNZ     R0,Not_U1 
    95: ; Dans ce cas on recommence la détection 
C:0x00AF    D807     DJNZ     R0,NOT_U1(C:00B8)
    96:         MOV      SCON,#0 
C:0x00B1    759800   MOV      SCON(0x98),#0x00
    97:         CLR      TR2 
C:0x00B4    C2CA     CLR      TR2(0xC8.2)
    98:         JMP      Detect     
    99: Not_U1: 
   100: ; On teste encore un caractère car avec des débits élevés, on manque partiellement le premier 
C:0x00B6    809B     SJMP     DETECT(C:0053)
   101:         JNB      RI,$ 
C:0x00B8    3098FD   JNB      RI(0x98.0),NOT_U1(C:00B8)
   102:         CLR      RI 
C:0x00BB    C298     CLR      RI(0x98.0)
   103:         MOV      A,SBUF 
   104: ; Renvoie le caractère 
C:0x00BD    E599     MOV      A,SBUF(0x99)
   105:         JNB      TI,$ 
C:0x00BF    3099FD   JNB      TI(0x98.1),C:00BF
   106:         CLR      TI 
C:0x00C2    C299     CLR      TI(0x98.1)
   107:         MOV      SBUF,A 
C:0x00C4    F599     MOV      SBUF(0x99),A
   108:         JMP      Detect_tst 
   109:  
   110:  
   111: ;***** Intel Hex File Load routine ***** 
   112: ;This routine loads an Intel Hex formatted file into  
   113: ;the buffer memory. The hex file is received as a series 
   114: ;of ASCII characters on the serial input line of the 
   115: ;serial port. A record type of 00H is considered to be 
   116: ;a data field. Any other type of record is considered 
   117: ;to be an End-of-File marker. This routine also calculates 
   118: ;the checksum on the field as it is received and compares 
   119: ;this calculated checksum with the checksum field received 
   120: ;in the record. 
   121: Intel_Hex: 
   122:  
C:0x00C6    80E2     SJMP     DETECT_TST(C:00AA)
   123: MOV A,#'s'  
C:0x00C8    7473     MOV      A,#0x73
   124: call CO 
   125:  
   126: ; It will be NECESSARY for the end-user’s code to set the ENBOOT bit prior to 
   127: ;  calling the common entry point for IAP operations 
C:0x00CA    3104     ACALL    CO(C:0104)
   128:         ORL     AUXR1,#ENBOOT        ; enable boot 
   129:  
   130: ; Fill Stack 
C:0x00CC    43A220   ORL      AUXR1(0xA2),#0x20
   131: MOV A,#0x5A 
C:0x00CF    745A     MOV      A,#0x5A
   132: MOV R0,SP 
C:0x00D1    A881     MOV      R0,SP(0x81)
   133: INC R0 
   134: Fill: 
C:0x00D3    08       INC      R0
   135: MOV @R0,A 
C:0x00D4    F6       MOV      @R0,A
   136: INC R0 
C:0x00D5    08       INC      R0
   137: CJNE R0,#0,Fill 
   138:  
   139: ; ERASE BLOCK 
C:0x00D6    B800FB   CJNE     R0,#0x00,FILL(C:00D4)
   140: MOV R0,#11      ; R0 = osc freq (integer) 
C:0x00D9    780B     MOV      R0,#0x0B
   141: MOV R1,#01h 
C:0x00DB    7901     MOV      R1,#0x01
   142: MOV DPH,#20h    ;block code, block 1 , 8k~16k 
C:0x00DD    758320   MOV      DPH(0x83),#0x20
   143: MOV DPL,#0 
C:0x00E0    758200   MOV      DPL(0x82),#0x00
   144: LCALL PGM_MTP   ; 0FFF0h 
   145: ; It never returne here!? 
   146:  
C:0x00E3    12FFF0   LCALL    C:FFF0
   147: MOV A,#'e'  
C:0x00E6    7465     MOV      A,#0x65
   148:         JNB      TI,$ 
C:0x00E8    3099FD   JNB      TI(0x98.1),C:00E8
   149:         CLR      TI 
C:0x00EB    C299     CLR      TI(0x98.1)
   150:         MOV      SBUF,A 
   151:  
   152: ;Display Stack 
C:0x00ED    F599     MOV      SBUF(0x99),A
   153: MOV R0,SP 
C:0x00EF    A881     MOV      R0,SP(0x81)
   154: INC R0 
   155: Disp: 
C:0x00F1    08       INC      R0
   156: MOV A,#' '  
C:0x00F2    7420     MOV      A,#0x20
   157:         JNB      TI,$ 
C:0x00F4    3099FD   JNB      TI(0x98.1),C:00F4
   158:         CLR      TI 
C:0x00F7    C299     CLR      TI(0x98.1)
   159:         MOV      SBUF,A 
C:0x00F9    F599     MOV      SBUF(0x99),A
   160: MOV A,@R0 
C:0x00FB    E6       MOV      A,@R0
   161: JMP OUTBYT 
   162: Disp2: 
C:0x00FC    8016     SJMP     OUTBYT(C:0114)
   163: INC R0 
C:0x00FE    08       INC      R0
   164: CJNE R0,#0,Disp 
   165:  
   166:  
C:0x00FF    B800F0   CJNE     R0,#0x00,DISP(C:00F2)
   167: jmp $  
   168:  
   169:  
   170: ;***** console output routine ***** 
   171: ;Outputs character in the ACC to  
   172: ;the serial output line. 
   173: CO: 
C:0x0102    80FE     SJMP     C:0102
   174:         JNB      TI,$ 
C:0x0104    3099FD   JNB      TI(0x98.1),CO(C:0104)
   175:         CLR      TI 
C:0x0107    C299     CLR      TI(0x98.1)
   176:         MOV      SBUF,A 
C:0x0109    F599     MOV      SBUF(0x99),A
   177:         RET 
   178:  
   179: ;***** console input routine ***** 
   180: ;Waits until character has been received 
   181: ;and then returns char in ACC. 
   182: CI: 
C:0x010B    22       RET      
   183:         JNB      RI,$ 
C:0x010C    3098FD   JNB      RI(0x98.0),CI(C:010C)
   184:         CLR      RI 
C:0x010F    C298     CLR      RI(0x98.0)
   185:         MOV      A,SBUF 
C:0x0111    E599     MOV      A,SBUF(0x99)
   186:         RET 
   187:  
   188:  
   189:  
   190: OUTBYT: 
C:0x0113    22       RET      
   191:         MOV     R4,A  ;"push acc" 
C:0x0114    FC       MOV      R4,A
   192:         SWAP    A 
C:0x0115    C4       SWAP     A
   193:         JMP     HEX2A1 
   194: OUTBYT1: 
   195: ;       CALL   CO 
C:0x0116    8013     SJMP     HEX2A1(C:012B)
   196:         JNB      TI,$ 
C:0x0118    3099FD   JNB      TI(0x98.1),OUTBYT1(C:0118)
   197:         CLR      TI 
C:0x011B    C299     CLR      TI(0x98.1)
   198:         MOV      SBUF,A 
C:0x011D    F599     MOV      SBUF(0x99),A
   199:         MOV     A,R4  ;"pop acc" 
C:0x011F    EC       MOV      A,R4
   200:         JMP     HEX2A2 
   201: OUTBYT2: 
   202: ;       CALL   CO 
C:0x0120    8018     SJMP     HEX2A2(C:013A)
   203:         JNB      TI,$ 
C:0x0122    3099FD   JNB      TI(0x98.1),OUTBYT2(C:0122)
   204:         CLR      TI 
C:0x0125    C299     CLR      TI(0x98.1)
   205:         MOV      SBUF,A 
C:0x0127    F599     MOV      SBUF(0x99),A
   206:         JMP Disp2 
   207:  
   208:  
   209:  
   210: ;***** HEX to ASCII routine ***** 
   211: ;This routine receives a single hex digit 
   212: ;(a four bit nibble) in the ACC and returns 
   213: ;the equivilent ASCII char in the ACC. 
   214: HEX2A1: 
C:0x0129    80D3     SJMP     DISP2(C:00FE)
   215:         ANL     A,#0FH 
C:0x012B    540F     ANL      A,#0x0F
   216:         CLR     C        ;carry affects the testing 
C:0x012D    C3       CLR      C
   217:         SUBB    A,#0AH      ;test for range of 0-9, A-F 
C:0x012E    940A     SUBB     A,#0x0A
   218:         JNC     HAHIGH1      ;no carry then A-F range 
C:0x0130    5004     JNC      HAHIGH1(C:0136)
   219:         ADD     A,#3AH       ;add offset for 0-9 range 
C:0x0132    243A     ADD      A,#0x3A
   220:         JMP OUTBYT1 
   221: HAHIGH1: 
C:0x0134    80E2     SJMP     OUTBYT1(C:0118)
   222:         ADD     A,#41H       ;add in offset for A-F range 
C:0x0136    2441     ADD      A,#0x41
   223:         JMP OUTBYT1 
   224:  
   225:  
   226: HEX2A2: 
C:0x0138    80DE     SJMP     OUTBYT1(C:0118)
   227:         ANL     A,#0FH 
C:0x013A    540F     ANL      A,#0x0F
   228:         CLR     C        ;carry affects the testing 
C:0x013C    C3       CLR      C
   229:         SUBB    A,#0AH      ;test for range of 0-9, A-F 
C:0x013D    940A     SUBB     A,#0x0A
   230:         JNC     HAHIGH2      ;no carry then A-F range 
C:0x013F    5004     JNC      HAHIGH2(C:0145)
   231:         ADD     A,#3AH       ;add offset for 0-9 range 
C:0x0141    243A     ADD      A,#0x3A
   232:         JMP OUTBYT2 
   233: HAHIGH2: 
C:0x0143    80DD     SJMP     OUTBYT2(C:0122)
   234:         ADD     A,#41H       ;add in offset for A-F range 
C:0x0145    2441     ADD      A,#0x41
   235:         JMP OUTBYT2 
C:0x0147    80D9     SJMP     OUTBYT2(C:0122)


List of 4 messages in thread
TopicAuthorDate
IAP for P89C51RC2FA (Erase sector problem)            01/01/70 00:00      
   a common mistake            01/01/70 00:00      
      not quite            01/01/70 00:00      
         send Bill/Bauke an e-mail and ask            01/01/70 00:00      

Back to Subject List