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

179 lines
5.9 KiB
Plaintext

; --------------------------------------------------------------------------------
; @Title: NAND Flash program Script for STM32MP157, MT29F8G08ABACAH4
;
; @Description:
; Devices:
; * NAND Flash program Script for ST STM32MP157 and
; * NAND flash (MT29F8G08ABACAH4, MICRON, 4096+224, block==64pages)
;
; Script arguments:
;
; DO stm32mp157-nand [PREPAREONLY]
;
; PREPAREONLY only declares flash but does not execute flash programming
;
; Example:
;
; DO ~~/demo/arm/flash/stm32mp157-nand.cmm PREPAREONLY
;
; 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
;
; @Keywords: ARM, Cortex-A7, NAND
; @Author: JIM
; @Board: STM32MP15X-EVAL
; @Chip: STM32MP157A-CA7
; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: stm32mp157-nand.cmm 12941 2024-01-16 06:17:32Z jjeong $
WinCLEAR
&FMC_BASE=0x58002000
PRIVATE &parameters
ENTRY %LINE &parameters
PRIVATE &param_prepareonly &param_cpu &param_dualport
&param_prepareonly=(STRing.SCAN(STRing.UPpeR("&parameters"),"PREPAREONLY",0)!=-1)
&param_cpu=STRing.SCANAndExtract(STRing.UPpeR("&parameters"),"CPU=","")
&param_dualport=STRing.SCANAndExtract(STRing.UPpeR("&parameters"),"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
; ------------------------------------------------------------------------------
; Flash Power & Clock Enable
Data.Set A:0x50000000+0x218 %LE %Long (0x1<<12.) ; RCC_MP_AHB6ENSETR, FMCEN
Data.Set A:0x50000000+0x19C %LE %Long (0x1<<12.) ; RCC_AHB6RSTCLRR, FMCEN NAND controller reset
Data.Set A:0x50000000+0x198 %LE %Long Data.Long(A:(0x50000000+0x198))&~(0x1<<12.) ; RCC_AHB6RSTSER, release NAND memory controller reset
Data.Set A:0x50000000+0x318 %LE %Long (0x1<<12.) ; RCC_AHB6LPENSETR, NAND memory controller clock enable during Sleep mode
Data.Set A:0x50000000+0xA28 %LE %Long 0x58 ;GPIO D(3) & E(4) & G(6) clk enable
; ------------------------------------------------------------------------------
; Flash Pin Mux Configuration
GOSUB PINMUX_CONFIG
; ------------------------------------------------------------------------------
; Flash Controller Init
PER.Set.simple A:&FMC_BASE+0x00 %Long 0x800030DB ;BCR1
PER.Set.simple A:&FMC_BASE+0x04 %Long 0x0FFFFFFF ;BTR1
PER.Set.simple A:&FMC_BASE+0x80 %Long 0x0102CB4E ;PCR
PER.Set.simple A:&FMC_BASE+0x88 %Long 0x01080E06 ;PMEM
PER.Set.simple A:&FMC_BASE+0x8C %Long 0x01330E2E ;PATT
GOSUB READ_ID_TEST
; ------------------------------------------------------------------------------
; Flashfile declaration
FLASHFILE.RESet
//FLASHFILE.CONFIG <Cmd_reg> <Addr_reg> <Data_reg>
FLASHFILE.CONFIG 0x80010000 0x80020000 0x80000000
//FLASHFILE.TARGET <Code_range> <Data_range> <Algorithm file>
// MT29F8G08ABACAH4 == 4096+224 64page
FLASHFILE.TARGET 0x30000000++0x1FFF E:0x30002000++0x27FF ~~/demo/arm/flash/byte/nand8g08xs224.bin /KEEP /DualPort
//Read FLASH Manufacture and Device ID
FLASHFILE.GETID
//Read FLASH ONFI, you can verify your nand flash spec & page_size & block_size
;FLASHFILE.GETONFI /VM
; Flash script ends here if called with parameter PREPAREONLY
IF &param_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
FLASHFILE.DUMP 0x0 ; Read out from the flash
ENDDO
PINMUX_CONFIG:
(
//pin mux, please refer the STM32MP1 alternate function mapping (Pinouts and pin description)
;CE# <-> GPIOG[9] en ALT 12, (NAND_NCE)
;CLE <-> GPIOD[11] en ALT 12, (NAND_CLE)
;ALE <-> GPIOD[12] en ALT 12, (NAND_ALE)
;RE# <-> GPIOD[4] en ALT 12, (NAND_NOE)
;WE# <-> GPIOD[5] en ALT 12, (NAND_NWE)
;RB# <-> GPIOD[6] en ALT 12, (NAND_NWAIT, R/B)
;IO0 <-> GPIOD[14] en ALT 12, (NAND_D0)
;IO1 <-> GPIOD[15] en ALT 12, (NAND_D1)
;IO2 <-> GPIOD[0] en ALT 12, (NAND_D2)
;IO3 <-> GPIOD[1] en ALT 12, (NAND_D3)
;IO4 <-> GPIOE[7] en ALT 12, (NAND_D4)
;IO5 <-> GPIOE[8] en ALT 12, (NAND_D5)
;IO6 <-> GPIOE[9] en ALT 12, (NAND_D6)
;IO7 <-> GPIOE[10] en ALT 12, (NAND_D7)
//D[15...0]
PER.Set.simple A:0x50005000+0x00 %Long 0xAEBFEAFA ; GPIOx_MODER
PER.Set.simple A:0x50005000+0x0C %Long 0x50001005 ; GPIOx_PUPDR
PER.Set.simple A:0x50005000+0x20 %Long 0x0CCC00CC ; GPIOx_AFRL[7:0]
PER.Set.simple A:0x50005000+0x24 %Long 0xCC0CC000 ; GPIOx_AFRH[15:8]
//E[10:7]
PER.Set.simple A:0x50006000+0x00 %Long 0xFFEABFFF
PER.Set.simple A:0x50006000+0x0C %Long 0x00154000
PER.Set.simple A:0x50006000+0x20 %Long 0xC0000000
PER.Set.simple A:0x50006000+0x24 %Long 0x00000CCC
//G[9]
PER.Set.simple ANSD:0x50008000+0x00 %Long 0xFFBBFFFF
PER.Set.simple ANSD:0x50008000+0x0C %Long 0x00000000
PER.Set.simple ANSD:0x50008000+0x20 %Long 0x00000000
PER.Set.simple ANSD:0x50008000+0x24 %Long 0x000000C0
RETURN
)
READ_ID_TEST:
(
&NAND_BASE=0x80000000
&NAND_ALE =0x80020000
&NAND_CLE =0x80010000
Data.Set &NAND_CLE %Byte 0x90 ;command reg
WAIT 100.ms
Data.Set &NAND_ALE %Byte 0x00 ; addr reg
WAIT 100.ms
PRINT "read 1st : 0x" Data.Byte(A:&NAND_BASE) " (Manufacture ID)"
PRINT "read 2nd : 0x" Data.Byte(A:&NAND_BASE) " (Device ID)"
PRINT "read 3rd : 0x" Data.Byte(A:&NAND_BASE)
PRINT "read 4th : 0x" Data.Byte(A:&NAND_BASE)
PRINT "read 5th : 0x" Data.Byte(A:&NAND_BASE)
PRINT "read 6th : 0x" Data.Byte(A:&NAND_BASE)
//clear controller flags
PER.Set.simple A:&FMC_BASE+0x0228 %Long -1 ; clear
PER.Set.simple A:&FMC_BASE+0x0220 %Long -1 ;enable
RETURN
)