⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flash_m68328vz_ads.s

📁 一个linux下的usb接口源代码
💻 S
字号:
;
; Code to copy data from memory into Fujitsu MBM29LV160T flash.
; It assumes 1 flash chip in word mode.
; This code assumes a top-boot device.  It also assumes
; that the starting flash address is at the beginning
; of a sector.
;

FLASH_BASE		.equ		$01000000

CPU_SPEED		.equ		16				; 16 MHz
DLOOP_CYCLES	.equ		26				; SUBI.L #,Dn -> 16; BNE.S -> 10
DELAY_TIME		.equ		20				; 20ms max delay after sector write
DELAY_COUNT		.equ		(CPU_SPEED*1000000*DELAY_TIME/1000)/DLOOP_CYCLES

	.section .flashinit
	.extern ___FBUF_START
	.extern ___FBUF_END
	.extern ___FLASH_START
	.global	copy_to_flash
copy_to_flash:

	;
	; Set up registers:
	;	a0 - flash image source start addr (in RAM)
	;	a1 - flash image source end addr (in RAM)
	; 	a2 - flash image dest addr (in FLASH)
	;

	move.l		#___FBUF_START,a0		; source addr of flash image
	move.l		#___FBUF_END,a1			; end addr of source flash image
	move.l		#___FLASH_START,a2		; dest addr of flash image
	
	move.l		#$555*2,d1				; load command offset 1 to d1
	move.l		#$2aa*2,d2				; load command offset 2 to d2


	;
	; Erase the next sector.  Each sector must be erased before it
	; can be programmed.
	;
	
erase_loop:
	cmp.l		a0,a1					; if done copying, verify
	ble			do_compare
	
	move.l		a2,d0
	and.l		#$ffe00000,d0			; calc. base addr of current chip
	move.l		d0,a3
	
	move.w		#$aa,(d1.l,a3)			; unlock step 1
	move.w		#$55,(d2.l,a3)			; unlock step 2
	move.w		#$80,(d1.l,a3)			; sector erase setup
	move.w		#$aa,(d1.l,a3)			; unlock step 1
	move.w		#$55,(d2.l,a3)			; unlock step 2
	move.w		#$30,(a2)				; erase current sector
erase_verify_loop:
	move.w		(a2),d0					; check sector data
	cmp.w		#$ffff,d0				; erased?
	bne.s		erase_verify_loop		; if not, keep checking


do_program:
	; Get the sector size, which depends on the sector offset.
	; This code assumes a top-boot device.  It also assumes
	; that the starting flash address is at the beginning
	; of a sector.

	move.l		a2,d0
	sub.l		a3,d0					; get offset of sector
	cmp.l		#$001f0000,d0			; is it sa31 or higher?
	bge.s		check_sa31				; if so, do more tests
	move.l		#$00010000,d0			; otherwise, size is 64K
	bra			program_loop
	
check_sa31:
	cmp.l		#$001f8000,d0			; is it sa32 or higher?
	bge.s		check_sa32				; if so, do more test
	move.l		#$00008000,d0			; otherwise, size is 32K
	bra			program_loop
	
check_sa32:
	cmp.l		#$001fc000,d0			; is it sa34?
	bge.s		size_sa34				; if so, get sa34 size
	move.l		#$00002000,d0			; otherwise, size is 8K
	bra			program_loop

size_sa34:
	move.l		#$00004000,d0			; sa34 size is 16K

program_loop:
	
	move.w		#$aa,(d1.l,a3)			; unlock step 1
	move.w		#$55,(d2.l,a3)			; unlock step 2
	move.w		#$a0,(d1.l,a3)			; program command
	
	move.w		(a0),d3
	move.w		d3,(a2)					; write data to flash
program_verify_loop:
	cmp.w		(a2),d3					; data written?
	bne.s		program_verify_loop		; if not, wait

	add.l		#2,a0					; next word
	add.l		#2,a2					; next word

	cmp.l		a0,a1					; done copying?
	ble.s		do_compare				; if so, verify

	sub.l		#2,d0					; next word
	beq			erase_loop				; if end of sector, erase next
	bra.s		program_loop			; otherwise, copy next word
	

	; Verify that the flash contents were written correctly.
do_compare:
	move.l		#___FBUF_START,a0		; source addr of flash image
	move.l		#___FBUF_END,a1			; end addr of source flash image
	move.l		#___FLASH_START,a2		; dest addr of flash image

compare_loop:
	cmp.w		(a0)+,(a2)+
	bne			prog_fail
	
	cmp.l		a0,a1					; is entire image verified?
	bgt			compare_loop			; if not, repeat
	
	trap		#0						; done
	nop

prog_fail:
	trap		#1						; failed
	nop
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -