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

252 lines
7.6 KiB
Plaintext

; --------------------------------------------------------------------------------
; @Title: ZYNQ-ULTRASCALE+-RPU on ZCU102 eMMC/SD_Card FLASH Programming Script
; @Description:
;
; S(D)RAM : 0xFFFC1000
; SD/SDIO/eMMC Controller base: 0xFF160000
; FLASH: SDCard
;
; @Keywords: ARM, Cortex-R5
; @Author: JIM
; @Board: ZCU102
; @Chip: ZYNQ-ULTRASCALE+-RPU
; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: zcu102-emmcsd.cmm 12996 2024-01-29 03:23:55Z jjeong $
LOCAL &arg1
ENTRY &arg1
&arg1=STRing.UPpeR("&arg1") // for example "PREPAREONLY"
&MMC_BASE=0xFF160000 ;SD0 SDIO Controller
&SDCARD=TRUE() ; SDCARD(1) or EMMC(0)
RESet
SYStem.RESet
SYStem.CPU ZYNQ-ULTRASCALE+-RPU
SYStem.MemAccess DAP
CORE.ASSIGN 1.
ETM.OFF
Trace.DISable
; <temporarily switch to BOOTMODE=JTAG>
; this sequence forces the SoC to use BOOTMODE=JTAG
; a SRST is issued using the debug logic
; we kickstart the first R5 for flash programming
SYStem.Option ResBreak OFF
SYStem.Option EnReset OFF
SYStem.Option TRST OFF
DO ~~/demo/arm/hardware/zynq_ultrascale/scripts/zynq-ultrascale_reset.cmm OVERRIDE_BOOTMODE=0x0
SYStem.Mode Prepare
DO ~~/demo/arm/hardware/zynq_ultrascale/scripts/zynq-ultrascale_kick_bootcore.cmm "R5_SINGLE"
SYStem.Mode.Attach
Break.direct
; </temporarily switch to BOOTMODE=JTAG>
; --------------------------------------------------------------------------------
; Power configuration, CRL_APB:(Clock Controller Low Power Domain)
; 0xFF5E0000
PER.Set.simple A:0xFF5E006C %Long 0x01010800 ;SD0_REF_CTRL
PER.Set.simple A:0xFF5E0070 %Long 0x01010800 ;SD1_REF_CTRL
PER.Set.simple A:0xFF5E0238 %Long 0x00010380 ;SD0&SD1 no reset
; --------------------------------------------------------------------------------
; Pin muxing MIO configuration, MIO control, IOU_SLCR (IOU SLCR Registers)
; 0xFF180000
PER.Set.simple A:0xFF180034 %Long 0x00000008 ;MIO13, SD0_DATA_IN[3]/SD0_DATA_OUT[3]
PER.Set.simple A:0xFF180038 %Long 0x00000008 ;MIO14, SD0_DATA_IN[3]/SD0_DATA_OUT[3]
PER.Set.simple A:0xFF18003C %Long 0x00000008 ;MIO15, SD0_DATA_IN[3]/SD0_DATA_OUT[3]
PER.Set.simple A:0xFF180040 %Long 0x00000008 ;MIO16, SD0_DATA_IN[3]/SD0_DATA_OUT[3]
PER.Set.simple A:0xFF180054 %Long 0x0x000008 ;MIO21, SD0_CMD
PER.Set.simple A:0xFF180058 %Long 0x0x000008 ;MIO22, SDIO0_CLK_OUT
PER.Set.simple A:0xFF180060 %Long 0x00000008 ;MIO24, SDIO0_CD_N
PER.Set.simple A:0xFF180204 %Long 0x55000006 ;!! Disable 3-state output buffers on MIO pins {0:77} !!
; --------------------------------------------------------------------------------
; Configure SD0 Host controller
Data.Set A:&MMC_BASE+0x02C %LE %Long (0x7<<24.)|0xE4007 ; sdio controller sw RESET
WAIT 2.s ;!! wait until the sd memory card is reset !!
Data.Set A:&MMC_BASE+0x028 %LE %Long 0xF04
Data.Set A:&MMC_BASE+0x004 %LE %Long 0x010200
Data.Set A:&MMC_BASE+0x02C %LE %Long 0xE8007
Data.Set A:&MMC_BASE+0x034 %LE %Long -1
Data.Set A:&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++0x47FF ~~/demo/arm/flash/byte/emmc.bin /KEEP /DualPort /STACKSIZE 0x200
Data.Set A:&MMC_BASE+0x2C %LE %Long 0x0E8007 ; 400Khz
FLASHFILE.GETID
Data.Set A:&MMC_BASE+0x2C %LE %Long 0x0E0407 ; increase clk <max 50.Mhz (base clock divided by 4)
IF &SDCARD==0 ;for eMMC
FLASHFILE.GETEXTCSD
//End of the test prepareonly
IF "&arg1"=="PREPAREONLY"
ENDDO
//When you access to the other partition on the flash
; FLASHFILE.SETEXTCSD 179. 0x48 ; access: partition null
; FLASHFILE.SETEXTCSD 179. 0x49 ; access: partition boot 1
; FLASHFILE.SETEXTCSD 179. 0x4A ; access: partition boot 2
FLASHFILE.DUMP 0x0
;FLASHFILE.ERASE 0x0--0xFFFFF ; Erase eMMC
;FLASHFILE.LOAD * 0x0 ; Write eMMC
ENDDO
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 200.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 100.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 200.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 200.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 200.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
SCREEN.ON
Data.Set &MMC_BASE+0x8 %Long 0x0 ;arg
Data.Set &MMC_BASE+0xc %Long 0x37020000 ;cmd55, resp1
WAIT 200.ms
//ACMD41
Data.Set &MMC_BASE+0x30 %Long 0xFFFFFFFF ;clear status
SCREEN.ON
Data.Set &MMC_BASE+0x8 %Long &OCR ;arg
Data.Set &MMC_BASE+0xc %Long 0x29020000 ;cmd41, resp1
WAIT 200.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 200.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 200.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
)