; --------------------------------------------------------------------------------
; @Title: Example Script for programming of ST STR71x internal flash
;
; @Description: 
; Script arguments:
;
;   DO str71x [PREPAREONLY]
;
;     PREPAREONLY only declares flash but does not execute flash programming
;
; Example:
;
;   DO ~~/demo/arm/flash/str71x PREPAREONLY
;
; List of STR71x derivatives and their configuration:
;
; CPU-Type      FlashBank0   FlashBank1  SRAM size 
;                (kByte)       (kByte)    (kByte)
; --------------------------------------------------------------------------------
; STR710FZ1        128.          16.        32.
; STR710FZ2        256.          16.        64.
; STR711FR0         64.          16.        16.
; STR711FR1        128.          16.        32.
; STR711FR2        256.          16.        64.
; STR712FR0         64.          16.        16.
; STR712FR1        128.          16.        32.
; STR712FR2        256.          16.        64.
; STR715FR0         64.          16.        16.
;
; NOTE:
;   FLASH.Erase and FLASH.Program are executing temporary unlock of write
;   protected sectors. After erasing or programming the sectors are 
;   locked again. FLASH.UNLOCK command is not needed for erasing or 
;   programming.
;
;   FLASH.UNLOCK command is unlocking all sectors independant of used 
;   argument. The unlock state is lost after erase or program execution.
;
;   FLASH.LOCK is write protecting the sectors given by the argument.
;
; @Author: WRD
; @Copyright: (C) 1989-2019 Lauterbach GmbH, licensed for use with TRACE32(R) only
; @Chip: STR71*
; --------------------------------------------------------------------------------
; $Id: str71x.cmm 7602 2019-11-05 15:02:25Z bschroefel $

LOCAL &parameters
ENTRY %LINE &parameters

LOCAL &param_prepareonly
&param_prepareonly=(STRing.SCAN(STRing.UPpeR("&parameters"),"PREPAREONLY",0)!=-1)

; --------------------------------------------------------------------------------
; Setup the configuration information out of the table above.
;
; Example for STR710FZ2

&flashbank0=256.

; Select flash base address for programming, 0x0 or 0x40000000.
&flashbase=0x00000000

; --------------------------------------------------------------------------------
; CPU setup
IF SYStem.MODE()<5
(
  SYStem.RESet
  SYStem.CPU STR712

  SYStem.Option RESBREAK OFF 
  SYStem.JtagClock 10MHz

  SYStem.Up
)
      
; --------------------------------------------------------------------------------
; Flash declaration

FLASH.RESet
FLASH.Create 1. (&flashbase+0x00000000)++0x01fff TARGET Long 0x00000001    ; Bank 0 Sector 0
FLASH.Create 1. (&flashbase+0x00002000)++0x01fff TARGET Long 0x00000002    ; Bank 0 Sector 1
FLASH.Create 1. (&flashbase+0x00004000)++0x01fff TARGET Long 0x00000004    ; Bank 0 Sector 2
FLASH.Create 1. (&flashbase+0x00006000)++0x01fff TARGET Long 0x00000008    ; Bank 0 Sector 3
FLASH.Create 1. (&flashbase+0x00008000)++0x07fff TARGET Long 0x00000010    ; Bank 0 Sector 4
IF &flashbank0>=128.
(
  FLASH.Create 1. (&flashbase+0x00010000)++0x0ffff TARGET Long 0x00000020  ; Bank 0 Sector 5
)
IF &flashbank0>=256.
(
  FLASH.Create 1. (&flashbase+0x00020000)++0x0ffff TARGET Long 0x00000040  ; Bank 0 Sector 6
  FLASH.Create 1. (&flashbase+0x00030000)++0x0ffff TARGET Long 0x00000080  ; Bank 0 Sector 7
)

FLASH.Create 2. (&flashbase+0x000C0000)++0x01fff TARGET Long 0x00010000    ; Bank 1 Sector 0
FLASH.Create 2. (&flashbase+0x000C2000)++0x01fff TARGET Long 0x00020000    ; Bank 1 Sector 1
   
FLASH.TARGET 0x20000000 0x20001000 0x1000 ~~/demo/arm/flash/long/str7.bin
  
  
; Flash script ends here if called with parameter PREPAREONLY
IF &param_prepareonly
  ENDDO PREPAREDONE
; --------------------------------------------------------------------------------
; Flash programming example
;
DIALOG.YESNO "Program flash memory?"
ENTRY &progflash

IF &progflash 
(
  FLASH.Erase ALL
  FLASH.Program ALL
  Data.LOAD.auto * /Long
  FLASH.Program off
  Data.LOAD.auto * /Long /ComPare
)

ENDDO

