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

📄 main.asm

📁 5509a FLASH 的读写操作程序,测试过没任何问题
💻 ASM
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;wirter:	ke yuandan
;data:	Feb 5,2004
;
;name convention 
;for debug mode
;I use the test_funciton_mdole
;here test is the key word, if it's be used in the final project,this 
;key word should be remove,
;here function mean the test aim, for example, in a goto statement,
;I want the pc goto another line this is the loking test such as 
;test_loking_pll
;here the modle means the test modle such as mcbsp, pll, emif and so on.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;     
     .include "emif_reg.asm"
     .include "gpio_reg.asm"
     .include "mcbsp_reg.asm"
     .text 
	.global start
	.def getByteFromAddress
	.ref setTo40BitMode_
	.ref spiDouble8BitModeSecond
	.ref delay_,delay_us ;the default is ms
	.ref spiDouble8BitMode,spiFive8BitMode
	.def writeEnableLatch
	.def enableWriteState
	.def AAIwriteAddress0
	.def writeBootCode
	;.globl writeEnableLatch,enableWriteState,writeStateRegisterForAAIWrite,writeAddress0,writeBootCode
	;.def buffer_16245,buffer_384,cpld_cmd
	.ref initial
	.global setWriteStateReady,setReadStateReady
	.global eraseSPIFlash
	.def readStateRegister
	.def setOtherBit
	.ref setToReadSequenceMode;single phase, 16bit-mode, 128channal.
	;fowllowing are the spi mode write flash function
	.ref setTo8BitMode_
	.ref setTo16BitMode_
	;.ref setTo5_8BitMode_
	.ref SPIModeInitial
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;the input address is in ac0, and output byte is in
;ar6 for byte1, and ar7 for byte 0
getByteFromAddress:
	xar0=ac0
	ar7=*ar0
	ar6=#0ffh&ar7
	ac0=ar7
	ac0 = ac0<<<#-8
	ar7=ac0
	ar7&=#0ffh
	return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
setWriteStateReady:
pollWriteStateReady_mcbsp_sub:
	ar0=*port(SPCR2_0)
	tc1=bit(ar0, @#1)
	if(!tc1) goto pollWriteStateReady_mcbsp_sub
	return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
setReadStateReady:
pollReadStateReady_mcbsp_sub:
	ar0=*port(SPCR1_0)
	tc1=bit(ar0, @#1)
	if(!tc1) goto pollReadStateReady_mcbsp_sub
	return	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
readStateRegister: ;the state is in ar4 
	ar3=*port(DRR1_0);a null function only used to fluch the previous data
	call setWriteStateReady
	*port(DXR1_0)=#05h
	call setReadStateReady
	ar3=*port(DRR1_0);
	call setReadStateReady
	ar3=*port(DRR1_0);
	return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
writeEnableLatch:
	call setWriteStateReady
	*port(DXR1_0)=#06h
	return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
enableWriteState:
	call setWriteStateReady
	*port(DXR1_0)=#50h
	return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
setOtherBit:
	call setWriteStateReady
	*port(DXR1_0)=#01h
	call setWriteStateReady
	*port(DXR1_0)=#42h
	return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
AAIwriteAddress0:
	call setWriteStateReady
	*port(DXR1_0)=#0afh
	call setWriteStateReady
	*port(DXR1_0)=#0h
	call setWriteStateReady
	*port(DXR1_0)=#0h
	call setWriteStateReady
	*port(DXR1_0)=#0h
	call setWriteStateReady
	*port(DXR1_0)=#00h ;here should be change for the proper data
	ar5=#10
	call delay_us
	return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
setSPITo8DoubleMode:
	*port(SRGR2_0)=#3010h
	repeat(#2h)
	nop_16
	return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
setSPITo8SingleMode:
	*port(SRGR2_0)=#3008h
	repeat(#2h)
	nop_16
	return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eraseSPIFlash:
	call writeEnableLatch
	call enableWriteState
	call setSPITo8doubleMode
	call setWriteStateReady
	*port(DXR1_0)=#60h ;here should be 
	call setWriteStateReady
	*port(DXR1_0)=#60h ;her
	ar5=#100 ;delay for 100 ms
	call delay_ 
	return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	


;;;;;;;;;;;;fowllowing are the write boot code;;;;;;;;;;;;;;;;;;;;;
writeBootCode:
	;here I will implement all the write things!
		.data 
;transfer_start .long 600000h
transfer_size .word 1e8h ;use ar4 and ar5 for temporary usage
transfer_temp_address .word 0h
	.text
	xar4=#600000h
	
	if(@transfer_temp_address!=#0) goto write_again_sub
	goto the_first_write
write_again_sub:
	call setWriteStateReady
	*port(DXR1_0)=#0afh
	ar4=@transfer_temp_address
	nop_16
	ac1=high_byte(*ar4)
;	ac1=*ar4
;	ac1=ac1<<<#-8
	call setWriteStateReady
	*port(DXR1_0)=ac1
	;delay 20 us
	ar5=#20
	call delay_us
	
	call setWriteStateReady
	*port(DXR1_0)=#0afh
	ar4=@transfer_temp_address
	nop_16
	ac1=low_byte(*ar4)
	call setWriteStateReady
	*port(DXR1_0)=ac1
	;increment the temp_address
	ar4=@transfer_temp_address
	ar4+=#1
	@transfer_temp_address=ar4
	;delay 20 us
	ar5=#20
	call delay_us
	;judge if the transfer is complete
	ar4=@transfer_temp_address
	ac0=#1e8h
	ac0=ac0-ar4;ar4^#1e8h
	if(ac0!=#0h) goto write_again_sub
	goto write_ok_sub
the_first_write:
	call setWriteStateReady
	*port(DXR1_0)=#0afh
	call setWriteStateReady
	*port(DXR1_0)=#00h
	ar3=@transfer_temp_address
	ar3+=#1
	@transfer_temp_address=ar3
	;delay 20 us
	ar5=#20
	call delay_us
	goto write_again_sub
write_ok_sub:	
	return
;;;;;;;;;;;;;;;;;;;;;up is end of write boot code;;;;;;;;;;;;



start:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
	;todo
	xsp=#0f800h;make sure the xsp register be initial befor any call
	xssp=#0fd00h ;must be set
	;;;flag
	*port(IODIR)=#0c0h
	*port(IODATA)=#40h; the led is on
	call initial    
	;goto over            ;
******************************************************************

;*************you must request the diffrent test here	*******
	;goto over
	;goto        ;??? name
	
	;goto test_sdram_emif
	;goto test_cpld_emif
	;goto test_flashContrl_emif
	;goto test_spiFlashReadWrite_mcbsp
	;goto test_fuction_modle(including the test_fuction_modle_sub)
	;goto  fuction_modle(including the funciton_modle_sub)
		       ;this in only used for the final              ;*   
	                                                         ;*
;**************************************************************
	;todo, make sure we also need to test the 16245 output 
	;voltage and the 384 output voltage, because we can't 
	;get the input voltage levle to more the 3.4V
	
	;goto buffer_16245 pls test the pin ??
	;goto buffer_384 pls test the pin ??
	;goto cmd_?
	
	;todo 
	;add the routie as nessisary
	;todo 
	;add the routie as nessisary

	
	
;test_spiFlashReadWrite_mcbsp:
******initial the mcbsp0 port for data reading. test the memory
	;call spiDouble8BitMode ;this is also double phase
	;call spiFive8BitMode ;this is the 8+24+8 mode, using single phase
						;with multichannal
	
	
	
	;call SPIModeInitial ;defaulte is 8bit mode
	call setTo16BitMode_
	;call setTo40BitMode_ ;used for 16 command write and read
	;goto test_writeCode
	goto test_writeAndReadStateRegister ;my_flag
	
	;call setTo8BitMode_ 
	;call setWriteStateReady
	;*port(DXR1_0)=#06h ;wirte enable latch command
;	call setWriteStateReady
	;*port(DXR1_0)=#04h ;wirte disable latch command
	
	
	;call setTo16BitMode_ ;wite state register.
	;call setWriteStateReady

	;call setTo8BitMode_
	;*port(XCR1_0)=#0h
	;call setWriteStateReady
	;repeat(#10)
	;*port(DXR1_0)=#50h ;enable write state register 
	;call setWriteStateReady
	;*port(XCR1_0)=#0040h

	;call setTo8BitMode_	
	;call setWriteStateReady

	;*port(DXR1_0)=#0aah ;the 01 is write comand, 00 is the state value

	;call setTo16BitMode_
	
	
	;call setWriteStateReady

	;*port(DXR1_0)=#0cc00h   ;enable write state register
	;call setWriteStateReady
	;*port(DXR1_0)=#0100h ;the 01 is write comand, 00 is the state value
	

	call setTo16BitMode_
	ar2=*port(DRR1_0);this is null 	
	call setWriteStateReady;read state register
	*port(DXR1_0)=#0580h;05 is the read command.
	call setReadStateReady
	ar3=*port(DRR1_0);read the state value to DDR1
	;call eraseSPIFlash
	
	call setSPITo8SingleMode

	call writeEnableLatch	;wirte enable latch.

	call setSPITo8DoubleMode
	call enableWriteState	;enable write state register.
	
	;call setSPITo8DoubleMode
	call setOtherBit ;de-protect all the spi_flash
	
	
	;;;;;;;;;;;;;;;;;;;;;;;;;;
	;call setSPITo8DoubleMode;
	;call readStateRegister  ;
	;;;;;;;;;;;;;;;;;;;;;;;;;;

	call spiFive8BitMode
	call AAIwriteAddress0 ;write the first byte in adderss 0 
	;initial the mcbsp0 port for Device ID reading. test the waveform
	;repeat(#2)
	;ar5=*port(DRR1_0)
	;ac0=*port(SPCR1_0)
	;bit(ac0,#0)=1
	

	;goto test_sendAgain_mcbsp_sub
	
	;repeat(#2)
	;nop_16
	
	;repeat(#2)
	;nop_16
	*port(RCERA_0)=#0010h
	*port(XCERA_0)=#00fh
test_sendAgain_mcbsp_sub:

test_pollAgainA2_mcbsp_sub:	
	ar0=*port(SPCR2_0)
	tc1=bit(ar0, @#1)
	if(!tc1) goto test_pollAgainA2_mcbsp_sub
	*port(DXR1_0)=#0afh

test_pollAgain3_mcbsp_sub:	
	ar0=*port(SPCR2_0)
	tc1=bit(ar0, @#1)
	if(!tc1) goto test_pollAgain3_mcbsp_sub
	*port(DXR1_0)=#00fh
	
test_pollAgainA1_mcbsp_sub:
	ar0=*port(SPCR2_0)
	tc1=bit(ar0, @#1)
	if(!tc1) goto test_pollAgainA1_mcbsp_sub
	*port(DXR1_0)=#08fh
	;ar3=*port(DRR1_0)
	
test_pollAgainA3_mcbsp_sub	
	ar0=*port(SPCR2_0)
	tc1=bit(ar0, @#1)
	if(!tc1) goto test_pollAgainA3_mcbsp_sub
	*port(DXR1_0)=#0abh
	
	
test_pollAgainD_mcbsp_sub:	
	ar0=*port(SPCR1_0)
	tc1=bit(ar0, @#1)
	if(!tc1) goto test_pollAgainD_mcbsp_sub
	ar3=*port(DRR1_0);
	
	*port(IODIR)=#0c0h
	*port(IODATA)=#40h; the led is on

	;goto over

	call setWriteStateReady
	*port(DXR1_0)=#0aah
	
	;goto over


	call spiDouble8BitModeSecond;write the sequential value.
	call writeBootCode
	;goto over
	
;***********************************	
;************************************/

;/**********************************
		
	
	;read the value in two 610000 data address.
	call setToReadSequenceMode;single phase, 16bit-mode, 128channal.
	call setWriteStateReady
	*port(DXR1_0)=#0300h
	call setWriteStateReady
	*port(DXR1_0)=#0000h
	xar4=#610000h
	
over:	
	*port(IODATA)=#80h; the led is anernate
	goto over
	
test_writeAndReadStateRegister:
	call setWriteStateReady
	*port(DXR1_0)=#0606h; write enable latch
	call setWriteStateReady
	*port(DXR1_0)=#5050h  ;enable state register write
	call setWriteStateReady
	*port(DXR1_0)=#010ch;write state register 
	
	call setWriteStateReady
	*port(DXR1_0)=#5050h  ;enable state register write
	call setWriteStateReady
	*port(DXR1_0)=#0100h ;write state register for program in bp0 and 1
	
	
	;;;;;;;;;;;;;;;;;;;
	;goto no_Erase_sub;;
	;temp for the read state register and saved to ar3
	;;;;;fowllowing are the chip erase operation!
	call setWriteStateReady ;this is the erase operation!
	*port(DXR1_0)=#6060h
	ar5=#200
	call delay_
	
	call setWriteStateReady
	*port(DXR1_0)=#0606h; write enable latch
	call setWriteStateReady
	*port(DXR1_0)=#5050h  ;enable state register write
	call setWriteStateReady
	*port(DXR1_0)=#010ch;write state register 
	
	call setWriteStateReady
	*port(DXR1_0)=#5050h  ;enable state register write
	call setWriteStateReady
	*port(DXR1_0)=#0100h ;write state register for program in bp0 and 1
	
	
	
	

no_Erase_sub:	
	
	;repeat(#1000)
	;nop_16
	
	
;;;;;;;;;;;;;;;;the fowllowing are just for read state test. 
	;ar2=*port(DRR1_0) ;this is a null
	;call setReadStateReady
	;ar2=*port(DRR1_0) ;this is a null
	;call setReadStateReady
	;ar2=*port(DRR1_0) ;this is a null
	
	;for a general read, you should first read three times and then,
	;new data can coming!
test_writeAndReadStateRegister_:
	call setWriteStateReady
	*port(DXR1_0)=#0505h
	call setReadStateReady
	ar3=*port(DRR1_0)
	ar3=ar3^#02h
	if(ar3!=0) goto test_writeAndReadStateRegister_
	;goto test_writeCode	

test_writeCode:;the longth is 0f2h

	call setTo40BitMode_
	ar5=#310
	call delay_us
	
	;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;goto read_state_reg;;;;;;;
	goto real_write_code;;;;;;

	;goto temp_read 
temp_write:;used for write a byte
	ar7=#0200h
	call setWriteStateReady
	*port(DXR1_0)=ar7;#0200h
	ar7=#0008h
	call setWriteStateReady
	*port(DXR1_0)=ar7;#0070h
	ar7=#0ac00h
	call setWriteStateReady
	*port(DXR1_0)=ar7;#0ca00h
	call setWriteStateReady
	ar5=#20
	call delay_us
	;second write	
	
	call setWriteStateReady
	*port(DXR1_0)=#0606h; write enable latch
	call setWriteStateReady
	*port(DXR1_0)=#0606h; write enable latch
	call setWriteStateReady
	*port(DXR1_0)=#0606h; write enable latch
	
	ar7=#0200h
	call setWriteStateReady
	*port(DXR1_0)=ar7;#0200h
	ar7=#0009h
	call setWriteStateReady
	*port(DXR1_0)=ar7;#0070h
	ar7=#0ca00h
	call setWriteStateReady
	*port(DXR1_0)=ar7;#0ca00h
	call setWriteStateReady
	ar5=#20
	call delay_us
	;goto temp_write;temp_write;
read_state_reg:
	call setWriteStateReady
	*port(DXR1_0)=#0300h;#0ab00h;0.
	
	call setWriteStateReady
	*port(DXR1_0)=#0009h;#0000h;
	call setWriteStateReady
	*port(DXR1_0)=#0000h
	ar5=#1
	call delay_us
	goto read_state_reg;;loop back

	;ar7=#10

	;xar4 sdram的数据地址
	;xar6 是SPI FLASH的地址
	;AC0是长度
	;fowlowing are the real write boot code in. 
real_write_code:
	xar4=#600000h
	;ac3=*ar4
	xar6=#0
	ac0=#2eh      ;the length is 2e391h:techshine
	ac0=ac0<<<#12
	ac0=ac0+#04a7h	
	;ac0=#73
	
test_writeCode_again:
	pshboth(ac0)

	call setWriteStateReady
	*port(DXR1_0)=#0606h; write enable latch
	call setWriteStateReady
	*port(DXR1_0)=#0606h; write enable latch
	call setWriteStateReady
	*port(DXR1_0)=#0606h; write enable latch
	
	call setWriteStateReady
	ac0=xar6
	ac0=ac0<<<#-16
	ac0|=#0200h
	*port(DXR1_0)=ac0;#0200h;ac3
	
	ac3=ar6
	call setWriteStateReady
	*port(DXR1_0)=ac3
	
	ac3=*ar4 
	call setWriteStateReady
	*port(DXR1_0)=ac3  ;write the high byte.
	
	ac0=xar6 ;increase the spi_flash address.
	ac0+=#1
	xar6=ac0
	
	ar5=#20
	call delay_us
	
	
	
	call setWriteStateReady
	*port(DXR1_0)=#0606h; write enable latch
	call setWriteStateReady
	*port(DXR1_0)=#0606h; write enable latch
	call setWriteStateReady
	*port(DXR1_0)=#0606h; write enable latch

	call setWriteStateReady
	ac0=xar6
	ac0=ac0<<<#-16
	ac0|=#0200h
	*port(DXR1_0)=ac0;#0200h;ac3
	
	ac3=ar6
	call setWriteStateReady
	*port(DXR1_0)=ac3 ;the address
	

	ac3=*ar4
	ac3=ac3<<<#8
	call setWriteStateReady
	*port(DXR1_0)=ac3
	
	ac0=xar6 ;increase the spi_flash address.
	ac0+=#1
	xar6=ac0
	
	ac0=xar4 ;increase the SDRAM address
	ac0+=#1
	xar4=ac0
	
	ar5=#20
	call delay_us
	
	;ar6-=#1  ;count down. 
	ac0=popboth()
	ac0-=#1
	
	;ar2+=#1  ;increment the address. 
	if(ac0!=#0) goto test_writeCode_again
	goto over
	.end

⌨️ 快捷键说明

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