AnsweredAssumed Answered

How do you write to flash on a K64f? What am I doing wrong?

Question asked by Mark Manning on Nov 2, 2019
Latest reply on Nov 13, 2019 by Mark Butcher

I have read the documentation over and over and over and over and over.  I have looked at other peoples code to write to flash, none of which is suitable for my purposes (all C code and there is zero C code in my project) so I am implementing it myself in assembler.  I do not know what I am doing wrong but for every attempt to write or erase flash I get ACCERR.

 

I will never use processor expert because this is one size fits all code and is HORRENDOUS.  It is also an impediment to understanding.  i do not ever click a "do this for me" easy button.

 

The ONLY initialization I do for the processor is to disable interrupts and the watchdog timer.  i have not attempted to modify clocks in any way.  I would be slightly annoyed if flash write access can only be done after some clock initialization because there is absolutely nothing what so ever that I can find in the documentation that suggests this is the case and as stated before, ive been over that documentation multiple times.

 

Both of the following functions result in ACCERR.  The call to ftfe_wait (not posted) initializes r7 to x040020000.  I have also tried to write each byte of the FCCOB registers individually with no change in the end result.  flash not modified and ACCERR.

 

ftfe_erase:
  str lr, [sp, #-4]!

  bl ftfe_wait              @ wait for previous command complete

  movs r0, #0x09            @ erase sector from address 0x000000
  str r0, [r7, FCCOB]
  movs r0, #CCIF            @ run the command
  strb r0, [r7, #FTFE_FSTAT]

  ldr pc, [sp], #4

 

ftfe_prog:
  str lr, [sp, #-4]!
  bl ftfe_wait              @ wait for previous command complete

  mov r0, r5                @ r5 = destination address

  lsl r0, r0, #8            @ shift addres up 8 bits to make room for...
  adds r0, r0, #7           @ program phrase
  str r0, [r7, FCCOB]

  ldr r0, [r9], #4
  str r0, [r7, FCCOB + 4]
  ldr r0, [r9], #4
  str r0, [r7, FCCOB + 8]

  movs r0, #CCIF            @ run the command
  strb r0, [r7, #FTFE_FSTAT]

  ldr pc, [sp], #4

 

P.S. these forums seem to be constructed in such a way as to make it as CLOSE to impossible for anyone to get any kind of help  I have NEVER seen any other forums that are this FREEEKING obfuscated to use.  WHERE IS THE FORUM FOR THE K64F !!!!!!!!!!!!!!!!!!

 

Outcomes