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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/20/05 23:05
Read: times


 
#95400 - straighforward?
Responding to: ???'s previous message
Erik, you broke the "peace" first! :-)

In fact, I don't believe there is any self-programming(IAP)-capable '51 clone which is NOT "straighforwardly" programmed.
It goes almost always the following way:
- set up address to be written to (sometimes writing to dedicated registers)
- set up data to be written (maybe writing to dedicated register)
- start programming writing to some "flash command" register
- check if programming finished (reading from a status register), or simply wait for a given time, or the processor stalls for the time of programming.
Most of the time it is necessary to run the program in a different part of memory than the programmed memory.

Particularly, for T89C51RD2 the data memory can be programmed by the following code (this code of course has to reside in the bootloader area; you cannot run out of user area)(this is no secret, hints can be found in the datasheet):
;Disclaimer: Use at your own risk. May be completely wrong.
FCON         EQU   0D1h   ;flash control SFR
;FCON = FPL3 FPL2 FPL1 FPL0 FPS FMOD1 FMOD0 FBUSY
FCON_PROG1   EQU   050h
FCON_PROG2   EQU   0A0h
FCON_MAP_FL  EQU   08h    ;maps flash for MOVX write
FCON_MOD_FL  EQU   00h    ;which area accessed:user flash/XAF/HSB
FCON_MOD_XAF EQU   02h
FCON_MOD_HSB EQU   04h

;program 1 byte in A into [dptr]
Flash_ProgByte:
   push  ie
   clr   ea
   mov   FCON,#FCON_MAP_FL|FCON_MOD_FL
   movx  dptr,@a
   mov   FCON,#FCON_PROG1|FCON_MOD_FL
   mov   FCON,#FCON_PROG2|FCON_MOD_FL
Flash_ProgWait:
   mov   a,FCON
   jb    acc.0,Flash_ProgWait
   mov   FCON,#0
   pop   ie
   ret
A remark: for the T89/AT89, there is no need to erase flash before programming.

I also went through what I had here and determined the resources needed.
;this is the T89C51RD2 bootloader 
;returns bootloader version (IAP call 08) - 24h
;uses the current register set (and does not modify rb0, rb1)
;may disable interrupts for a while (but does not modify them)
;interrupts should be OK, as during programming it disables them
;
;resources usage (stack excl. 2 bytes for the IAP call itself):
;
;IAP call (r1)             stack    registers
;00 (read ID)              0        dptr (contains the accessed XAF address)
;02 (program data byte)    2        r2, acc (returns ALWAYS zero!)
;03 (read device data)     0        (acc - contains the read byte)
;04 (erase SBV+BSB)        2        r4, acc, dptr
;05 (program SSB)          2        r4, acc, dptr
;06 (program SBV+BSB)      2        r4, acc, dptr
;07 (misc read)            0        dptr, (acc)
;08 (bootloader version)   0        (acc)
;09 (program data page)    2        r2, r4, r6, dptr, AUXR1, acc (returns ALWAYS zero!)
;
-----------------------------
;this is the AT89C51ED2 bootloader 
;returns bootloader version (IAP call 0F) - 00h  (and both 0E calls return 00h)
;uses the current register set (and does not modify rb0, rb1)
;contrary to datasheet, most functions (except 09) don't explicitly use DPTR0, but the current DPTR
;contrary to T89... it does NOT disable interrupts...
;
;resources usage (stack excl. 2 bytes for the IAP call itself):
;
;IAP call (r1)             stack    registers
;00 (read ID)              0        dptr (contains the accessed XAF address) (acc)
;01 (erase block)          0        r0, r1, dptr, acc
;02 (program data byte)    0        acc
;03 (read device data)     0        (acc - contains the read byte) *undocumented*
;04 (erase SBV+BSB)        0        acc, dptr *undocumented*
;05 (program SSB)          0        acc, dptr
;06 (program SBV+BSB)      0        acc
;07 (misc read)            0        dptr, (acc) *undocumented - dptr=0003h reads XAF address 06h...*)
;09 (program data page)    0        r0, dptr, AUXR1, acc (returns ALWAYS zero!)
;0A (program X2,BLJB)      2        r0, r1, r2, dptr, (acc)
;0B (read HSB)             0        dptr, (acc)
;0E (read boot ID)         0        (acc)
;0F (read boot version)    0        (acc)


The usual disclaimer: Use at your own risk. I may be completely wrong and you can have a different version of the bootloader.

Jan Waclawek


List of 42 messages in thread
TopicAuthorDate
IAP Problem in AT89C51RD2            01/01/70 00:00      
   IAP PROBLEM            01/01/70 00:00      
      misinterpretations            01/01/70 00:00      
   IAP source            01/01/70 00:00      
      IAP source?            01/01/70 00:00      
         ..xC51x.. IAP API            01/01/70 00:00      
            oh those...            01/01/70 00:00      
               IAP            01/01/70 00:00      
                  sorry...            01/01/70 00:00      
                  IAP            01/01/70 00:00      
               Yes, but..            01/01/70 00:00      
                  bootloader            01/01/70 00:00      
                     Depressing, isn't it?            01/01/70 00:00      
                        complaining to Atmel?            01/01/70 00:00      
                           please, WHAT is the problem            01/01/70 00:00      
                              Not at all...            01/01/70 00:00      
                                 comments            01/01/70 00:00      
                                    More comments            01/01/70 00:00      
                                       comments on more comments            01/01/70 00:00      
                                          other way 'round (a pinch of irony)            01/01/70 00:00      
                                             keep it going            01/01/70 00:00      
                                                What's the point?            01/01/70 00:00      
                                          COMCOMC            01/01/70 00:00      
                                             for those of you who need this            01/01/70 00:00      
                                                straighforward?            01/01/70 00:00      
   Interrupts            01/01/70 00:00      
      The coments are in spanish if you are in            01/01/70 00:00      
         Translation?            01/01/70 00:00      
            The code            01/01/70 00:00      
   IAP on Atmel            01/01/70 00:00      
      only 16 bytes?            01/01/70 00:00      
         don't know            01/01/70 00:00      
            that might be the explanation            01/01/70 00:00      
      Are you overwriting your own code? Where            01/01/70 00:00      
         code example            01/01/70 00:00      
            IAP Problem            01/01/70 00:00      
            My Code            01/01/70 00:00      
               This looks good...            01/01/70 00:00      
   Thank U for the Great support            01/01/70 00:00      
      I see many and no U            01/01/70 00:00      
      And what was the problem???            01/01/70 00:00      
         Not Yet            01/01/70 00:00      

Back to Subject List