; -------------------------------------------------------------------------------- ; @Title: R-CarV3M System Evaluation Board QSPI Flash script ; @Description: ; SPI FLASH Program script by the core (CR7) for the RCARV3M Evaluation ; The S25FL (Spansion, 256KB block non uniform) is on the SPI Multi I/O ; Bus controller ; ; Prerequisites: ; start description in here ; &sysup_script="~~/demo/arm/hardware// ; -cr7/-cr7_sieve_sram.cmm" ; ; * activate QSPI0 flash ; SW5 = 3 pin SPI-FLASH or EX-SPI ; SW6 = 1 pin SPI-FLASH ; SW7 = all ON ; ; SRAM: 0xE6328000 ; SPI Multi I/O Bus(controller) Base: 0xEE200000 ; ; @Keywords: ARM, Cortex-R7, Spansion Flash SPI RCarV3M ; @Author: jjeong ; @Board: Y-R-CAR-V3H-BOARD-DEV-ES10 (Eagle) ; @Chip: R8A77970-CR7 ; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only ; -------------------------------------------------------------------------------- ; $Id: rcarv3m-cr7-spi.cmm 12742 2023-11-17 08:05:09Z mschaeffner $ PRIVATE ¶meters ENTRY %LINE ¶meters PRIVATE ¶m_prepareonly ¶meters=STRing.UPpeR("¶meters") ¶m_prepareonly=(STRing.SCAN("¶meters","PREPAREONLY",0)!=-1) &SPI_BASE=0xEE200000 ; ------------------------------------------------------------------------------ ; Setup CPU RESet SYStem.RESet SYStem.CPU R8A77970-CR7 SYStem.MemAccess DAP SYStem.JtagClock CTCK 10MHz Trace.DISable SYStem.Up ; -------------------------------------------------------------------------------- ; enable the SRAM & MPU - alternative execute BootROM e.g. Go/Wait/Break IF TRUE() ( ; enable SRAM Data.Set AD:0xE67F0018 %LE %Long 0x1 ; disable MPU Data.Set C15:0x1 %Long 0xC50078 ; disable all regions PRIVATE &i &i=0 RePeaT 16. ( ; set MRNR Data.Set C15:0x26 %Long &i ; clear RSER Data.Set C15:0x216 %Long 0x0 &i=&i+1. ) ; setup regions for simplicity only region 0&1 ; region 0: 0x00000000--0xffffffff - Shareable Device - all permissions Data.Set C15:0x026 %Long 0x0 Data.Set C15:0x016 %Long 0x0 Data.Set C15:0x216 %Long 0x3f Data.Set C15:0x416 %Long 0x305 ; region 1: 0xe6300000--0xe637ffff - non-cacheable - all permissions Data.Set C15:0x026 %Long 0x1 Data.Set C15:0x016 %Long 0xe6300000 Data.Set C15:0x216 %Long 0x25 Data.Set C15:0x416 %Long 0x30c ; enable MPU Data.Set C15:0x1 %Long Data.Long(C15:0x1)|0x1 ) ELSE ( Go.direct 0x268 WAIT !STATE.RUN() 0.2s IF STATE.RUN() Break.direct ) ; ------------------------------------------------------------------------------ ; Flash Controller Power & Clock Enable ; ------------------------------------------------------------------------------ ; Flash Pin Mux Configuration ; ------------------------------------------------------------------------------ ; Flash Controller Init Data.Set A:&SPI_BASE %LE %Long 0x01fff300 ;enable RPC AHB read Data.Set A:&SPI_BASE+0x010 %LE %Long (0x13<<16.) ;DRCMR, read 4byte address mode command Data.Set A:&SPI_BASE+0x01C %LE %Long 0x4F00 ;DRENR, 32bit address mode, (24bit==0x4700) Data.Set A:&SPI_BASE+0x014 %LE %Long 0x1 ;DREAR, 32bit Extended External Address Valid Range, A[25:0] enabled ; ------------------------------------------------------------------------------ ; Flash Read ID Test GOSUB READ_ID_TEST ; ------------------------------------------------------------------------------ ; Init SRAM (16KB) for the flash algorithm ; ------------------------------------------------------------------------------ ; Flash declaration Break.RESet FLASH.RESet FLASH.Create 0x08000000++0x7FFF 0x01000 TARGET Byte FLASH.Create 0x08008000++0x37FFF 0x38000 TARGET Byte FLASH.Create 0x08040000--0xBFFFFFF 0x40000 TARGET Byte FLASH.TARGET 0xE6328000 0xE632A000 0x2000 ~~/demo/arm/flash/byte/snor_rcar3.bin ; Flash script ends here if called with parameter PREPAREONLY IF ¶m_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 * 0x08000000 FLASH.ReProgram.off ; Reset device PRINT "Please power-cycle the board after flash program is complete" ) ENDDO ; -------------------------------------------------------------------------------- READ_ID_TEST: ( &CMNCR=(&SPI_BASE) &SMCR=(&SPI_BASE+0x20) ; SMCR_0 , SPI mode control &SMCMR=(&SPI_BASE+0x24) ; SMCMR_0 , SPI mode command setting register &SMADR=(&SPI_BASE+0x28) ;address &SMOPR=(&SPI_BASE+0x2C) ;option data setting &SMENR=(&SPI_BASE+0x30) ;enable setting &SMRDR=(&SPI_BASE+0x38) &SMRDR1=(&SPI_BASE+0x3C) &SMWDR=(&SPI_BASE+0x40) &SMWDR1=(&SPI_BASE+0x44) &SMDMCR=(&SPI_BASE+0x60) ;dummy cycle ®Data=Data.Long(A:&CMNCR) Data.Set A:&CMNCR %Long 0x80000000|®Data ;enable manual mode, disable AHB read Data.Set A:&SMCMR %Long (0x9f<<16.) ;read-id cmd Data.Set A:&SMADR %Long 0x0 ;address 0x0 Data.Set A:&SMOPR %Long 0x0 ;address 0x0 ;Data.Set A:&SMDMCR %l 0x7 ; dummy 8 cycle number &smenr=(0x1<<14.)|0xF; cmd enable, 4byte data read Data.Set A:&SMENR %Long &smenr //start spi transfer &smcr=0x1|(0x2<<1.) ; spie and spire , SPI Read data Data.Set A:&SMWDR %LE %Long 0x00000000 ; write Tx buffer init Data.Set A:&SMCR %Long &smcr &read_data=Data.Long(A:&SMRDR) 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:&CMNCR %Long ®Data ;disable manual mode, enable AHB read RETURN )