AnsweredAssumed Answered

S12XEP Pflash write speed

Question asked by Oliver Hufnagl on Oct 5, 2017
Latest reply on Oct 9, 2017 by lama

Hello,
i am using a 9S12XEP100 Controller (8Mhz Crystal) PLL96Mhz Bus 48Mhz
I now wrote a subroutine for P Flash programming, that transfers 1KB Blocks from memory to the P FLASH 70_0000'G to 77_FFFF'G  (768K accessible, except PBLOCK 0)
FCLKDIV is set to 0x07 according to the reference manual (8Mhz Crystal --> 1Mhz Flash clk)
Measuring the performance, it takes 40ms to transfer a block of 1KB to the P FLASH (20ms for erasing a sector + 20ms to write 1024 Bytes)
With a MC9S12XDP512 Controller at 24Mhz and Flash Clk about 200Khz, the same operation takes just 5-8msek.
If I reduce  FCLKDIV at the XEP to 0x00, the sector erase + write of 1024 Bytes takes about 8ms.
What is the Problem, is there an other clockdevider in use?

I can not imagine that the Flash performace of the XEP is 8 times slower compared to XDP without excessiv Flash overclocking.

Codeblock, Flash Sektor Write
Two allocated RAM Registers
FLASH_GPAGE DS.B 1
FLASH_GADR   DS.W 1
Subroutine:
FLASH_WRITE:                 ;Y= passes the Sector Number , X = Source Data, D= Length to write
;Sectors 0-2FF (768KB) --> Global translation
;0000 = 70_0000
;0001 = 70_0400
;0002 = 70_0800
;0003 = 70_0C00
;0004 = 70_1000
;02FF = 77_FC00  last Block 768K 
      sei                                ;no Ints
      pshd
      pshx
      pshy
      pshd
      TFR   Y,D                        ;Y --> D global calculation
      lsld                                  ;x 4
      lsld         
      adda  #$70                      ;AKKA--> Global Page
      staa  FLASH_GPAGE    ;store for later use
      TFR   B,A                       ; --> D has global ADR
      clrb       
      std    FLASH_GADR     ;Store for later use
   
;Erase sector
FLASH_WRITE_WAIT1:   
      ldaa   FSTAT                           ;Wait CCIF
      bita   #$80
      beq    FLASH_WRITE_WAIT1
      anda   #$30                            ;Clear Errors
      staa   FSTAT
;Command Flash Sector erase   
      clr    FCCOBIX                         ;COBIX =0
      movb   #$0A,FCCOBHI           ;Command erase sector
      movb   FLASH_GPAGE,FCCOBLO        ;Global page
      inc    FCCOBIX                                     ;next IDX
      movw   FLASH_GADR,FCCOB           ;Global ADR
      movb   #$80,FSTAT                               ;Execute
;Write data, 8 Byte aligned 
      puld                                         ;Number of Bytes to write
      ldy    FLASH_GADR                 ;Y --> Global ADR     
FLASH_WRITE_LOOP_SEKTOR:
      psha
FLASH_WRITE_WAIT2:   
      ldaa   FSTAT                  ;Wait  CCIF 
      bita   #$80
      beq    FLASH_WRITE_WAIT2
      anda   #$30                         ;Clear Errors
      staa   FSTAT
      pula
;Flash Command Write, 8 Byte aligned Adress   
      clr    FCCOBIX                ;INDEX =00
      movb   #$06,FCCOBHI           ;Write Phrase
      movw   FLASH_GPAGE,FCCOBLO        ;Global Page
      inc    FCCOBIX                ;next IDX
      sty    FCCOB                   ;Global ADR 
      inc    FCCOBIX                ;next IDX
      movw   2,x+,FCCOB        ;word 1 to write
      inc    FCCOBIX                ;next IDX
      movw   2,x+,FCCOB        ;word 2 to write
      inc    FCCOBIX                ;next IDX
      movw   2,x+,FCCOB        ;word 3 to write
      inc    FCCOBIX                ;next IDX
      movw   2,x+,FCCOB        ;word 4 to write
      movb   #$80,FSTAT         ;execute
      addy   #8                          ;Global ADR +8
      bcc    FLASH_WRITE_NOPAGEchange  ;check for next global page
      inc    FLASH_GPAGE                ;Next page if data len >1024Bytes
FLASH_WRITE_NOPAGEchange:  
      subd   #8                     ;write Counter -8 Bytes
      bcs    FLASH_WRITE_END_SEKTOR     ;All Bytes written + some unexpected--> D was not 8byte aligned 
      bne    FLASH_WRITE_LOOP_SEKTOR   ;all Bytes written
FLASH_WRITE_END_SEKTOR:  ;return
      cli
      puly
      pulx
      puld
      rtc

Outcomes