Files
Gen4_R-Car_Trace32/2_Trunk/demo/arm/flash/zynq7000-emmcsd.cmm
2025-10-14 09:52:32 +09:00

290 lines
8.1 KiB
Plaintext

; --------------------------------------------------------------------------------
; @Title: Xilinx ZC706(ZYNQ-7000) EMMC/SDCARD Flash Programming CMM
; @Description:
; Prerequisites:
; * Debugger or Combiprobe is connected to J62
; * Set SW4 to 11.
; * Set SW11
; MIO[2..6]=0y00000 - JTAG BOOT
; or
; MIO[2..6]=0y00110 - SD BOOT
; * IF a FMC debug card is plugged TDI-TDO must be shorted on the card
; Note:
;
; @Keywords: Cortex-A9, Xilinx, Zynq, Zynq7000
; @Board: ZC706
; @Chip: Zynq-7000
; @Author: JIM
; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: zynq7000-emmcsd.cmm 12996 2024-01-29 03:23:55Z jjeong $
LOCAL &arg1
ENTRY &arg1
&arg1=STRing.UPpeR("&arg1") // for example "PREPAREONLY"
&MMC_BASE=0xE0100000 ;SD0 SDIO Controller
&SDCARD=TRUE() ; SDCARD(1) or EMMC(0)
SYStem.RESet
RESet
SYStem.CPU ZYNQ-7000
SYStem.MemAccess DAP
; This selects the DAP for accessing the ARM cores
; (accessing the TAP of the FPGA logic requires different settings)
SYStem.CONFIG.DAPIRPRE 6.
SYStem.CONFIG.DAPIRPOST 0.
SYStem.CONFIG.DAPDRPRE 1.
SYStem.CONFIG.DAPDRPOST 0.
TrOnchip.Set.RESET OFF
TrOnchip.Set.UNDEF OFF
TrOnchip.Set.DABORT OFF
TrOnchip.Set.PABORT OFF
SYStem.JtagClock CTCK 10.0MHz
CORE.ASSIGN 1.
SYStem.Mode.Attach
IF STATE.RUN()
Break.direct
//disable MMU & Cache
PER.Set C15:0x1 %Long 0x18c52c78
; PC should be around 0xfffc0000--0xffffffff
; SLCR - UNLOCK WRITE
Data.Set ASD:0XF8000008 %Long 0x0000DF0D
; Assert Reset of Second core - we are save to remap memories
Data.Set ASD:0xF8000244 %Long 0x2
; MMU disable, Exception Vectors HIGH
Data.Set C15:0x1 %Long 0x18C52478
; OCM_CFG - ALL RAMS HIGH 0xfffc0000
Data.Set AZSD:0xF8000910 %Long 0x1F
; exception Vectors
Data.Assemble R:0xffff0000 b $+0
Data.Assemble , b $+0
Data.Assemble , b $+0
Data.Assemble , b $+0
Data.Assemble , b $+0
Data.Assemble , b $+0
Data.Assemble , b $+0
; set PC to a endless loop in OCM - prevent issues with XIP mode
Register.Set PC 0xffff0020
Data.Assemble R:0xffff0020 b $+0
; ------------------------------------------------------------------------------
; Flash Power & Clock Enable
PER.Set.simple C15:0x1 %Long Data.Long(C15:0x1)&(~0x1)
Data.Set AZSD:0XF8000008 %Long 0x0000DF0D ; SLCR - UNLOCK WRITE
Data.Set AZSD:0xF8000150 %LE %Long 0x1403 ; clk for sdio
Data.Set AZSD:0xF800012C %LE %Long Data.Long(AZSD:0xF800012C)|0xC00 ; Enable Clock of QSPI
Data.Set AZSD:0xF8000218 %LE %Long 0x10 ; assert RESET
WAIT 100.ms
Data.Set AZSD:0xF8000218 %LE %Long 0x0 ; deassert RESET
WAIT 100.ms
; ------------------------------------------------------------------------------
; Flash Pin Mux Configuration
GOSUB PINMUX_CONFIG
; ------------------------------------------------------------------------------
; Setup Flash Controller
Data.Set AZSD:&MMC_BASE+0x02C %LE %Long 0x7<<24. ; sdio controller sw RESET
WAIT 100.ms
Data.Set AZSD:&MMC_BASE+0x028 %LE %Long 0xF04
Data.Set AZSD:&MMC_BASE+0x004 %LE %Long 0x010200
Data.Set AZSD:&MMC_BASE+0x02C %LE %Long 0xE4007
Data.Set AZSD:&MMC_BASE+0x034 %LE %Long -1
Data.Set AZSD:&MMC_BASE+0x038 %LE %Long -1
; ------------------------------------------------------------------------------
; Flash Read ID Test
GOSUB READ_ID_TEST
; ------------------------------------------------------------------------------
; Flash declaration
FLASHFILE.RESet
;FLASHFILE.CONFIG <eMMC controller> <0x0> <0x0>
FLASHFILE.CONFIG &MMC_BASE 0x0 0x0
;FLASHFILE.TARGET <<code range>> <<data range>> <<algorithm file>>
IF &SDCARD==1
FLASHFILE.TARGET 0xFFFC0000++0x3FFF E:0xFFFD0000++0x47FF ~~/demo/arm/flash/byte/emmcsd.bin /KEEP /DualPort /STACKSIZE 0x200
ELSE
FLASHFILE.TARGET 0xFFFC0000++0x3FFF E:0xFFFD0000++0x41FF ~~/demo/arm/flash/byte/emmc.bin /KEEP
Data.Set A:&MMC_BASE+0x2C %LE %Long 0x0A8007 ; make a slower clk around 400Khz for the initialization of MMC/SD
FLASHFILE.GETID
Data.Set A:&MMC_BASE+0x2C %LE %Long 0x0A0107 ; make a higher clk around 25Mhz
IF &SDCARD==0 ;for eMMC
FLASHFILE.GETEXTCSD
//End of the test prepareonly
IF "&arg1"=="PREPAREONLY"
ENDDO
FLASHFILE.DUMP 0x0 ; Read eMMC/SD
;FLASHFILE.ERASE 0x0--0xFFFFF ; Erase eMMC/SD
;FLASHFILE.LOAD * 0x0 /NoZero ; Write eMMC/SD
;FLASHFILE.LOAD * 0x0 /ComPareCKSUM ;Verify eMMC/SD
ENDDO
PINMUX_CONFIG:
(
Data.Set AZSD:0xF8000738 %LE %Long 0x1201
Data.Set AZSD:0xF800073C %LE %Long 0x1201
Data.Set AZSD:0xF80007A0 %LE %Long 0x280 ;LVCMOS18, Lvl3 Mux, MIO40
Data.Set AZSD:0xF80007A4 %LE %Long 0x280 ;LVCMOS18, Lvl3 Mux, MIO41
Data.Set AZSD:0xF80007A8 %LE %Long 0x280 ;LVCMOS18, Lvl3 Mux, MIO42
Data.Set AZSD:0xF80007AC %LE %Long 0x280 ;LVCMOS18, Lvl3 Mux, MIO43
Data.Set AZSD:0xF80007B0 %LE %Long 0x280 ;LVCMOS18, Lvl3 Mux, MIO44
Data.Set AZSD:0xF80007B4 %LE %Long 0x280 ;LVCMOS18, Lvl3 Mux, MIO45
RETURN
)
READ_ID_TEST:
(
IF !&SDCARD
&OCR=0x40FF8080 ; init with low voltage power 1.7~1.95v, ex. eMMC
ELSE
&OCR=0x40FF8000 ; init with defualt voltage power 2.7~3.6v, ex. SD
IF &SDCARD==1 //SD(HC) interface, not MMC
(
//CMD0
RePeaT 2.
(
Data.Set &MMC_BASE+0x30 %Long 0xFFFFFFFF ;clear status
Data.Set &MMC_BASE+0x8 %Long 0x0 ;arg
Data.Set &MMC_BASE+0xc %Long 0x0 ;cmd
WAIT 10.ms
)
//CMD8, is madatory to intialize High Capacity SD Memory Card
RePeaT 2.
(
Data.Set &MMC_BASE+0x30 %Long 0xFFFFFFFF ;clear status
Data.Set &MMC_BASE+0x8 %Long 0x1AA ;arg
Data.Set &MMC_BASE+0xc %Long 0x08020000 ;cmd
WAIT 10.ms
&status=Data.Long(A:&MMC_BASE+0x30)
IF (&status&0x30000)==0x0
(
PRINT "passed CMD8(voltage check)"
GOTO jump_cmd55
)
ELSE
(
//CMD0
Data.Set &MMC_BASE+0x30 %Long 0xFFFFFFFF ;clear status
Data.Set &MMC_BASE+0x8 %Long 0x0 ;arg
Data.Set &MMC_BASE+0xc %Long 0x0 ;cmd
WAIT 10.ms
)
)
)
ELSE //MMC interface, not SD(HC)
(
//CMD0
RePeaT 2.
(
Data.Set &MMC_BASE+0x30 %Long 0xFFFFFFFF ;clear status
Data.Set &MMC_BASE+0x8 %Long 0x0 ;arg
Data.Set &MMC_BASE+0xc %Long 0x0 ;cmd
WAIT 10.ms
)
//CMD1
RePeaT 10.
(
Data.Set &MMC_BASE+0x30 %Long 0xFFFFFFFF ;clear status
Data.Set &MMC_BASE+0x8 %Long &OCR ;arg
Data.Set &MMC_BASE+0xc %Long 0x01020000 ;cmd1
WAIT 100.ms
&resp=Data.Long(A:(&MMC_BASE+0x10))
//print "CMD1 resp: 0x" &resp
IF (&resp&0x80000000)==0x80000000
(
GOTO jump_cmd2
)
)
PRINT "CMD1 fail"
END
)
jump_cmd55:
//CMD55
RePeaT 10.
(
Data.Set &MMC_BASE+0x30 %Long 0xFFFFFFFF ;clear status
Data.Set &MMC_BASE+0x8 %Long 0x0 ;arg
Data.Set &MMC_BASE+0xc %Long 0x37020000 ;cmd55, resp1
WAIT 100.ms
//ACMD41
Data.Set &MMC_BASE+0x30 %Long 0xFFFFFFFF ;clear status
Data.Set &MMC_BASE+0x8 %Long &OCR ;arg
Data.Set &MMC_BASE+0xc %Long 0x29020000 ;cmd41, resp1
WAIT 100.ms
&resp=Data.Long(A:(&MMC_BASE+0x10))
//print "CMD1 resp: 0x" &resp
IF (&resp&0x80000000)==0x80000000
(
GOTO jump_cmd2
)
)
PRINT "ACMD41 fail"
END
jump_cmd2:
//CMD2
Data.Set &MMC_BASE+0x30 %Long 0xFFFFFFFF ;clear status
Data.Set &MMC_BASE+0x8 %Long 0x0 ;arg
Data.Set &MMC_BASE+0xc %Long 0x02010000 ;cmd2
WAIT 10.ms
//CMD3
Data.Set &MMC_BASE+0x30 %Long 0xFFFFFFFF ;clear status
Data.Set &MMC_BASE+0x8 %Long 0x00010000 ; arg, MMC RCA is (0x0001<<16.)
Data.Set &MMC_BASE+0xc %Long 0x03020000 ;cmd3
WAIT 10.ms
&cardaddress=Data.Long(A:(&MMC_BASE+0x10))
&cardaddress=&cardaddress&0xFFFF0000
//CMD10
Data.Set &MMC_BASE+0x30 %Long 0xFFFFFFFF ;clear status
IF &SDCARD==1
Data.Set &MMC_BASE+0x8 %Long &cardaddress ; arg, card address
ELSE
Data.Set &MMC_BASE+0x8 %Long 0x00010000 ; arg, MMC RCA is (0x0001<<16.)
Data.Set &MMC_BASE+0xc %Long 0x0A010000 ;cmd10
WAIT 10.ms
//Response2
PRINT "CID register"
PRINT "[127:104] 0x" Data.Long(A:(&MMC_BASE+0x1c))
PRINT "[103:72] 0x" Data.Long(A:(&MMC_BASE+0x18))
PRINT "[71:40] 0x" Data.Long(A:(&MMC_BASE+0x14))
PRINT "[39:8] 0x" Data.Long(A:(&MMC_BASE+0x10))
RETURN
)