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

203 lines
6.6 KiB
Plaintext

; --------------------------------------------------------------------------------
; @Title: Renesas RZ/T2M QSPI,OSPI Flash script
; @Description:
; The MX25UR51245GMI00 is on the xSPI controller
;
; MX25UR51245GMI00(QSPI 0xC2, 0x35, 0x1A), MX25UW51245G (OSPI, 0xC2, 0x81, 0x3A)
;
; XSPI0_IO7 -- P15_6
; XSPI0_IO6 -- P15_5
; XSPI0_IO5 -- P15_4
; XSPI0_IO4 -- P15_3
; XSPI0_IO3 -- P15_2
; XSPI0_IO2 -- P15_1
; XSPI0_IO1 -- P15_0
; XSPI0_IO0 -- P14_7
;
; XSPI0_RESET -- P16_1
; XSPI0_CS -- P15_7
; XSPI0_DQS -- P14_4
; XSPI0_SCLK -- P14_6
; XSPI0_ECS -- P14_2
;
; SRAM: 0x20000
; xSPI Controller Base: 0x80220000
; xSPI AHB: 0x60000000
;
; @Keywords: ARM, Cortex-R52
; @Author: jjeong
; @Board:
; @Chip: RZT2M
; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: rzt2m-cr52-spi.cmm 12743 2023-11-17 08:11:30Z mschaeffner $
PRIVATE &parameters
ENTRY %LINE &parameters
PRIVATE &param_prepareonly
&parameters=STRing.UPpeR("&parameters")
&param_prepareonly=(STRing.SCAN("&parameters","PREPAREONLY",0)!=-1)
&SPI_BASE=0x80220000
&flashsize=0x1000000 ; 16MByte , 0x2000000 :32MB
&WS2=0 ; not WS2.x LSI
; --------------------------------------------------------------------------------
; Initialize and start the debugger
RESet
SYStem.RESet
SYStem.CPU RZT2M
CORE.ASSIGN 1.
SYStem.MemAccess DAP
SYStem.JtagClock 10MHz
;SYStem.CONFIG.DEBUGPORTTYPE SWD
SYStem.Option.TRST OFF
SYStem.Option.ResBreak OFF
SYStem.Option.WaitCTIREG ON
SYStem.Option.SLaVeSOFTRESet ON
SYStem.Option.MemStatusCheck ON ; to access SPI AHB without bus error because of the slower bus
SYStem.Up
; ------------------------------------------------------------------------------
; Flash Controller Power & Clock Enable
GOSUB CLK_INIT
; ------------------------------------------------------------------------------
; Flash Pin Mux Configuration
GOSUB IOMUX_INIT
; ------------------------------------------------------------------------------
; Flash Controller Init
GOSUB xSPI_INIT
; ------------------------------------------------------------------------------
; Flash Read ID Test
GOSUB READ_ID_TEST
; ------------------------------------------------------------------------------
; Init SRAM (16KB) for the flash algorithm
Data.Test 0x20000++0x3FFF
; ------------------------------------------------------------------------------
; Flash declaration
FLASH.RESet
FLASH.Create 0x60000000++(&flashsize-1) 0x10000 TARGET Byte
FLASH.TARGET A:0x20000 A:0x22000 0x2000 ~~/demo/arm/flash/byte/snor3b_rzt2m.bin
IF &flashsize>0x1000000 ;4Byte Address mode
(
FLASH.RESet
FLASH.Create 0x60000000++(&flashsize-1) 0x10000 TARGET Byte
FLASH.TARGET A:0x20000 A:0x22000 0x2000 ~~/demo/arm/flash/byte/snor_rzt2m.bin
)
; Flash script ends here if called with parameter PREPAREONLY
IF &param_prepareonly
ENDDO PREPAREDONE
; ------------------------------------------------------------------------------
; Flash programming example
DIALOG.YESNO "Program flash memory?"
LOCAL &progflash
ENTRY &progflash
IF &progflash
(
FLASH.ReProgram.ALL
Data.LOAD.auto *
;Data.LOAD.Binary * 0x60000000
FLASH.ReProgram.off
; Reset device
PRINT "Please power-cycle the board after flash program is complete"
)
ENDDO
; --------------------------------------------------------------------------------
IOMUX_INIT:
(
Data.Set A:0x80281000+0xA10 %LE %Long 0xa504 ;Non-Safety Area Protect Register (PRCRN)
Data.Set A:0x81281000+0xA00 %LE %Long 0xa504 ;Safety Area Protect Register (PRCRS)
Data.Set A:0x81030200+0x01C %LE %Long 0x00000404 ;PORT 14/15 Mode register
Data.Set A:0x81030200+0x020 %LE %Long 0x00010000 ;PORT 16/17 Mode register
Data.Set A:0x81030400+0x00C %LE %Long 0x87D41BFF ;PORT 12/13/14/15 Control Register
Data.Set A:0x81030400+0x010 %LE %Long 0x01F1A062 ;PORT 16/17/18/19 Control Register
Data.Set A:0x81030000+0x638 %LE %Long 0x100 ;PORT 14 Function Control Register
Data.Set A:0x81030000+0x63C %LE %Long 0x0 ;PORT 15 Function Control Register
Data.Set A:0x81030000+0x640 %LE %Long 0x02100000 ;PORT 16 Function Control Register
RETURN
)
//BSP Clock reset...
CLK_INIT:
(
RETURN
)
xSPI_INIT:
(
;release/unlock the xSPI controller
Data.Set A:0x80281000+0xA10 %LE %Long 0xa502 ;Write Enable for Non-Safety Area Protect Register (PRCRN)
Data.Set A:0x81281000+0xA00 %LE %Long 0xa502 ;Safety Area Protect Register (PRCRS)
Data.Set A:0x80280000+0x300 %LE %Long Data.Long(A:0x80280300)&~0x30 ;MSTPCRA module stop control register for xSPI0& xSPI1
//xSPI0
Data.Set A:&SPI_BASE+0x00 %LE %Long 0x0 ;WRAPCFG
//3Byte address mode, SPI flash is larger than 16MB
Data.Set A:&SPI_BASE+0x10 %LE %Long 0x8 ; 0x8: 3Byte Address ;CMCFG0
Data.Set A:&SPI_BASE+0x14 %LE %Long 0x0300 ; read command : 0x0300, 0x6EB00 for opi mode with 6 dummy cycles
IF &flashsize>0x1000000 ;4Byte Address mode
(
Data.Set A:&SPI_BASE+0x10 %LE %Long 0xC ; 0xC: 4Bytes address range ;CMCFG0
Data.Set A:&SPI_BASE+0x14 %LE %Long 0x1300 ; read command : 0x1300, 0x6EB00 for opi mode with 6 dummy cycles
)
Data.Set A:&SPI_BASE+0x18 %LE %Long 0x200 ; CMCFG2
Data.Set A:&SPI_BASE+0x60 %LE %Long 0xFF ; BMCTL0
Data.Set A:&SPI_BASE+0x08 %LE %Long 0x00 ; BMCFG
Data.Set A:&SPI_BASE+0x50 %LE %Long 0x70000 ; b[9:0] 1S-1S-1S protocol
IF &WS2==1 ;//WS2.x LSI
(
Data.Set A:&SPI_BASE+0x50 %LE %Long 0x70000|(0x1<<24.); b[9:0] 1S-1S-1S protocol, SDR_SMP_SFT[27:24]
)
Data.Set A:&SPI_BASE+0x6C %LE %Long 0x3F ; 64MB for CS0, CS0_Size[5:0], CS1_Size[13:8]
Data.Set A:&SPI_BASE+0x70 %LE %Long 0x00 ;CSSEL
RETURN
)
READ_ID_TEST:
(
;xSPI Command Manual Type Buf n (CDTBUFn), A:&SPI_BASE+0x80
;cmdsize[1:0] //0: none, 1~nBytes
;addsize[4:2] //0: none, 1~nBytes
;datasize[8:5] //0: none, 1: 1bytes ~ 8bytes
;latency[13:9] //min 0 - max 31 cycles
;read/write[15] //0:read data, 1: write data
;cmd[31:16] //[31:24]cmd0 , [23:16] cmd1
Data.Set A:&SPI_BASE+0x80 %Long 0x9F000081 ;cmd, direction, dummy cycles CDT ,data_length
Data.Set A:&SPI_BASE+0x84 %Long 0x00 ; address, CDA
Data.Set A:&SPI_BASE+0x70 %Long 0x01 ; CDCTL0, b[0]:TRREQ, transaction request
WAIT (Data.Long(A:&SPI_BASE+0x0190)&0x1)==0x1 ; wait until b0 == 0x1, Command Completed
&read_data=Data.Long(A:&SPI_BASE+0x88)
PRINT "Read 1st: 0x" (&read_data)&0xFF " (Manufacturer) "
PRINT "Read 2nd: 0x" (&read_data>>8.)&0xFF " (Device) "
PRINT "Read 3rd: 0x" (&read_data>>16.)&0xFF
PRINT "Read 4th: 0x" (&read_data>>24.)&0xFF
Data.Set A:&SPI_BASE+0x194 %Long 0x01 ; Clear status
GOSUB xSPI_INIT
RETURN
)