; --------------------------------------------------------------------------------
; @Title: Programming internal flash of SPC56AP60, SPC56AP54, SPC560P60, SPC560P54
;
; @Description:
; Example script for programming internal flash of
;   SPC56AP60, SPC56AP54
;   SPC560P60, SPC560P54
;
; Script arguments:
;
;   DO spc56ap60 [PREPAREONLY] [SKIPCONFIG]
;
;     PREPAREONLY only declares flash but does not execute flash programming
;     SKIPCONFIG  skip configuration part to allow script external configuration
;
; Example:
;
;   DO ~~/demo/powerpc/flash/spc56ap PREPAREONLY SKIPCONFIG
;
; @Author: WRD
; @Chip: SPC56AP60 SPC56AP54 SPC560P60 SPC560P50
; @Copyright: (C) 1989-2014 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Rev: 5830 $
; $Id: spc56ap.cmm 5830 2018-07-16 15:25:52Z rweiss $
;


LOCAL &parameters &param_prepareonly &param_skipconfig
ENTRY %LINE &parameters
&param_prepareonly=(STRing.SCAN(STRing.UPpeR("&parameters"),"PREPAREONLY",0)!=-1)
&param_skipconfig=(STRing.SCAN(STRing.UPpeR("&parameters"),"SKIPCONFIG",0)!=-1)

LOCAL &flashbase &shadowbase &rambase &flashsize
&flashbase=0x00000000
&shadowbase=0x00200000
&rambase=0x40000000
&flashsize="tbd"

LOCAL &DualPort
IF VERSION.BUILD.BASE()>=45520.
  &DualPort="/DualPort"

; ------------------------------------------------------------------------------
; CPU setup

IF !&param_skipconfig
(
  SYStem.RESet
  SYStem.BdmClock 4.0MHz
  SYStem.CPU MPC55XX
  SYStem.DETECT.CPU
  SYStem.Option.WATCHDOG OFF
  SYStem.Up
)

IF (CPU()=="SPC56AP60")||(CPU()=="SPC560P60")
  &flashsize=0x100000
ELSE IF (CPU()=="SPC56AP54")||(CPU()=="SPC560P54")
  &flashsize=0x0C0000

; protect from accessing unimplemented memory (open Data.List/Dump windows)
MAP.DenyAccess 0x20000000--0x3FFFFFFF

; initialize internal SRAM
Data.Set EA:0x40000000--0x40003FFF %Quad 0

; ------------------------------------------------------------------------------
; Flash declaration

FLASH.RESet

FLASH.Create 1. (&flashbase+0x00000000)++0x03fff TARGET Quad 0. ; L0
FLASH.Create 1. (&flashbase+0x00004000)++0x03fff TARGET Quad 1. ; L1
FLASH.Create 1. (&flashbase+0x00008000)++0x07fff TARGET Quad 2. ; L2
FLASH.Create 1. (&flashbase+0x00010000)++0x07fff TARGET Quad 3. ; L3
FLASH.Create 1. (&flashbase+0x00018000)++0x03fff TARGET Quad 4. ; L4
FLASH.Create 1. (&flashbase+0x0001c000)++0x03fff TARGET Quad 5. ; L5
FLASH.Create 1. (&flashbase+0x00020000)++0x0ffff TARGET Quad 6. ; L6
FLASH.Create 1. (&flashbase+0x00030000)++0x0ffff TARGET Quad 7. ; L7

FLASH.Create 2. (&flashbase+0x00040000)++0x1ffff TARGET Quad 0. ; M0
FLASH.Create 2. (&flashbase+0x00060000)++0x1ffff TARGET Quad 1. ; M1

LOCAL &flashaddr &Hx
&flashaddr=&flashbase+0x00080000
&Hx=0.
WHILE &flashaddr<(&flashbase+&flashsize)
(
  FLASH.Create 3. &flashaddr++0x1ffff TARGET Quad &Hx ; H0..H3
  &flashaddr=&flashaddr+0x20000
  &Hx=&Hx+1.
)

; Shadow row
FLASH.Create 4. (&shadowbase+0x00000000)++0x3fff NOP Quad

; Data flash
FLASH.Create 5. (&flashbase+0x00800000)++0x3fff TARGET Quad 0.
FLASH.Create 5. (&flashbase+0x00804000)++0x3fff TARGET Quad 1.
FLASH.Create 5. (&flashbase+0x00808000)++0x3fff TARGET Quad 2.
FLASH.Create 5. (&flashbase+0x0080c000)++0x3fff TARGET Quad 3.

FLASH.TARGET E:&rambase E:&rambase+0x2000 0x1000 ~~/demo/powerpc/flash/quad/c90fl56ap60.bin /STACKSIZE 0x0200 &DualPort

; Flash script ends here if called with parameter PREPAREONLY
IF &param_prepareonly
  ENDDO PREPAREDONE

; ------------------------------------------------------------------------------
; Flash programming example
;
; Flash programming speed is about three times faster when memory class E:
; is used for data buffer (DUALPORT memory access). For DUALPORT access it
; is required to setup MemAccess NEXUS for both, NEXUS and JTAG debugger.

DIALOG.YESNO "Flash programming prepared. Program flash memory now?"
LOCAL &progflash
ENTRY &progflash

IF &progflash
(
  FLASH.ReProgram ALL /Erase
  Data.LOAD.auto *
  FLASH.ReProgram.off
)
ELSE
(
  FLASH.List
)

ENDDO
