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

277 lines
8.2 KiB
Plaintext

; --------------------------------------------------------------------------------
; @Title: Flash declaration for ST STM32U5 internal flash
; @Description:
; Script arguments:
; DO stm32u5 [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> use dual port memory access, default 1
; Example:
; DO ~~/demo/arm/flash/stm32u5 PREPAREONLY
; Note:
; This file must NOT be modified.
; This file is intended to stay within TRACE32 installation.
; Usage examples are available in the ~~/demo/arm/hardware/... subdirectories.
;
; List of STM32U5 derivatives and their configuration:
; CPU-Type SRAM1-3
; [byte]
; --------------------------------------------------------------------------------
; STM32U535xy 0x040000 x=C,N,R,J,V y=B,C,E
; STM32U545xy 0x040000 x=C,N,R,J,V y=B,C,E
; STM32U575xy 0x0C0000 x=C,R,O,V,Q,Z,A y=G,I
; STM32U585xy 0x0C0000 x=C,R,O,V,Q,Z,A y=G,I
; STM32U595xy 0x270000 x=R,V,Q,Z,A y=I,J
; STM32U5A5xy 0x270000 x=R,V,Q,Z,A y=I,J
; STM32U599xy 0x270000 x=V,Z,B,N* y=I,J
; STM32U5A9xy 0x270000 x=V,Z,B,N* y=I,J
;
; x indicates the package footprint (number and layout of pins)
; * - N for the 535/545 is different than for the 599/5A9: WLCSP-56 vs TFBGA-216
;
; y Flash
; [byte]
; --------------------------------------------------------------------------------
; B 0x020000
; C 0x040000
; E 0x080000
; G 0x100000
; I 0x200000
; J 0x400000
;
; Flash unsecured : 0x08000000--<end addr>
; Flash secured : 0x0C000000--<end addr>
; SRAM1-3 : 0x20000000--<end addr>
; SRAM4 : 0x28000000--0x28003FFF
;
; @Chip: STM32U5*
; @Author: PHI
; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Rev: 13355 $
; $Id: stm32u5.cmm 13355 2024-04-19 17:04:35Z bwright $
PRIVATE &parameters
ENTRY %LINE &parameters
PRIVATE &param_prepareonly &param_cpu &param_dualport
&parameters=STRing.UPpeR("&parameters")
&param_prepareonly=(STRing.SCAN("&parameters","PREPAREONLY",0)!=-1)
&param_cpu=STRing.SCANAndExtract("&parameters","CPU=","")
&param_dualport=STRing.SCANAndExtract("&parameters","DUALPORT=","0")
; --------------------------------------------------------------------------------
; Initialize and start the debugger
IF !SYStem.Up()
(
SYStem.RESet
IF "&param_cpu"!=""
SYStem.CPU &param_cpu
IF !CPUIS(STM32U5*)
SYStem.CPU STM32U5*
SYStem.MemAccess DAP
IF CABLE.TWOWIRE()
SYStem.CONFIG DEBUGPORTTYPE SWD
ELSE
SYStem.CONFIG DEBUGPORTTYPE JTAG
SYStem.Up
)
; --------------------------------------------------------------------------------
; Flash declaration
FLASH.RESet
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?"
PRIVATE &progflash
ENTRY &progflash
IF &progflash
(
FLASH.ReProgram ALL /Erase
Data.LOAD.auto *
FLASH.ReProgram OFF
; Reset device
SYStem.Down
SYStem.Up
)
ENDDO
; --------------------------------------------------------------------------------
; SUBROUTINES
; --------------------------------------------------------------------------------
; Flash declaration depending on selected CPU
;
; Please do NOT modify the TRACE32 flash declaration.
;
; Modifications can result in unpredictable behavior.
; Please contact support@lauterbach.com for any changes.
FlashDeclaration: ;(param_dualport)
(
PARAMETERS &param_dualport
PRIVATE &FlashDriver
PRIVATE &tzen &secure_allowed &FlashStart &SecureFlashStart &RamStart &SecuredRamStart &sectorsize
PRIVATE &offset &size &DeclaredSize
IF CPUIS(STM32U5*)
(
&FlashDriver="stm32u5_512k.bin"
)
&FlashStart=0x08000000
&SecureFlashStart=0x0c000000
&RamStart=0x20000000
&SecuredRamStart=0x30000000
&sectorsize=0x2000
&tzen=FALSE()
&secure_allowed=FALSE()
IF CPUIS(STM32U5???B)
&FlashSize=0x20000
ELSE IF CPUIS(STM32U5???C)
&FlashSize=0x40000
ELSE IF CPUIS(STM32U5???E)
&FlashSize=0x80000
ELSE IF CPUIS(STM32U5???G)
(
&FlashDriver="stm32u5_1m.bin"
&FlashSize=0x100000
)
ELSE IF CPUIS(STM32U5???I)
(
&FlashDriver="stm32u5_2m.bin"
&FlashSize=0x200000
)
ELSE IF CPUIS(STM32U5???J)
(
&FlashDriver="stm32u5_4m.bin"
&FlashSize=0x400000
)
ELSE
(
PRINT %ERROR "Unexpected flash size designator. Try manually entering flash size or contact support."
ENDDO
)
ON ERROR CONTinue
(
&tzen=(Data.Long(ZD:0x40022040)&0x80000000)==0x80000000
&secure_allowed=(Data.Long(ZD:0x40022040)&0x000000ff)==0x000000aa ; Check read protection level
)
ON ERROR DEFault
IF (&tzen&&!&secure_allowed)
(
&error=FALSE()
; Take initial stackpointer of the vector table as reference for available SRAM
&RamStart=(Data.Long(D:(Data.Long(D:0xE000ED08)))-1)&0xFFFFC000
ON ERROR GOSUB
(
&error=TRUE()
RETURN
)
Data.Test &RamStart++0x3fff
IF FOUND()||(&error)
(
PRINT %ERROR "Found non-secure SRAM space to small for flash algorithm"
ENDDO
)
)
; Flash declaration, if Trustzone is not activated
IF !&tzen
(
FLASH.Create 1. &FlashStart++((&FlashSize/2.)-1.) &sectorsize TARGET Quad
FLASH.Create 2. (&FlashStart+(&FlashSize/2.))++((&FlashSize/2.)-1.) &sectorsize TARGET Quad
FLASH.Create 3. 0x0BFA0000--0x0BFA01FF TARGET Quad /OTP
FLASH.CreateAlias &SecureFlashStart++((&FlashSize/2.)-1.) &FlashStart
FLASH.CreateAlias (&SecureFlashStart+(&FlashSize/2.))++((&FlashSize/2.)-1.) (&FlashStart+(&FlashSize/2.))
)
ELSE
; Flash declaration for activated Trustzone
; Secured zones are defined by watermark registers
(
;Determine secured region in bank 1
GOSUB Secwmr1 "&sectorsize" "1"
RETURNVALUES &offset &size
;Declare secure/non-secure partitions in bank 1
FLASH.Create 1. &FlashStart++((&FlashSize/2.)-1.) &sectorsize TARGET Quad
IF (&size>0.)
(
FLASH.Delete (&FlashStart+&offset)++(&size-1.)
IF (&secure_allowed)
FLASH.Create 1. (&SecureFlashStart+&offset)++(&size-1.) &sectorsize TARGET Quad
ELSE
FLASH.Create 1. (&SecureFlashStart+&offset)++(&size-1.) &sectorsize NOP Quad
)
FLASH.Create 3. 0x0BFA0000--0x0BFA01FF TARGET Quad /OTP
;Determine secured region in bank 2
GOSUB Secwmr1 "&sectorsize" "2"
RETURNVALUES &offset &size
;Declare secure/non-secure partitions in bank 2
FLASH.Create 2. (&FlashStart+(&FlashSize/2.))++((&FlashSize/2.)-1.) &sectorsize TARGET Quad
IF (&size>0.)
(
FLASH.Delete (&FlashStart+(&FlashSize/2.)+&offset)++(&size-1.)
FLASH.Create 2. (&SecureFlashStart+(&FlashSize/2.)+&offset)++(&size-1.) &sectorsize TARGET Quad
)
)
IF ("&param_dualport"!="1")
(
IF (&secure_allowed)&&(&tzen)
FLASH.TARGET Z:&SecuredRamStart Z:(&SecuredRamStart+0x1000) 0x1000 ~~/demo/arm/flash/byte/&FlashDriver
ELSE
FLASH.TARGET &RamStart (&RamStart+0x1000) 0x1000 ~~/demo/arm/flash/byte/&FlashDriver
)
ELSE
(
IF (&secure_allowed)&&(&tzen)
FLASH.TARGET Z:&SecuredRamStart EZ:(&SecuredRamStart+0x1000) 0x1000 ~~/demo/arm/flash/byte/&FlashDriver /DualPort
ELSE
FLASH.TARGET &RamStart E:(&RamStart+0x1000) 0x1000 ~~/demo/arm/flash/byte/&FlashDriver /DualPort
)
RETURN
)
Secwmr1:
(
PARAMETERS &sectorsize &bank
PRIVATE &startoffset &securedsize &secwmr1 &firstpage &lastpage &number
IF (&bank==1)
&secwmr1=Data.LONG(D:0x50022050)
ELSE
&secwmr1=Data.LONG(D:0x50022060)
&firstpage=&secwmr1&0x7F
&lastpage=(&secwmr1>>16.)&0x7F
IF (&lastpage>=&firstpage)
&number=&lastpage-&firstpage+0x1
ELSE
&number=0x0
&startoffset=&firstpage*&sectorsize
&securedsize=&number*&sectorsize
RETURN "&startoffset" "&securedsize"
)