您好,歡迎進入深圳市穎特新科技有限公司官方網(wǎng)站!
Flash存儲器支持硬件編程和應(yīng)用編程(IAP)。如果產(chǎn)品在研發(fā)階段或產(chǎn)品需要更新軟固件時,硬件編程就顯得不太方便,采用在系統(tǒng)編程(ISP)方式,可使這一過程變得方便。執(zhí)行ISP不需要將控制器從系統(tǒng)板上拆下來。通過軟件控制可以重新編程設(shè)備。因此這使得更新應(yīng)用程序固件ISP得到廣泛的應(yīng)用。
用戶可以開發(fā)自己的引導(dǎo)代碼放在LDROM中。LDROM最大為4KB。用戶開發(fā)的引導(dǎo)代碼可以通過并行燒錄器或是電路編程器(ICP)下載到LDROM中去。
一般來說,ISP是PC與MCU之間進行通訊。PC通過串口傳輸新的用戶代碼給MCU。然后引導(dǎo)代碼接收這些數(shù)據(jù),將這些數(shù)據(jù)通過IAP命令編程到用戶代碼區(qū)域。新唐針對N76E003提供ISP固件和PC端軟件,這樣可以很容易實現(xiàn)ISP通過UART端口升級代碼。
以下是簡單ISP參考代碼
匯編例程代碼:
;******************************************************************************
; This code illustrates how to do APROM and CONFIG IAP from LDROM.
; APROM are re-programmed by the code to output P1 as 55h and P0 as aah.
; The CONFIG2 is also updated to disable BOD reset.
; User needs to configure CONFIG0 = 0x7F, CONFIG1 = 0xFE, CONFIG2 = 0xFF.
;******************************************************************************
PAGE_ERASE_AP EQU 00100010b
BYTE_PROGRAM_AP EQU 00100001b
BYTE_READ_AP EQU 00000000b
ALL_ERASE_CONFIG EQU 11100010b
BYTE_PROGRAM_CONFIG EQU 11100001b
BYTE_READ_CONFIG EQU 11000000b
ORG 0000h
CLR EA ;disable all interrupts
CALL Enable_IAP
CALL Enable_AP_Update
CALL Erase_AP ;erase AP data
CALL Program_AP ;programming AP data
CALL Disable_AP_Update
CALL Program_AP_Verify ;verify Programmed AP data
CALL Read_CONFIG ;read back CONFIG2
CALL Enable_CONFIG_Update
CALL Erase_CONFIG ;erase CONFIG bytes
CALL Program_CONFIG ;programming CONFIG2 with new data
CALL Disable_CONFIG_Update
CALL Program_CONFIG_Verify ;verify Programmed CONFIG2
CALL Disable_IAP
MOV TA,#0Aah ;TA protection
MOV TA,#55h ;
ANL CHPCON,#11111101b ;BS = 0, reset to APROM
MOV TA,#0Aah
MOV TA,#55h
ORL CHPCON,#80h ;software reset and reboot from APROM
SJMP $
;********************************************************************
; IAP Subroutine
;********************************************************************
Enable_IAP:
MOV TA,#0Aah ;CHPCON is TA protected
MOV TA,#55h
ORL CHPCON,#00000001b ;IAPEN = 1, enable IAP mode
RET
Disable_IAP:
MOV TA,#0Aah
MOV TA,#55h
ANL CHPCON,#11111110b ;IAPEN = 0, disable IAP mode
RET
Enable_AP_Update:
MOV TA,#0Aah ;IAPUEN is TA protected
MOV TA,#55h
ORL IAPUEN,#00000001b ;APUEN = 1, enable APROM update
RET
Disable_AP_Update:
MOV TA,#0Aah
MOV TA,#55h
ANL IAPUEN,#11111110b ;APUEN = 0, disable APROM update
RET
Enable_CONFIG_Update:
MOV TA,#0Aah
MOV TA,#55h
ORL IAPUEN,#00000100b ;CFUEN = 1, enable CONFIG update
RET
Disable_CONFIG_Update:
MOV TA,#0Aah
MOV TA,#55h
ANL IAPUEN,#11111011b ;CFUEN = 0, disable CONFIG update
RET
Trigger_IAP:
MOV TA,#0Aah ;IAPTRG is TA protected
MOV TA,#55h
ORL IAPTRG,#00000001b ;write ‘1’ to IAPGO to trigger IAP process
RET
;********************************************************************
; IAP APROM Function
;********************************************************************
Erase_AP:
MOV IAPCN,#PAGE_ERASE_AP
MOV IAPFD,#0FFh
MOV R0,#00h
Erase_AP_Loop:
MOV IAPAH,R0
MOV IAPAL,#00h
CALL Trigger_IAP
MOV IAPAL,#80h
CALL Trigger_IAP
INC R0
CJNE R0,#44h,Erase_AP_Loop
RET
Program_AP:
MOV IAPCN,#BYTE_PROGRAM_AP
MOV IAPAH,#00h
MOV IAPAL,#00h
MOV DPTR,#AP_code
Program_AP_Loop:
CLR A
MOVC A,@A+DPTR
MOV IAPFD,A
CALL Trigger_IAP
INC DPTR
INC IAPAL
MOV A,IAPAL
CJNE A,#14,Program_AP_Loop
RET
Program_AP_Verify:
MOV IAPCN,#BYTE_READ_AP
MOV IAPAH,#00h
MOV IAPAL,#00h
MOV DPTR,#AP_code
Program_AP_Verify_Loop:
CALL Trigger_IAP
CLR A
MOVC A,@A+DPTR
MOV B,A
MOV A,IAPFD
CJNE A,B,Program_AP_Verify_Error
INC DPTR
INC IAPAL
MOV A,IAPAL
CJNE A,#14,Program_AP_Verify_Loop
RET
Program_AP_Verify_Error:
CALL Disable_IAP
MOV P0,#00h
SJMP $
;********************************************************************
; IAP CONFIG Function
;********************************************************************
Erase_CONFIG:
MOV IAPCN,#ALL_ERASE_CONFIG
MOV IAPAH,#00h
MOV IAPAL,#00h
MOV IAPFD,#0FFh
CALL Trigger_IAP
RET
Read_CONFIG:
MOV IAPCN,#BYTE_READ_CONFIG
MOV IAPAH,#00h
MOV IAPAL,#02h
CALL Trigger_IAP
MOV R7,IAPFD
RET
Program_CONFIG:
MOV IAPCN,#BYTE_PROGRAM_CONFIG
MOV IAPAH,#00h
MOV IAPAL,#02h
MOV A,R7
ANL A,#11111011b
MOV IAPFD,A ;disable BOD reset
MOV R6,A ;temp data
CALL Trigger_IAP
RET
Program_CONFIG_Verify:
MOV IAPCN,#BYTE_READ_CONFIG
MOV IAPAH,#00h
MOV IAPAL,#02h
CALL Trigger_IAP
MOV B,R6
MOV A,IAPFD
CJNE A,B,Program_CONFIG_Verify_Error
RET
Program_CONFIG_Verify_Error:
CALL Disable_IAP
MOV P0,#00h
SJMP $
;********************************************************************
; APROM code
;********************************************************************
AP_code:
DB 75h,0B1h, 00h ;OPCODEs of “MOV P0M1,#0”
DB 75h,0B3h, 00h ;OPCODEs of “MOV P1M1,#0”
DB 75h, 90h, 55h ;OPCODEs of “MOV P1,#55h”
DB 75h,080h,0Aah ;OPCODEs of “MOV P0,#0Aah”
DB 80h,0Feh ;OPCODEs of “SJMP $”
END
按照那條路,一步一步走,如果感覺慢,那就加快一些腳步,時不我待,可是別因為著急就什么也不管不顧,那樣損失會更多
下一篇:N76E003之串口
掃碼關(guān)注我們
傳真:0755-82591176
郵箱:vicky@yingtexin.net
地址:深圳市龍華區(qū)民治街道民治大道973萬眾潤豐創(chuàng)業(yè)園A棟2樓A08