309 lines
9.3 KiB
Plaintext
309 lines
9.3 KiB
Plaintext
; --------------------------------------------------------------------------------
|
|
; @Title: Flash declaration for ST STM32H5 internal flash
|
|
; @Description:
|
|
; Script arguments:
|
|
; DO stm32h5 [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)
|
|
; HOSTMODE=<0|1> use host-mode programming (1) or target-based binary (0)
|
|
; Example:
|
|
; DO ~~/demo/arm/flash/stm32h5 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 STM32H5 derivatives and their configuration:
|
|
; CPU-Type TZ SRAM FLASH
|
|
; [byte] [byte]
|
|
; ------------------------------------------------------------------------------
|
|
; STM32H503xB N 0x08800 0x020000
|
|
; STM32H562xG Y 0xA1000 0x100000
|
|
; STM32H562xI Y 0xA1000 0x200000
|
|
; STM32H563xG Y 0xA1000 0x100000
|
|
; STM32H563xI Y 0xA1000 0x200000
|
|
; STM32H573xI Y 0xA1000 0x200000
|
|
;
|
|
; Flash nonsecure : 0x08000000--<end addr>
|
|
; Flash secure : 0x0C000000--<end addr> (TZ=Y)
|
|
; SRAM nonsecure : 0x20000000--<end addr>
|
|
; SRAM secure : 0x30000000--<end addr> (TZ=Y)
|
|
; Backup SRAM : 0x40036400--<end addr> (0x50036400 start addr for secure)
|
|
;
|
|
; NOTE: In case there is an active window watchdog that cannot be disabled using
|
|
; the debugger, HOSTMODE=1 will use an alternative programming mode. This is
|
|
; slower than a target-based binary for flash operations but will prevent a
|
|
; watchdog reset.
|
|
;
|
|
; Currently, host-mode (1) is the default.
|
|
;
|
|
; @Chip: STM32H5*
|
|
; @Author: BWR
|
|
; @Copyright: (C) 1989-2023 Lauterbach GmbH, licensed for use with TRACE32(R) only
|
|
; --------------------------------------------------------------------------------
|
|
; $Rev: 12945 $
|
|
; $Id: stm32h5.cmm 12945 2024-01-17 12:15:35Z bwright $
|
|
|
|
PRIVATE ¶meters
|
|
ENTRY %LINE ¶meters
|
|
|
|
PRIVATE ¶m_prepareonly ¶m_cpu ¶m_dualport ¶m_hostmode
|
|
¶meters=STRing.UPpeR("¶meters")
|
|
¶m_prepareonly=(STRing.SCAN(STRing.UPpeR("¶meters"),"PREPAREONLY",0)!=-1)
|
|
¶m_cpu=STRing.SCANAndExtract(STRing.UPpeR("¶meters"),"CPU=","")
|
|
¶m_dualport=STRing.SCANAndExtract(STRing.UPpeR("¶meters"),"DUALPORT=","0")
|
|
¶m_hostmode=STRing.SCANAndExtract(STRing.UPpeR("¶meters"),"HOSTMODE=","1")
|
|
|
|
; --------------------------------------------------------------------------------
|
|
; Initialize and start the debugger
|
|
IF !SYStem.Up()
|
|
(
|
|
SYStem.RESet
|
|
|
|
IF "¶m_cpu"!=""
|
|
SYStem.CPU ¶m_cpu
|
|
IF !CPUIS(STM32H5*)
|
|
SYStem.CPU STM32H5*
|
|
|
|
SYStem.MemAccess DAP
|
|
|
|
IF CABLE.TWOWIRE()
|
|
SYStem.CONFIG DEBUGPORTTYPE SWD
|
|
ELSE
|
|
SYStem.CONFIG DEBUGPORTTYPE JTAG
|
|
|
|
SYStem.Up
|
|
)
|
|
|
|
; --------------------------------------------------------------------------------
|
|
; Flash declaration
|
|
FLASH.RESet
|
|
GOSUB FlashDeclaration "¶m_dualport" "¶m_hostmode"
|
|
|
|
; Flash script ends here if called with parameter PREPAREONLY
|
|
IF ¶m_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 param_hostmode)
|
|
(
|
|
PARAMETERS ¶m_dualport ¶m_hostmode
|
|
PRIVATE &FlashDriver
|
|
PRIVATE &tzen &secure_allowed &FlashStart &SecureFlashStart &RamStart &SecureRamStart §orsize
|
|
PRIVATE &offset &size
|
|
PRIVATE &mode
|
|
|
|
IF "¶m_hostmode"!="0"
|
|
&mode="STM32H5"
|
|
ELSE
|
|
&mode="TARGET"
|
|
|
|
IF CPUIS(STM32H5*)
|
|
&FlashDriver="stm32h5.bin"
|
|
ELSE
|
|
SYStem.CPU STM32H5*
|
|
|
|
&FlashStart=0x08000000
|
|
&SecureFlashStart=0x0C000000
|
|
&RamStart=0x20000000
|
|
&SecureRamStart=0x30000000
|
|
§orsize=0x2000
|
|
&tzen=FALSE()
|
|
&secure_allowed=FALSE()
|
|
|
|
IF CPUIS(STM32H5???B*)
|
|
&FlashSize=0x20000
|
|
ELSE IF CPUIS(STM32H5???G*)
|
|
&FlashSize=0x100000
|
|
ELSE IF CPUIS(STM32H5???I*)
|
|
&FlashSize=0x200000
|
|
ELSE
|
|
(
|
|
PRINT %ERROR "Unexpected flash size designator. Try manually entering flash size or contact support."
|
|
ENDDO
|
|
)
|
|
|
|
IF CPUIS(STM32H503*)
|
|
(
|
|
; TrustZone not available for the CPU
|
|
&tzen=FALSE()
|
|
&secure_allowed=TRUE()
|
|
)
|
|
ELSE
|
|
(
|
|
ON ERROR CONTinue
|
|
(
|
|
&tzen=(Data.Long(ZD:0x40022070)&0xFF000000)==0xB4000000
|
|
&secure_allowed=(Data.Long(ZD:0x40022050)&0x0000FF00)==0x0000ED00
|
|
; See RM0481 section 3.11.2 for details
|
|
)
|
|
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++0x37FF
|
|
IF FOUND()||(&error)
|
|
(
|
|
PRINT %ERROR "Detected non-secure SRAM space too small for flash algorithm"
|
|
ENDDO
|
|
)
|
|
)
|
|
|
|
IF (Data.Long(D:0x40022050)>>31.)==1.
|
|
PRINT "Flash banks 1 and 2 are currently swapped."
|
|
|
|
IF !&tzen
|
|
(
|
|
; Flash declaration, if Trustzone is not activated
|
|
FLASH.Create 1. &FlashStart++((&FlashSize/2.)-1.) §orsize &mode Quad
|
|
FLASH.Create 2. (&FlashStart+(&FlashSize/2.))++((&FlashSize/2.)-1.) §orsize &mode Quad
|
|
FLASH.Create 3. 0x08FFF000--0x08FFF7FF &mode Quad /OTP
|
|
|
|
IF !CPUIS(STM32H503*)
|
|
(
|
|
FLASH.CreateAlias &SecureFlashStart++((&FlashSize/2.)-1.) &FlashStart
|
|
FLASH.CreateAlias (&SecureFlashStart+(&FlashSize/2.))++((&FlashSize/2.)-1.) (&FlashStart+(&FlashSize/2.))
|
|
)
|
|
)
|
|
ELSE
|
|
(
|
|
; Flash declaration with Trustzone active
|
|
; Secure zones are defined by watermark registers
|
|
|
|
; Determine secured region in bank 1
|
|
GOSUB SecwmNr "§orsize" "1"
|
|
RETURNVALUES &offset &size
|
|
|
|
;Declare secure/non-secure partitions in bank 1
|
|
FLASH.Create 1. &FlashStart++((&FlashSize/2.)-1.) §orsize &mode Quad
|
|
IF (&size>0.)
|
|
(
|
|
FLASH.Delete (&FlashStart+&offset)++(&size-1.)
|
|
IF (&secure_allowed)
|
|
FLASH.Create 1. (&SecureFlashStart+&offset)++(&size-1.) §orsize &mode Quad
|
|
ELSE
|
|
FLASH.Create 1. (&SecureFlashStart+&offset)++(&size-1.) §orsize NOP Quad
|
|
)
|
|
FLASH.Create 3. 0x08FFF000--0x08FFF7FF &mode Quad /OTP
|
|
|
|
;Determine secured region in bank 2
|
|
GOSUB SecwmNr "§orsize" "2"
|
|
RETURNVALUES &offset &size
|
|
|
|
;Declare secure/non-secure partitions in bank 2
|
|
FLASH.Create 2. (&FlashStart+(&FlashSize/2.))++((&FlashSize/2.)-1.) §orsize &mode Quad
|
|
IF (&size>0.)
|
|
(
|
|
FLASH.Delete (&FlashStart+(&FlashSize/2.)+&offset)++(&size-1.)
|
|
FLASH.Create 2. (&SecureFlashStart+(&FlashSize/2.)+&offset)++(&size-1.) §orsize &mode Quad
|
|
)
|
|
)
|
|
|
|
; Set inaccessible/write-protected flash regions to NOP
|
|
IF CPUIS(STM32H503*)
|
|
GOSUB DenyWrpsgMaskedAccess "&FlashStart" "&FlashSize" "§orsize" "1"
|
|
ELSE
|
|
GOSUB DenyWrpsgMaskedAccess "&FlashStart" "&FlashSize" "§orsize" "4"
|
|
|
|
IF ("¶m_hostmode"!="1")
|
|
(
|
|
IF ("¶m_dualport"!="1")
|
|
(
|
|
IF (&secure_allowed)&&(&tzen)
|
|
FLASH.TARGET Z:&SecureRamStart Z:(&SecureRamStart+0x1000) 0x2000 ~~/demo/arm/flash/byte/&FlashDriver
|
|
ELSE
|
|
FLASH.TARGET &RamStart (&RamStart+0x1000) 0x2000 ~~/demo/arm/flash/byte/&FlashDriver
|
|
)
|
|
ELSE
|
|
(
|
|
IF (&secure_allowed)&&(&tzen)
|
|
FLASH.TARGET Z:&SecureRamStart EZ:(&SecureRamStart+0x1000) 0x2000 ~~/demo/arm/flash/byte/&FlashDriver /DualPort
|
|
ELSE
|
|
FLASH.TARGET &RamStart E:(&RamStart+0x1000) 0x2000 ~~/demo/arm/flash/byte/&FlashDriver /DualPort
|
|
)
|
|
)
|
|
|
|
RETURN
|
|
)
|
|
|
|
DenyWrpsgMaskedAccess:
|
|
(
|
|
PARAMETERS &FlashStart &FlashSize §orsize §orspergroup
|
|
PRIVATE &bitshift &wrp1r_cur &wrp2r_cur &bank2_start &groupsize
|
|
&groupsize=§orsize*§orspergroup
|
|
&wrp1r_cur=Data.Long(D:0x400220E8)
|
|
&wrp2r_cur=Data.Long(D:0x400221E8)
|
|
&bitshift=0.
|
|
WHILE &bitshift<(&FlashSize/(2*&groupsize))
|
|
(
|
|
IF (&wrp1r_cur&(1<<&bitshift))==0.
|
|
FLASH.CHANGEtype (&FlashStart+&groupsize*&bitshift)++(&groupsize-1) NOP /INFO "Read-only (WRPSG)"
|
|
IF (&wrp2r_cur&(1<<&bitshift))==0.
|
|
FLASH.CHANGEtype (&FlashStart+(&FlashSize/2.)+§orsize*&bitshift)++(&groupsize-1) NOP /INFO "Read-only (WRPSG)"
|
|
&bitshift=&bitshift+1
|
|
)
|
|
RETURN
|
|
)
|
|
|
|
SecwmNr:
|
|
(
|
|
PARAMETERS §orsize &bank
|
|
PRIVATE &startoffset &securedsize &secwmNr &firstpage &lastpage &number
|
|
|
|
IF (&bank==1)
|
|
&secwmNr=Data.Long(D:0x500220E0)
|
|
ELSE
|
|
&secwmNr=Data.Long(D:0x500221E0)
|
|
|
|
&firstpage=&secwmNr&0x7F
|
|
&lastpage=(&secwmNr>>16.)&0x7F
|
|
IF (&lastpage>=&firstpage)
|
|
&number=&lastpage-&firstpage+0x1
|
|
ELSE
|
|
&number=0x0
|
|
|
|
&startoffset=&firstpage*§orsize
|
|
&securedsize=&number*§orsize
|
|
|
|
RETURN "&startoffset" "&securedsize"
|
|
)
|