problems programming e128 flash

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

problems programming e128 flash

4,011 次查看
e_taylor
Contributor III
hello:
 
i wrote some code to program the flash memory @0x4000. when i run the sector erase code ithe program counter goes to 0x1050 causing an illegal breakpoint. i have commented out the write to FSTAT (and subsequent read) and the routine runs out of ram and returns to the main loop. where have i gine wrong?
 
 
thanks in advance.
 
 
ed
 

FlashParameters
  movw #RamOperatingVariables,FlashDataStart     ;area in ram
  movw #FlashOperatingVariables,FlashStart           ;0x4000
  movw #EndFlashVariables,FlashEnd
 

MoveFlashCodeToRam
  ldx #RamFlashRoutine   ;ram area for flash programmer code
  ldy #FlashCode   ;start of flash program
MoveMoreCode ldaa 1,y+
  staa 1,x+
  cpy #FlashCodeEnd   ;move to ram
  blo MoveMoreCode
  jsr RamFlashRoutine
  rts  
  
FlashCode      
  
  ldy FlashDataStart
  ldx FlashStart
  std 0,x    ;write any word to start of flash
  movb #EraseFlashSector,FCMD  ;
; bset FSTAT,#FSTAT_CBEIF  ;clear the cbeif flag to start program
; brclr FSTAT,#FSTAT_CBEIF,*  ;wait for the command buffer to empty
  rts
标签 (1)
0 项奖励
回复
7 回复数

1,513 次查看
blood
Contributor III
Are you sure the rts of the FlashCode got copied into RAM? It would depend on what FlashCodeEnd is set to. If it is the address of the rts then it will not have been copied.
0 项奖励
回复

1,513 次查看
e_taylor
Contributor III
hi blood:
 
thanks for your reply!
 
indeed the rts made it. i've tried jumping to the flash routine and then jump back to a valid label with the same results. one issue was that i didn't have my interrupts stopped and setting the interrupt mask allowed me to program and erase flash.
 
now with my cyclone pro connected i can run the following routines and have success. if i power the target board off and back on the data shows up correctly, however, if if try to change some data with the power cycled board the flash is just erased. i put a branch always to * at the end of the code to aviod the crash.  any suggestions?
 
MoveFlashVariablesToRam
  ldx #FlashOperatingVariables
  ldy #RamOperatingVariables
MFVLoop  ldaa 1,x+
  staa 1,y+
  cpx #EndFlashVariables  
  blo MFVLoop
  rts

FlashParameters
  movw #RamOperatingVariables,FlashDataStart
  movw #FlashOperatingVariables,FlashStart
  movw #EndFlashVariables,FlashEnd
 

MoveFlashCodeToRam
  ldx #RamFlashRoutine   ;ram area for flash programmer code
  ldy #FlashCode   ;start of flash program
MoveMoreCode ldaa 1,y+
  staa 1,x+
  cpy #FlashCodeEnd   ;move to ram
  blo MoveMoreCode
  sei
  jmp RamFlashRoutine
FlashReturn cli
  rts  
  
FlashCode      
  ldy FlashDataStart
  ldx FlashStart
  std 0,x    ;write any word to start of flash
  movb #EraseFlashSector,FCMD  ;
  bset FSTAT,#FSTAT_CBEIF  ;clear the cbeif flag to start program
   brclr FSTAT,#FSTAT_CBEIF,*  ;wait for the command buffer to empty
FlashMore ldd 2,y+    
  std 2,x+    ;move data to valid flash address
  movb #ProgramFlashWord,FCMD  
  bset FSTAT,#FSTAT_CBEIF  ;clear the cbeif flag to start program
  brclr FSTAT,#FSTAT_CBEIF,*  ;wait for the command buffer to empty
  cpx FlashEnd ;
         blo FlashMore
  brclr FSTAT,#FSTAT_CBEIF,*  ;wait for last command to complete 
  bra *
  jmp FlashReturn
FlashCodeEnd    equ *
 
 
is there an app note for the e128 flash that could address my lack of understanding?
 
thanks in advance
 
 
 
0 项奖励
回复

1,513 次查看
blood
Contributor III
Programming of the E128 flash is still the same process as the other varients. It is just things like the flash block size that is different.
I suggest you check what the values are in FSTAT as PVIOL and ACCERR will get set if there was an error. So check them as they can give an indication of what went wrong. These need to be cleared before doing another flash command so it pays to clear them at the start of every flash operation and check them after every command as they show in the flash command flow diagrams in the datasheet.
The datasheet should also have a section "Illegal Flash Operations" which you should read as it may give some ideas on what you have done wrong.
 
Also shouldn't you be testing CCIF and not CBEIF to determine the flash erase has finished and also the programme has finished?
0 项奖励
回复

1,513 次查看
e_taylor
Contributor III
hi blood:
 
thanks very much for your help!
 
i pored over the data sheet and feel i understand it adequately, unless i'm missing something obvoius (wouldn't be the first time).
 
i originally had the code written as follows.
 
brclr FSTAT,#FSTAT_CCIF,*  ;wait for the command buffer to empty
 
CCIF would not set and the code would hang there. i had a look at the FSTAT register in the memory window and no errors were showing up.
 
as you suggest i'll try clearing the flags before i erase or flash and see if it resolves the issue.
 
i'm almost leaning towards a possible hardware issue as if i do a reset through the bdm pod (cyclone pro) i get better (not perfect) results in being able to erase and write flash with the code crashing after. if i power off the target and repower it the erase portion appears to work, however the new data does not get written. resetting with the bdm pod will again work to a point.
 
thanks again for your help. i'll definately post when i get this resolved.
 
 
best reagrds,
 
ed
0 项奖励
回复

1,513 次查看
e_taylor
Contributor III
hi again:
 
using a different e128 board from tech arts this time. same problems so it does not appear to be hardware at this point.
 
i've tried to follow the flow diagram exactly. the code moves to ram correctly but hangs at the second last line waiting for CCIF to set. all it is doing at this point is erase a sector that is loaded with dummy data in code warrior.
 
of note, if i am using the block @ 0x4000 it does not erase and hangs at the CCIF trap. if i use the block @0x8000 it erases but still hangs at the same place. there is probably some text in bold 24 point print glaring at me, but i am stymied on this seemingly simple task
 

MoveFlashCodeToRam
  ldx #RamFlashRoutine   ;ram area for flash programmer code
  ldy #FlashCode   ;start of flash program
MoveMoreCode ldaa 1,y+
  staa 1,x+
  cpy #FlashCodeEnd   ;move to ram
  blo MoveMoreCode
   sei
  jsr RamFlashRoutine
FlashReturn cli
  rts  
  
FlashCode      
  brset FCLKDIV,#FCLKDIV_FDIVLD,CheckFSTAT
  movb #42,FCLKDIV   ;divider clock 190 khz
CheckFSTAT brclr FSTAT,#FSTAT_CBEIF,*
  brclr FSTAT,#FSTAT_ACCERR+FSTAT_PVIOL,WriteDummy
  bset FSTAT,#FSTAT_ACCERR+FSTAT_PVIOL
  ldy FlashDataStart
WriteDummy ldx FlashStart
  std 0,x    ;write any word to start of flash
  movb #$40,FCMD  ;
  bset FSTAT,#FSTAT_CBEIF  ;clear the cbeif flag to start program
   brclr FSTAT,#FSTAT_CCIF,*  ;wait for the command buffer to empty
  rts
thanks in advance!
 
 
regards,
 
ed
0 项奖励
回复

1,513 次查看
kef
Specialist I
Where's the missing code? Where are all those missing equates FSTAT_... ? Are you using codewarrior? If so then you should use not FSTAT_xxx but mFSTAT_xxx
 
FSTAT_CCIF:         equ    6                                         ; Command Complete Interrupt Flag
mFSTAT_CCIF:        equ    %01000000
How are you FSTAT_CCIF defined? CW FSTAT_CCIF defines bit number, mFSTAT_CCIF defines bit mask. It's obvious you should use bitmasks, it's S12, not HC08/HCS08.
 
 
Also this is wrong:
 
  bset FSTAT,#FSTAT_ACCERR+FSTAT_PVIOL
FSTAT flags are clearable by writing 1 to corresponding flag. So in ^^ this line CPU reads FSTAT, possibly with CCIF and CBEIF bits set, and maybe with ACCERR bit set. So CPU reads 0xD0, right? Then CPU bit-ORs 0xD0 with ACCERR and PVIOL bit masks, 0xD0 | 0x30 = 0xF0. CPU will write 0xF0 back to FSTAT register. Write of one to CCIF will be ignored, but write of one to CBEIF will trigger undefined flash command, because you didn't yet write any command to CCIF.
 
use either
 
  BCLR  FSTAT,#~(mFSTAT_ACCERR | mFSTAT_PVIOL)
 
or
 
  MOVB  #mFSTAT_ACCERR | mFSTAT_PVIOL, FSTAT
 
 
Line below is also bad, it attempts to ckear all flags that are set, not just CBEIF
 
  bset FSTAT,#FSTAT_CBEIF  
 
0 项奖励
回复

1,513 次查看
e_taylor
Contributor III
hi kef:
 
thanks for your reply. i'm fairly new at code warrior and indeed i had misunderstood the bit definitions. it states "; bit numbers for usage in BCLR, BSET, BRCLR and BRSET" however when i disassemble the code it proves your use of bit masks is the correct. thanks again! i'm sure i'm on the right track now
 
best regards,
 
ed
 
 
;*** FSTAT - Flash Status Register; 0x00000105 ***
FSTAT:              equ    $00000105                                ;*** FSTAT - Flash Status Register; 0x00000105 ***
; bit numbers for usage in BCLR, BSET, BRCLR and BRSET
FSTAT_BLANK:        equ    2                                         ; Blank Verify Flag
FSTAT_ACCERR:       equ    4                                         ; Access error
FSTAT_PVIOL:        equ    5                                         ; Protection violation
FSTAT_CCIF:         equ    6                                         ; Command Complete Interrupt Flag
FSTAT_CBEIF:        equ    7                                         ; Command Buffers Empty Interrupt Flag
; bit position masks
mFSTAT_BLANK:       equ    %00000100
mFSTAT_ACCERR:      equ    %00010000
mFSTAT_PVIOL:       equ    %00100000
mFSTAT_CCIF:        equ    %01000000
mFSTAT_CBEIF:       equ    %10000000
0 项奖励
回复