📄 flash.asm
字号:
*********************************************************************************
* seeddsk.asm v1.00 *
* copy (c) 2002- SEED Lt.d *
* function: flash writing and the way of bootloader from flash *
* design: lifeng duan *
*********************************************************************************
.copy "flash.h"
.copy "VC5402.h"
.global _main
.mmregs
***********************************************************************************
* *
* when running this code ,please load the blink.out under flashboot\ *
* blink\. *
* *
***********************************************************************************
stack .usect ".stack",64
.text
__STACK_SIZE .set 40H
SWWSR_VALI .set 0FFFFH ;I/O:10w/s;Data U:10w/s,L:4w/s;PROG U:10w/s,L:4w/s
SWCR_VALI .set 0000H ;Wait states x2
***********************************************************************************
* *
* we boot the blink.out in this example *
* init the DSP vc5402 *
***********************************************************************************
_main: STM #(stack+__STACK_SIZE-1),SP ; set to beginning of stack memory
; add size to get to top
ANDM #0fffeh,*(SP) ; make sure it is an even address
RSBX SXM ; make the led is off
SSBX XF ; turn on LED
ANDM #0000H,*(IMR) ; forbiden all interruption
ANDM #OVLY_0,*(PMST) ; OVLY = 0
RSBX CPL ; make the DP is ok
STM #SWWSR_VALI,SWWSR ; set the SWWSR
STM #SWCR_VALI,SWCR
LD #04H,DP ; set the dp register
STM #0,AH
STM #FLASHENB,AL
STL A,1H
NOP
NOP
NOP
NOP
PORTW 1H,CNTL2 ; make flash is at high 512k of the program memory
NOP
NOP
NOP
NOP
NOP
****************************************************************************************
* erase flash *
****************************************************************************************
CALL flash_erase
****************************************************************************************
* the firt step of the bootload: *
* write the address of the boottable to 0xFFFF,which is the address of the data *
* space *
* the address of the Seeddsk's flash is 0x4000~0xFFFF,so ,the first address of our *
* boottable at 0x4000. *
* the first address of our flash in program is 0x80000,so, we write 0x4000 to *
* 0x84000. *
****************************************************************************************
STM #Flash_base,AH ;the entrance for write flash is 0x80000
STM #0FFFFH,AL ;the offsize is 0x4000
ST #4000H,4H ; the data which write to flash is 0x203H
CALL flash_write
BC next1,ANEQ ;if A!=0 ,write next data
B $
****************************************************************************************
* the second step of the bootload: *
* write the first word of the boot table ,which is tell the DSP how many bit flash *
* you selected. we select 16-bit flash ,so we write 0x10aa to this word. *
****************************************************************************************
next1: STM #Flash_base,AH
STM #4000H,AL
ST #10AAH,4H
CALL flash_write
BC next2,ANEQ ;if A!=0 ,write next data
B $
******************************************************************************************
* the third step of the bootload: *
* write the second word of the boot table ,which will initialize the value of SWWSR *
* we write 0xffff to this register ,this value is reset value *
******************************************************************************************
next2: STM #Flash_base,AH
STM #4001H,AL
ST #0FFFFH,4H
CALL flash_write
BC next3,ANEQ ;if A!=0 ,write next data
B $
******************************************************************************************
* the four step of the bootload: *
* write the third word of the boot table ,which will initialize the value of BSCR *
* we write 0x800 to this register, *
******************************************************************************************
next3: STM #Flash_base,AH
STM #4002H,AL
ST #0800H,4H
CALL flash_write
BC next4,ANEQ ;if A!=0 ,write next data
B $
******************************************************************************************
* the five step of the bootload: *
* write the Entry point (Xpc) and write the Entry point PC *
* you can see the blink.map ,find the address of _cinit00 *
* in the example XPC is 0 PC is 0x1036
******************************************************************************************
next4: STM #Flash_base,AH ;write the XPC to 4003
STM #4003H,AL
ST #0000H,4H
CALL flash_write
BC next5,ANEQ ;if A!=0 ,write next data
B $
next5: STM #Flash_base,AH ;write the PC to 4004
STM #4004H,AL
ST #1036H,4H
CALL flash_write
BC next6,ANEQ ;if A!=0 ,write next data
B $
******************************************************************************************
* the sixth step of the bootload: *
* write the code to flash ,we only write the code and the INITIALIZED section. *
* First ,write the size of the section *
* Second ,write the destination XPC of the section *
* Third ,write the destination PC of the section *
* fourth, write the data of the code *
* so ,writing the first section *
******************************************************************************************
next6: STM #Flash_base,AH ;write the size of the first section(.cinit)to 4005
STM #4005H,AL
ST #036H,4H
CALL flash_write
BC next7,ANEQ ;if A!=0 ,write next data
B $
next7: STM #Flash_base,AH ;write the xPC of the first section(.cinit)to 4006
STM #4006H,AL
ST #0,4H
CALL flash_write
BC next8,ANEQ ;if A!=0 ,write next data
B $
next8: STM #Flash_base,AH ;write the PC of the first section(.cinit)to 4007
STM #4007H,AL
ST #01000H,4H
CALL flash_write
BC next9,ANEQ ;if A!=0 ,write next data
B $
******************************************************************************************
* save the address of flash to 6H *
******************************************************************************************
next9: STM #Flash_base,AH
STM #4008H,AL
DST A,6H ;save the address of the flash
STM #0,AH
STM #01000H,AL
STLM A,AR1 ;write the address of fisrt section(.cinit) to AR1
NOP
NOP
NOP
STM #0,AH
STM #036H,AL
STLM A,AR2 ;AR2 is the longth of we recieved fisrt section(.cinit)
DLD 6H,A ;get the address of flash
CALL bwrite ;write to flash
BC bnext1,ANEQ ;if(a=0),write to flash is error
B $
bnext1: NOP
NOP
DLD 2H,A
NOP
NOP
ADD #1,A ;get the end address to A
NOP
NOP
DST A,6H ;save next block address of flash
*****************************************************************************************
* write the sencod section (.text) *
*****************************************************************************************
DLD 6H,A ;get the address of flash
ST #035aH,4H
CALL flash_write ;write the size of the sencod section(.text)
BC nexta,ANEQ ;if A!=0 ,write next data
B $
nexta: DLD 6H,A ;get the address of flash
NOP
NOP
ADD #1,A ;get the end address to A
NOP
NOP
DST A,6H ;save next block address of flash
DLD 6H,A ;get the address of flash
ST #0,4H
CALL flash_write ;write the XPC of the sencod section(.text)to 4006
BC nextb,ANEQ ;if A!=0 ,write next data
B $
nextb: DLD 6H,A ;get the address of flash
NOP
NOP
ADD #1,A ;get the end address to A
NOP
NOP
DST A,6H ;save next block address of flash
DLD 6H,A ;get the address of flash
ST #1036H,4H
CALL flash_write ;write the PC of the sencod section(.text)
BC nextc,ANEQ ;if A!=0 ,write next data
B $
nextc: DLD 6H,A ;get the address of flash
NOP
NOP
ADD #1,A ;get the end address to A
NOP
NOP
DST A,6H ;save next block address of flash
STM #0,AH
STM #01036H,AL
STLM A,AR1 ;write the address of sencod section(.text) to AR1
NOP
NOP
NOP
STM #0,AH
STM #035aH,AL
STLM A,AR2 ;AR2 is the longth of the sencod section(.text)
DLD 6H,A ;get the address of flash
CALL bwrite ;write to flash
BC bnext2,ANEQ ;if(a=0),write to flash is error
B $
bnext2: NOP
NOP
DLD 2H,A
NOP
NOP
ADD #1,A ;get the end address to A
NOP
NOP
DST A,6H ;save next block address of flash
******************************************************************************************
* write the third section(.vector) to flash *
******************************************************************************************
DLD 6H,A ;get the address of flash
ST #078H,4H
CALL flash_write ;write the size of the third section(.vectors)
BC nextd,ANEQ ;if A!=0 ,write next data
B $
nextd: DLD 6H,A ;get the address of flash
NOP
NOP
ADD #1,A ;get the end address to A
NOP
NOP
DST A,6H ;save next block address of flash
DLD 6H,A ;get the address of flash
ST #0,4H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -