260 lines
8.2 KiB
Plaintext
260 lines
8.2 KiB
Plaintext
; --------------------------------------------------------------------------------
|
|
; @Title: SDCARD program Script for ST STM32MP157
|
|
;
|
|
; @Description:
|
|
; Boot configurations:
|
|
; BOOT[2:0] = x001 ;UART and USB
|
|
; BOOT[2:0] = x001 ;Serial NOR
|
|
; BOOT[2:0] = x010 ;eMMC
|
|
; BOOT[2:0] = x011 ;NAND
|
|
; BOOT[2:0] = x101 ;SD
|
|
; BOOT[2:0] = x111 ;Serial NAND
|
|
;
|
|
; SD pin configurations:
|
|
; SDMMC1_D[0:3] -- PC[8:11]
|
|
; SDMMC1_CK -- PC12
|
|
; SDMMC1_CKIN -- PE4
|
|
; SDMMC1_CMD -- PD2
|
|
; SDMMC1_CDIR -- PB8
|
|
; SDMMC1_D0DIR -- PF2
|
|
; SDMMC1_D123DIR -- PC7
|
|
; uSD_LDO_SEL -- PF14
|
|
; uSD_DETECT -- PG1
|
|
; uSD_LS_EN -- PE11
|
|
;
|
|
; @Keywords: ARM, Cortex-A7, SDCARD
|
|
; @Author: JIM
|
|
; @Board: STM32MP15X-EVAL
|
|
; @Chip: STM32MP157A-CA7
|
|
; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only
|
|
; --------------------------------------------------------------------------------
|
|
; $Id: stm32mp157-sd.cmm 12746 2023-11-17 09:17:02Z mschaeffner $
|
|
|
|
WinCLEAR
|
|
|
|
&MMC_BASE=0x58005000 ;SDMMC1
|
|
|
|
PRIVATE ¶meters
|
|
ENTRY %LINE ¶meters
|
|
|
|
PRIVATE ¶m_prepareonly ¶m_cpu ¶m_dualport
|
|
¶m_prepareonly=(STRing.SCAN(STRing.UPpeR("¶meters"),"PREPAREONLY",0)!=-1)
|
|
¶m_cpu=STRing.SCANAndExtract(STRing.UPpeR("¶meters"),"CPU=","")
|
|
¶m_dualport=STRing.SCANAndExtract(STRing.UPpeR("¶meters"),"DUALPORT=","0")
|
|
|
|
; ------------------------------------------------------------------------------
|
|
; Setup CPU
|
|
RESet
|
|
SYStem.RESet
|
|
SYStem.CPU STM32MP157A-CA7
|
|
SYStem.JtagClock 10MHz
|
|
CORE.ASSIGN 1.
|
|
Trace.DISable
|
|
SYStem.MemAccess DAP
|
|
SYStem.Up
|
|
|
|
PER.Set.simple C15:0x1 %Long (Data.Long(C15:0x1)&~(0x1)) ; disable MMU
|
|
|
|
Data.Set A:0x500008F4 %LE %Long 0x3 ;0x3: hsi_ker_ck clock selected as kernel peripheral clock (default after reset)
|
|
|
|
; ------------------------------------------------------------------------------
|
|
; Flash Power & Clock Enable
|
|
Data.Set A:0x50000000+0x218 %LE %Long (0x1<<16.) ; RCC_MP_AHB6ENSETR, FMCEN
|
|
Data.Set A:0x50000000+0x19C %LE %Long (0x1<<16.) ; RCC_AHB6RSTCLRR, FMCEN NAND controller reset
|
|
Data.Set A:0x50000000+0x198 %LE %Long Data.Long(A:(0x50000000+0x198))&~(0x1<<16.) ; RCC_AHB6RSTSER, release NAND memory controller reset
|
|
Data.Set A:0x50000000+0x398 %LE %Long (0x1<<16.) ; RCC_AHB6LPENSETR, NAND memory controller clock enable during Sleep mode
|
|
|
|
Data.Set A:0x50000000+0xA28 %LE %Long 0xFF ;GPIO D(3) & E(4) & G(6) clk enable
|
|
|
|
; ------------------------------------------------------------------------------
|
|
; Flash Pin Mux Configuration
|
|
GOSUB PINMUX_CONFIG
|
|
|
|
; ------------------------------------------------------------------------------
|
|
; Flash Controller Init
|
|
GOSUB Init_MMC
|
|
GOSUB READ_ID_TEST
|
|
|
|
; ------------------------------------------------------------------------------
|
|
; Flashfile declaration
|
|
FLASHFILE.RESet
|
|
|
|
//FLASHFILE.CONFIG <Cmd_reg>
|
|
FLASHFILE.CONFIG &MMC_BASE
|
|
|
|
//FLASHFILE.TARGET <Code_range> <Data_range> <Algorithm file>
|
|
FLASHFILE.TARGET 0x30000000++0x1FFF E:0x30002000++0x27FF ~~/demo/arm/flash/byte/emmcsd_stm32mp15x.bin /KEEP /DualPort
|
|
|
|
//Read FLASH Manufacture and Device ID
|
|
FLASHFILE.GETID
|
|
|
|
PER.Set.simple A:&MMC_BASE+0x04 %Long 0x00130001 ; clk increase
|
|
|
|
; Flash script ends here if called with parameter PREPAREONLY
|
|
IF ¶m_prepareonly
|
|
ENDDO PREPAREDONE
|
|
|
|
//FLASHFILE.ERASE 0x0--0xFFFFF ; Erase the flash 0x0--0xFFFFF
|
|
|
|
//FLASHFILE.LOAD * 0x0 ; Write a file to the flash
|
|
//FLASHFILE.LOAD * 0x0 /ComPare ; Verify
|
|
|
|
//for example) u-boot.img writing to sd card
|
|
//1 sector == 512Bytes
|
|
//FLASHFILE.LOAD ./sd_partition.bin 0x00000000 ; [sec_begin:sec_end]
|
|
//FLASHFILE.LOAD ./boot-spl.stm32 0x00004400 ; [34:545] 1:fsbl1
|
|
//FLASHFILE.LOAD ./boot-spl.stm32 0x00044400 ; [546:1057] 2:fsbl2
|
|
//FLASHFILE.LOAD ./u-boot.img 0x00084400 ; [1058:5153] 3:ssbl == uboot
|
|
|
|
FLASHFILE.DUMP 0x0 ; Read out from the flash
|
|
|
|
ENDDO
|
|
|
|
|
|
PINMUX_CONFIG:
|
|
(
|
|
|
|
//B PB8(AF11,SDMMC_CDIR)
|
|
PER.Set.simple A:0x50003000+0x00 %Long 0xAFFBFEAF ; GPIOx_MODER
|
|
PER.Set.simple A:0x50003000+0x0C %Long 0x50040140 ; GPIOx_PUPDR
|
|
PER.Set.simple A:0x50003000+0x20 %Long 0x00099800 ; GPIOx_AFRL[7:0]
|
|
PER.Set.simple A:0x50003000+0x24 %Long 0x990000B0 ; GPIOx_AFRH[15:8]
|
|
|
|
//C PC[7:12](AF8,AF12,AF12,AF12,AF12,AF12)
|
|
PER.Set.simple A:0x50004000+0x00 %Long 0xFEAABFFF ; GPIOx_MODER
|
|
PER.Set.simple A:0x50004000+0x0C %Long 0x00554000 ; GPIOx_PUPDR
|
|
PER.Set.simple A:0x50004000+0x20 %Long 0x80000000 ; GPIOx_AFRL[7:0]
|
|
PER.Set.simple A:0x50004000+0x24 %Long 0x000CCCCC ; GPIOx_AFRH[15:8]
|
|
|
|
//D D2(F12, pullDown)
|
|
PER.Set.simple A:0x50005000+0x00 %Long 0xFFFFFFAF ; GPIOx_MODER
|
|
PER.Set.simple A:0x50005000+0x0C %Long 0x00000040 ; GPIOx_PUPDR
|
|
PER.Set.simple A:0x50005000+0x20 %Long 0x00009C00 ; GPIOx_AFRL[7:0]
|
|
PER.Set.simple A:0x50005000+0x24 %Long 0x00000000 ; GPIOx_AFRH[15:8]
|
|
|
|
//E E4(AF8)
|
|
PER.Set.simple A:0x50006000+0x00 %Long 0xFFFFFABF ; GPIOx_MODER
|
|
PER.Set.simple A:0x50006000+0x0C %Long 0x00000540 ; GPIOx_PUPDR
|
|
PER.Set.simple A:0x50006000+0x20 %Long 0x00989000 ; GPIOx_AFRL[7:0]
|
|
PER.Set.simple A:0x50006000+0x24 %Long 0x00000000 ; GPIOx_AFRH[15:8]
|
|
|
|
//F F2(AF11)
|
|
PER.Set.simple A:0x50007000+0x00 %Long 0xDFFFFFEF ; GPIOx_MODER
|
|
PER.Set.simple A:0x50007000+0x0C %Long 0x00000010 ; GPIOx_PUPDR
|
|
PER.Set.simple A:0x50007000+0x20 %Long 0x00000B00 ; GPIOx_AFRL[7:0]
|
|
PER.Set.simple A:0x50007000+0x24 %Long 0x00000000 ; GPIOx_AFRH[15:8]
|
|
|
|
RETURN
|
|
)
|
|
|
|
Init_MMC:
|
|
(
|
|
|
|
//SDIO controller configuration
|
|
PER.Set.simple A:&MMC_BASE+0x00 %Long 0x13 ;power on
|
|
PER.Set.simple A:&MMC_BASE+0x24 %Long 0xFFFFFFFF
|
|
PER.Set.simple A:&MMC_BASE+0x28 %Long 0x200
|
|
PER.Set.simple A:&MMC_BASE+0x2C %Long 0x0 ;0x92
|
|
//SDMMC_CLKCR[21:20] == 01 : use the SDMMC_CKIN feedback ckock
|
|
PER.Set.simple A:&MMC_BASE+0x04 %Long 0x0013007B ; clk around 400Khz, sdmmc_ker_ck / [2 * CLKDIV].
|
|
|
|
RETURN
|
|
)
|
|
|
|
READ_ID_TEST:
|
|
(
|
|
//CMD0
|
|
RePeaT 2.
|
|
(
|
|
Data.Set &MMC_BASE+0x38 %Long 0x1FE00FFF ;clear status
|
|
Data.Set &MMC_BASE+0x8 %Long 0x0 ;arg
|
|
Data.Set &MMC_BASE+0xc %Long 0x1000 ;cmd
|
|
WAIT 10.ms
|
|
)
|
|
|
|
|
|
//CMD8, is madatory to intialize High Capacity SD Memory Card
|
|
RePeaT 2.
|
|
(
|
|
Data.Set &MMC_BASE+0x38 %Long 0x1FE00FFF ;clear status
|
|
Data.Set &MMC_BASE+0x8 %Long 0x1AA ;arg
|
|
Data.Set &MMC_BASE+0xc %Long 0x1108 ; (0x1<<12)|(0x1<<8)|0x08 ;cmd8
|
|
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+0x38 %Long 0x1FE00FFF ;clear status
|
|
Data.Set &MMC_BASE+0x8 %Long 0x0 ;arg
|
|
Data.Set &MMC_BASE+0xc %Long 0x1000
|
|
WAIT 10.ms
|
|
)
|
|
)
|
|
|
|
jump_cmd55:
|
|
//CMD55
|
|
RePeaT 10.
|
|
(
|
|
Data.Set &MMC_BASE+0x38 %Long 0x1FE00FFF ;clear status
|
|
Data.Set &MMC_BASE+0x8 %Long 0x0 ;arg
|
|
Data.Set &MMC_BASE+0xc %Long 0x1137 ; (0x1<<12)|(0x1<<8)|0x37 ;cmd55, resp1
|
|
WAIT 100.ms
|
|
|
|
//ACMD41
|
|
Data.Set &MMC_BASE+0x38 %Long 0x1FE00FFF ;clear status
|
|
Data.Set &MMC_BASE+0x8 %Long 0x40FF8000 ;0x40300000 ;arg , OCR
|
|
Data.Set &MMC_BASE+0xc %Long 0x1229 ; (0x1<<12)|(0x2<<8)|0x29 ;cmd41, resp1
|
|
WAIT 100.ms
|
|
|
|
&resp=Data.Long(A:(&MMC_BASE+0x14))
|
|
//print "CMD1 resp: 0x" &resp
|
|
IF (&resp&0x80000000)==0x80000000
|
|
(
|
|
GOTO jump_cmd2
|
|
)
|
|
)
|
|
|
|
PRINT "CMD1 fail"
|
|
END
|
|
|
|
jump_cmd2:
|
|
//CMD2
|
|
Data.Set &MMC_BASE+0x38 %Long 0x1FE00FFF ;clear status
|
|
Data.Set &MMC_BASE+0x8 %Long 0x0 ;arg
|
|
Data.Set &MMC_BASE+0xc %Long 0x1302; 0x0002|(0x3<<8)|(0x1<<12.) ;cmd2
|
|
WAIT 10.ms
|
|
|
|
//CMD3
|
|
Data.Set &MMC_BASE+0x38 %Long 0x1FE00FFF ;clear status
|
|
Data.Set &MMC_BASE+0x8 %Long 0x00010000 ; arg, MMC RCA is (0x0001<<16.)
|
|
Data.Set &MMC_BASE+0xc %Long 0x1103 ;0x003|(0x1<<8)|(0x1<<12.) ;cmd3
|
|
WAIT 10.ms
|
|
|
|
&cardaddress=Data.Long(A:(&MMC_BASE+0x14))
|
|
&cardaddress=&cardaddress&0xFFFF0000
|
|
|
|
//CMD10
|
|
Data.Set &MMC_BASE+0x30 %Long 0x1FE00FFF ;clear status
|
|
Data.Set &MMC_BASE+0x8 %Long &cardaddress ; arg, card address
|
|
Data.Set &MMC_BASE+0xc %Long 0x130A ;cmd10
|
|
WAIT 10.ms
|
|
|
|
//Response2
|
|
PRINT "CID register"
|
|
PRINT "[127:104] 0x" Data.Long(A:(&MMC_BASE+0x14))
|
|
PRINT "[103:72] 0x" Data.Long(A:(&MMC_BASE+0x18))
|
|
PRINT "[71:40] 0x" Data.Long(A:(&MMC_BASE+0x1C))
|
|
PRINT "[39:8] 0x" Data.Long(A:(&MMC_BASE+0x20))
|
|
|
|
RETURN
|
|
)
|
|
|
|
SDRAM_INIT:
|
|
RETURN
|