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

199 lines
6.1 KiB
Plaintext

; --------------------------------------------------------------------------------
; @Title: Memory mapped Quad SPI Flash program Script for STM32MP157, MX25L512
;
; @Description:
; Devices:
; * ST STM32MP157
; * QSPI flash (MX25L512, MACRONIX)
; Script arguments:
;
; DO stm32mp157-qspi [PREPAREONLY] [CPU=<cpu>] [DUALPORT=0|1]
;
; PREPAREONLY only declares flash but does not execute flash programming
;
; CPU=<cpu> selects CPU derivative <cpu>
;
; DUALPORT=0|1 default value is 0 (disabled).
;
; Example:
;
; DO ~~/demo/arm/flash/stm32mp157-qspi.cmm PREPAREONLY DUALPORT=1
;
; @Keywords: ARM, Cortex-A7
; @Author: JIM
; @Board: STM32MP15X-EVAL
; @Chip: STM32MP157A-CA7
; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: stm32mp157-qspi.cmm 12746 2023-11-17 09:17:02Z mschaeffner $
&QSPI_BASE=0x58003000
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.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<<14.) ; RCC_AHB3ENR, Quad SPI memory controller clock enable
Data.Set A:0x50000000+0x19C %LE %Long (0x1<<14.) ; RCC_AHB6RSTCLRR, Quad SPI memory controller reset
Data.Set A:0x50000000+0x198 %LE %Long data.long(A:(0x50000000+0x198))&~(0x1<<14.) ; RCC_AHB6RSTSER, release Quad SPI memory controller reset
Data.Set A:0x50000000+0x318 %LE %Long (0x1<<14.) ; RCC_AHB6LPENSETR, QUADSPI memory controller clock enable during Sleep mode
Data.Set A:0x50000000+0xA28 %LE %Long (0x1<<1.)|(0x1<<5.) ;GPIOB & GPIOF clk enable
; ------------------------------------------------------------------------------
; Flash Pin Mux Configuration
GOSUB PINMUX_CONFIG
; ------------------------------------------------------------------------------
; Flash Controller Init
Data.Set A:&QSPI_BASE+0x00 %Long 0x04000311 ; QUADSPI_CR, QUADSPI control register, enable clk and prescaler (/4)
Data.Set A:&QSPI_BASE+0x04 %Long 0x00190100 ; QUADSPI_DCR, flash size 2^26 (64MBytes), 0x00170100==16Mbytes
Data.Set A:&QSPI_BASE+0x0C %Long 0xFF ; QUADSPI_FCR, QUADSPI flag clear register
//EXIT QUAD INPUT/OUTPUT MODE(QPI), to make the single spi mode
//Only for MACRONIX & MICRON SPI flash memories
GOSUB WRITEBYTE_QPI 0xF5
GOSUB READ_ID_TEST
//switch QSPI to the memory mapped mode
Data.Set A:&QSPI_BASE %Long (Data.Long(A:&QSPI_BASE)&~0x1) ;disable
Data.Set A:&QSPI_BASE+0x14 %Long 0x0D003513 ; FMODE, READ cmd(0x13), ADSize 32b and so on...
Data.Set A:&QSPI_BASE %Long (Data.Long(A:&QSPI_BASE)|0x1) ;enable
; ------------------------------------------------------------------------------
; Flash declaration
GOSUB FlashDeclaration "&param_dualport"
; 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 *
FLASH.ReProgram.off
; Reset device
SYStem.Down
SYStem.Up
)
ENDDO
READ_ID_TEST:
(
&QSPI_FCR=&QSPI_BASE+0xC
&QSPI_CCR=&QSPI_BASE+0x14
&QSPI_DLR=&QSPI_BASE+0x10
&QSPI_DR=&QSPI_BASE+0x20
Data.Set A:&QSPI_FCR %LE %Long 0x1F ;clear status
// 1 instruction , 4 read data
Data.Set A:&QSPI_DLR %Long 0x3 ; 4byte data read
&ccr=0x19F ; imode with insturction 1byte instruction write (1: 1 instruction line)
&ccr=&ccr|(0x1<<24.) ; dmode single
&ccr=&ccr|(0x1<<26.) ; indirect read mode
Data.Set A:&QSPI_CCR %LE %Long &ccr
&read_data=Data.Long(A:&QSPI_DR) ;read little endian
PRINT "1st 0x" &read_data&0xFF " (Manufacturer)"
PRINT "2nd 0x" (&read_data>>8.)&0xFF " (Device ID)"
PRINT "3rd 0x" (&read_data>>16.)&0xFF
PRINT "4th 0x" (&read_data>>24.)&0xFF
RETURN
)
WRITEBYTE_QPI:
(
ENTRY &wdata
SCREEN.OFF
Data.Set A:(&QSPI_BASE+0xC) %LE %Long 0x1F ;clear status
&ccr=(0x3<<8)|&wdata ; imode with insturction 1byte instruction write (3: 4 instruction lines)
Data.Set A:(&QSPI_BASE+0x14) %LE %Long &ccr
SCREEN.ON
RETURN
)
; Flash declaration
FlashDeclaration:
(
PRIVATE &FlashSize &FlashDriver &FlashBaseAddr
PARAMETERS &DualPort
FLASH.RES
&FlashDriver="snor_stm32mp157.bin"
&FlashSize=0x4000000 ;64Mbytes
&FlashBaseAddr=0x70000000 ;SPI AHB base address
FLASH.Create 2. &FlashBaseAddr++(&FlashSize-0x1) 0x10000 TARGET2 Byte
IF "&DualPort"=="0"
FLASH.TARGET2 0x30000000 0x30002000 0x4000 ~~/demo/arm/flash/byte/&FlashDriver
ELSE
FLASH.TARGET2 0x30000000 E:0x30002000 0x4000 ~~/demo/arm/flash/byte/&FlashDriver /DualPort
FLASH.List
RETURN
)
PINMUX_CONFIG:
(
//pin mux, please refer the STM32MP1 alternate function mapping (Pinouts and pin description)
;S# <-> GPIOB[6] en ALT 10, (QUADSPI_BK1_NCS)
;CLK <-> GPIOF[10] en ALT 9, (QUADSPI_CLK)
;DQ0 <-> GPIOF[8] en ALT 10, (QUADSPI_BK1_IO0)
;DQ1 <-> GPIOF[9] en ALT 10, (QUADSPI_BK1_IO1)
;DQ2 <-> GPIOF[7] en ALT 9, (QUADSPI_BK1_IO2)
;DQ3 <-> GPIOF[6] en ALT 9. (QUADSPI_BK1_IO3)
Data.Set A:0x50003000+0x00 %LE %Long (0x2<<12.) ;GPIOB_MODER, PB[6] alternate function mode
Data.Set A:0x50003000+0x20 %LE %Long (0xA<<24.) ;GPIOB[7:0], PB[6] alt 10
Data.Set A:0x50003000+0x24 %LE %Long 0x0 ;GPIOB[15:8]
Data.Set A:0x50007000+0x00 %LE %Long (0x2AA<<12.) ;GPIOF_MODER, PF[10:6] alternate function mode
Data.Set A:0x50007000+0x20 %LE %Long (0x99<<24.) ;GPIOF[7:0], PF[7:6] alt 9
Data.Set A:0x50007000+0x24 %LE %Long (0x9AA) ;GPIOF[15:8], PF[10] alt 9, PF[9:8] alt 10
)
RETURN