223 lines
7.0 KiB
Plaintext
223 lines
7.0 KiB
Plaintext
; --------------------------------------------------------------------------------
|
|
; @Title: eMMC Flash program Script for ST STM32MP157, Toshiba, THGBMNG5D1LBAIL
|
|
;
|
|
; @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
|
|
;
|
|
; eMMC pin configurations:
|
|
; SDMMC2_D0 -- PB14
|
|
; SDMMC2_D1 -- PB15
|
|
; SDMMC2_D2 -- PB3
|
|
; SDMMC2_D3 -- PB4
|
|
; SDMMC2_D4 -- PA8
|
|
; SDMMC2_D5 -- PA9
|
|
; SDMMC2_D6 -- PE5
|
|
; SDMMC2_D7 -- PD3
|
|
; SDMMC2_CK -- PE3
|
|
; SDMMC2_CMD -- PG6
|
|
;
|
|
; @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-emmc.cmm 12745 2023-11-17 08:43:11Z mschaeffner $
|
|
|
|
WinCLEAR
|
|
|
|
&MMC_BASE=0x58007000 ;SDMMC2
|
|
|
|
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<<17.) ; RCC_MP_AHB6ENSETR, FMCEN
|
|
Data.Set A:0x50000000+0x19C %LE %Long (0x1<<17.) ; RCC_AHB6RSTCLRR, FMCEN NAND controller reset
|
|
Data.Set A:0x50000000+0x198 %LE %Long Data.Long(A:(0x50000000+0x198))&~(0x1<<17.) ; RCC_AHB6RSTSER, release NAND memory controller reset
|
|
Data.Set A:0x50000000+0x398 %LE %Long (0x1<<17.) ; 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/emmc_stm32mp15x.bin /KEEP /DualPort
|
|
|
|
//Read FLASH Manufacture and Device ID
|
|
FLASHFILE.GETID
|
|
|
|
PER.Set.simple A:&MMC_BASE+0x04 %Long 0x00030001 ; clk increase
|
|
|
|
; Flash script ends here if called with parameter PREPAREONLY
|
|
IF ¶m_prepareonly
|
|
ENDDO PREPAREDONE
|
|
|
|
//When you access to the other partition on the flash
|
|
;FLASHFILE.SETEXTCSD 179. 0x00 ; access: partition null, no boot, access: no boot partition
|
|
;FLASHFILE.SETEXTCSD 179. 0x48 ; access: partition null
|
|
;FLASHFILE.SETEXTCSD 179. 0x49 ; access: partition boot 1
|
|
;FLASHFILE.SETEXTCSD 179. 0x4A ; access: partition boot 2
|
|
|
|
//FLASHFILE.ERASE 0x0--0xFFFFF ; Erase the flash 0x0--0xFFFFF
|
|
|
|
//FLASHFILE.LOAD * 0x0 ; Write a file to the flash
|
|
//FLASHFILE.LOAD * 0x0 /ComPare ; Verify
|
|
|
|
FLASHFILE.DUMP 0x0 ; Read out from the flash
|
|
|
|
ENDDO
|
|
|
|
|
|
PINMUX_CONFIG:
|
|
(
|
|
//A
|
|
PER.Set.simple A:0x50002000+0x00 %Long 0xC7FAFFFF ; GPIOx_MODER
|
|
PER.Set.simple A:0x50002000+0x0C %Long 0x00050000 ; GPIOx_PUPDR
|
|
PER.Set.simple A:0x50002000+0x20 %Long 0x00000000 ; GPIOx_AFRL[7:0]
|
|
PER.Set.simple A:0x50002000+0x24 %Long 0x000000A9 ; GPIOx_AFRH[15:8]
|
|
|
|
//B
|
|
PER.Set.simple A:0x50003000+0x00 %Long 0xAFFFFEAF ; GPIOx_MODER
|
|
PER.Set.simple A:0x50003000+0x0C %Long 0x50000140 ; GPIOx_PUPDR
|
|
PER.Set.simple A:0x50003000+0x20 %Long 0x00099800 ; GPIOx_AFRL[7:0]
|
|
PER.Set.simple A:0x50003000+0x24 %Long 0x99000000 ; GPIOx_AFRH[15:8]
|
|
|
|
//D
|
|
PER.Set.simple A:0x50005000+0x00 %Long 0xFFDFFFBF ; GPIOx_MODER
|
|
PER.Set.simple A:0x50005000+0x0C %Long 0x00000040 ; GPIOx_PUPDR
|
|
PER.Set.simple A:0x50005000+0x20 %Long 0x00009000 ; GPIOx_AFRL[7:0]
|
|
PER.Set.simple A:0x50005000+0x24 %Long 0x00000000 ; GPIOx_AFRH[15:8]
|
|
|
|
//E
|
|
PER.Set.simple A:0x50006000+0x00 %Long 0xFFFFFBBF ; GPIOx_MODER
|
|
PER.Set.simple A:0x50006000+0x0C %Long 0x00000440 ; GPIOx_PUPDR
|
|
PER.Set.simple A:0x50006000+0x20 %Long 0x00909000 ; GPIOx_AFRL[7:0]
|
|
PER.Set.simple A:0x50006000+0x24 %Long 0x00000000 ; GPIOx_AFRH[15:8]
|
|
|
|
//G
|
|
PER.Set.simple A:0x50008000+0x00 %Long 0xFFBFEFFF ; GPIOx_MODER
|
|
PER.Set.simple A:0x50008000+0x0C %Long 0x00001000 ; GPIOx_PUPDR
|
|
PER.Set.simple A:0x50008000+0x20 %Long 0x0A000000 ; GPIOx_AFRL[7:0]
|
|
PER.Set.simple A:0x50008000+0x24 %Long 0x00006000 ; 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
|
|
PER.Set.simple A:&MMC_BASE+0x04 %Long 0x0003007B ; 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
|
|
)
|
|
|
|
|
|
//CMD1
|
|
RePeaT 10.
|
|
(
|
|
Data.Set &MMC_BASE+0x38 %Long 0x1FE00FFF ;clear status
|
|
Data.Set &MMC_BASE+0x8 %Long 0x40FF8080 ;arg
|
|
Data.Set &MMC_BASE+0xc %Long 0x1201 ; (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
|
|
|
|
//CMD10
|
|
Data.Set &MMC_BASE+0x30 %Long 0x1FE00FFF ;clear status
|
|
Data.Set &MMC_BASE+0x8 %Long 0x010000 ; 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
|