📄 f_intel_arm.s
字号:
bl check_status ; check Flash status and return in R0
bne flash_exit ; failed on this one
cmp R9,#0 ; want verify?
beq done_write ; no, just quit
cmp R0,#0 ; write went ok?
bne done_write ; no, just quit
mov R7,#0xFF ; set to read mode
EXPAND R7
STORE R7,[R1] ; write to Flash
mov R2,R9 ; reset count
sub R4,R4,R2 ; back up to start of block to verify
sub R5,R5,R2 ; back up to start of buffer to verify
bl block_lock ; lock block
b FLASH_validate ; go on to validate code
done_write
b flash_exit ; Stop routine on breakpoint
;* -----------------------------------------------------------------------
; FLASH_validate - validate write to a Flash block
;
; Notes:
; - this compares a buffer and a flash block. The caller uses this
; after a write to verify the write worked.
; - the host knows about block sizes and all, and passes in the needed
; info.
;
; Input/Output:
; - In: R1=Base of Flash block to verify
; R0=Page of Flash (no meaning for ARM)
; R2=Count of bytes to verify
; R4=Offset in block to verify from
; R5=Address of buffer to verify against
; R8=Page of buffer (no meaning for ARM)
; - Out:R0=status code (0=OK, else error)
; - Scratch: R6,R7
; ----------------------------------------------------------------------- */
FLASH_validate
mov R6,#0
mov R7,#0
validate_loop
LOAD R7,[R5],#WIDTH ; load value from buffer
LOAD R6,[R4],#WIDTH ; load value from Flash
cmp R6,R7 ; same?
bne bad_validate ; no, failed
subs R2,R2,#WIDTH ; decrement count, more?
bgt validate_loop ; yes, continue
bl check_status ; check Flash status and return in R0
b flash_exit ; Stop routine on breakpoint
bad_validate
mov R0,#1 ; compare
b flash_exit ; Stop routine on breakpoint
;* -----------------------------------------------------------------------
; FLASH_break - end of function entry for all Flash routines
;
; Notes:
; - this routine is the Stop routine for the flash code. It runs over
; what should be a break (set by host). If the host messes up, it
; will loop forever allowing the host to halt it.
;
; Input/Output:
; - In: R0=status code to return (0=OK, else error)
; R1=base of Flash block operated on
; ----------------------------------------------------------------------- */
Local_init ; we have no local init
flash_exit
mov R7,#0xFF ; set to read mode
EXPAND R7
STORE R7,[R1] ; write to Flash
FLASH_break
nop ; place to put breakpoint from host
forever
b forever ; in case host screws up
;************************************************************************/
;* STATIC FUNCTIONS */
;************************************************************************/
;* -----------------------------------------------------------------------
; erase_block - erase a block of the flash and check if OK
;
; Notes:
; - this handles erase of a Flash block and returns status in R0
; as well as the Z flag
;
; Input/Output:
; - In: R1=Base of Flash
; - Out:R0=Status (0=OK, else failed)
; - Scratch: R0,R6
; ----------------------------------------------------------------------- */
erase_block
mov R7,R14 ; save link for calls below
bl block_unlock ; unlock block
mov R6,#0x20 ; erase setup msg
EXPAND R6
STORE R6,[R1] ; ask to Flash erase
mov R6,#0xD0 ; erase confirmation msg
EXPAND R6
STORE R6,[R1] ; confirm we want to erase
mov R6,R7 ; Need to use R7 which holds R14 call
; so move to R6
bl wait_for_ready ; wait for erase to finish
mov R7,R6 ; Need to reuse R6 so store call address
; in R7
bl block_lock ; lock block
mov R6,R7 ; Need to use R7 which holds R14 call
; so move to R6
bl check_status ; check Flash status and return in R0
mov R15,R6 ; Return with code in R0 and Z bit
;* -----------------------------------------------------------------------
; check_status - check to see if operation completed OK.
;
; Notes:
; - this reads the error status of the Flash and returns in R0.
; - bit 7 = Ready (when high)
; - bit 6 = Erase Suspend (high when in effect)
; - bit 5 = Erase Successful (low when successful)
; - bit 4 = Program Error (low when successful)
; - bit 3 = VPEN Error (low when VPEN OK)
; - bit 2 = Program Suspend (high when in effect)
; - bit 1 = Block Lock Error (low when block is not not locked)
; - bit 0 = BEFP Status (high when in effect)
;
; Input/Output:
; - In: R1=Base of Flash
; - Out:R0=Status (0=OK, else failed)
; - Scratch: R7
; ----------------------------------------------------------------------- */
check_status
mov R0,#0x70 ; read status request
EXPAND R0
STORE R0,[R1] ; write to Flash base
LOAD R0,[R1] ; read back results
ldr R7,=0x10000008
str R0,[R7] ; display LEDs
mov R7,#0x3A
EXPAND R7
ands R0,R0,R7 ; mask for errors
mov R15,R14 ; Return with code in R0
;* -----------------------------------------------------------------------
; wait_for_ready - wait for Flash to complete an operation.
;
; Notes:
; - this reads the status of the Flash until done.
;
; Input/Output:
; - In: R1=Base of Flash
; - Scratch: R0,R7
; ----------------------------------------------------------------------- */
wait_for_ready
mov R0,#0x70 ; read status request
EXPAND R0
STORE R0,[R1] ; write to Flash base
LOAD R0,[R1] ; read back results
mov R7,#0x80
EXPAND R7
cmp R0,R7 ; read back as 0x80 means OK
bne wait_for_ready ; no, wait some more
mov R15,R14 ; Return
;* -----------------------------------------------------------------------
; block_unlock - Unlock block
;
; Notes:
; - You cannot erase or write to a block until it is unlocked. The
; block is locked everytime the flash is reset or repowered
;
; Input/Output:
; - In: R1=Base of Flash
; - Scratch: R6
; ----------------------------------------------------------------------- */
block_unlock
mov R6,#0x60 ; Unlock/lock block
EXPAND R6
STORE R6,[R1]
mov R6,#0xD0 ; Confirm Unlock block
EXPAND R6
STORE R6,[R1]
mov R6,#0xFF ; Exit Block unlock/lock
EXPAND R6
STORE R6,[R1]
mov R15,R14 ; Return
;* -----------------------------------------------------------------------
; block_unlock - Unlock block
;
; Notes:
; - You cannot erase or write to a block until it is unlocked. The
; block is locked everytime the flash is reset or repowered
;
; Input/Output:
; - In: R1=Base of Flash
; - Scratch: R6
; ----------------------------------------------------------------------- */
block_lock
mov R6,#0x60 ; Unlock/lock block
EXPAND R6
STORE R6,[R1]
mov R6,#0x1 ; Confirm lock block
EXPAND R6
STORE R6,[R1]
mov R6,#0xFF ; Exit Block unlock/lock
EXPAND R6
STORE R6,[R1]
mov R15,R14 ; Return
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -