; -------------------------------------------------------------------------------- ; @Title: Generic script for Freescale MKL02, MKL03, MKL04 and MKL05 internal flash ; ; @Description: ; ; Example for flash declaration of Freescale MKL02, MKL03, MKL04 and MKL05 internal ; flash. ; ; Script arguments: ; ; DO mkl0 [PREPAREONLY] [CPU=] [DUALPORT=0|1] [MASSERASE] ; ; PREPAREONLY only declares flash but does not execute flash programming ; example ; ; CPU= selects CPU derivative . can be CPU name out of the ; table listed below. For these derivatives the flash declaration ; is done by the script. ; ; DUALPORT default value is 0 (disabled). If DualPort mode is enabled ; flash algorithm stays running until flash programming is ; finished. Data is tranferred via dual port memory access. ; ; MASSERASE forces mass erase of device before establishing debug connection ; ; For example: ; ; DO ~~/demo/arm/flash/mkl0 CPU=MKL05Z32VLF4 DUALPORT=1 PREPAREONLY ; ; List of MKL02, MKL03, MKL04 and MKL05 derivatives and their configuration: ; ; CPU-Type ProgFlash RamSize ; [Byte] [Byte] ; -------------------------------------------------------------------------------- ; MKL02Z8VFG4 8kB 1kB ; MKL02Z8VFG4R 8kB 1kB ; MKL02Z16VFG4 16kB 2kB ; MKL02Z16VFG4R 16kB 2kB ; MKL02Z16VFK4 16kB 2kB ; MKL02Z16VFM4 16kB 2kB ; MKL02Z32VFG4 32kB 4kB ; MKL02Z32VFG4R 32kB 4kB ; MKL02Z32VFK4 32kB 4kB ; MKL02Z32VFK4R 32kB 4kB ; MKL02Z32VFM4 32kB 4kB ; MKL02Z32VFM4R 32kB 4kB ; MKL02Z32CAF4R 32kB 4kB ; -------------------------------------------------------------------------------- ; MKL03Z8VFG4 8kB 2kB ; MKL03Z16VFG4 16kB 2kB ; MKL03Z16VFG4R 16kB 2kB ; MKL03Z16VFK4R 16kB 2kB ; KKL03Z32CAF4R 32kB 2kB ; KKL03Z32CBF4R 32kB 2kB ; MKL03Z32VFG4 32kB 2kB ; MKL03Z32VFG4R 32kB 2kB ; MKL03Z32VFK4R 32kB 2kB ; MKL03Z32CAF4R 32kB 2kB ; MKL03Z8VFG4R 8kB 2kB ; MKL03Z8VFK4 8kB 2kB ; MKL03Z16VFK4 16kB 2kB ; MKL03Z32VFK4 32kB 2kB ; -------------------------------------------------------------------------------- ; MKL04Z8VFK4 8kB 1kB ; MKL04Z8VFM4 8kB 1kB ; MKL04Z8VLC4 8kB 1kB ; MKL04Z8VLC4R 8kB 1kB ; MKL04Z16VFK4 16kB 2kB ; MKL04Z16VFM4 16kB 2kB ; MKL04Z16VLC4 16kB 2kB ; MKL04Z16VLC4R 16kB 2kB ; MKL04Z16VLF4 16kB 2kB ; MKL04Z32VFK4 32kB 4kB ; MKL04Z32VFK4R 32kB 4kB ; MKL04Z32VFM4 32kB 4kB ; MKL04Z32VFM4R 32kB 4kB ; MKL04Z32VLC4 32kB 4kB ; MKL04Z32VLC4R 32kB 4kB ; MKL04Z32VLF4 32kB 4kB ; MKL04Z32VLF4R 32kB 4kB ; -------------------------------------------------------------------------------- ; MKL05Z8VFK4 8kB 1kB ; MKL05Z8VFM4 8kB 1kB ; MKL05Z8VLC4 8kB 1kB ; MKL05Z16VFK4 16kB 2kB ; MKL05Z16VFM4 16kB 2kB ; MKL05Z16VLC4 16kB 2kB ; MKL05Z16VLF4 16kB 2kB ; MKL05Z32VFK4 32kB 4kB ; MKL05Z32VFK4R 32kB 4kB ; MKL05Z32VFM4 32kB 4kB ; MKL05Z32VFM4R 32kB 4kB ; MKL05Z32VLC4 32kB 4kB ; MKL05Z32VLC4R 32kB 4kB ; MKL05Z32VLF4 32kB 4kB ; MKL05Z32VLF4R 32kB 4kB ; ; Flash Configuration Field: ; ; Byte address Width Description ; -------------------------------------------------------------------------------- ; 0x0400--0x0407 8 Backdoor Comparison Key. ; 0x0408--0x040B 4 Program flash protection bytes (FPROT0-3). ; 0x040F 1 Program flash only devices: Reserved ; FlexNVM devices: Data flash protection byte ; (FDPROT). ; 0x040E 1 Program flash only devices: Reserved ; FlexNVM devices: EEPROM protection byte ; (FEPROT). ; 0x040D 1 Flash nonvolatile option byte (FOPT). ; 0x040C 1 Flash security byte (FSEC). ; ; Flash Configuration Field can be programmed using FLASH.AUTO command ; with /CENSORSHIP option. ; ; @Chip: MKL02* MKL03* MKL04* MKL05* ; @Author: WRD ; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only ; -------------------------------------------------------------------------------- ; $Rev: 10516 $ ; $Id: mkl0.cmm 10516 2022-02-02 11:39:30Z bschroefel $ ; LOCAL ¶meters ENTRY %LINE ¶meters LOCAL ¶m_prepareonly ¶m_masserase ¶m_cpu ¶m_prepareonly=(STRing.SCAN(STRing.UPpeR("¶meters"),"PREPAREONLY",0)!=-1) ¶m_masserase=(STRing.SCAN(STRing.UPpeR("¶meters"),"MASSERASE",0)!=-1) ¶m_cpu=STRing.SCANAndExtract(STRing.UPpeR("¶meters"),"CPU=","") LOCAL ¶m_dualport ¶m_dualport=0 IF VERSION.BUILD.BASE()>=43441. ¶m_dualport=STRing.SCANAndExtract(STRing.UPpeR("¶meters"),"DUALPORT=","0") ; ------------------------------------------------------------------------------ ; Setup CPU IF (SYStem.MODE()<5)||¶m_masserase ( SYStem.RESet IF "¶m_cpu"!="" SYStem.CPU ¶m_cpu IF !CPUIS(MKL0*) SYStem.CPU MKL0* SYStem.CONFIG.DEBUGPORTTYPE SWD IF ¶m_masserase GOSUB MassErase ON.ERROR GOSUB Unsecure SYStem.Up ON.ERROR ) ; Unsecure device IF (Data.Long(EDBG:0x40000100)&0x04)==0x04 GOSUB Unsecure ; Disable watchdog ON.ERROR GOSUB Unsecure GOSUB DisableWatchdog ON.ERROR ; ------------------------------------------------------------------------------ ; Flash declaration FLASH.RESet GOSUB FlashDeclaration ¶m_dualport ; Flash script ends here if called with parameter PREPAREONLY IF ¶m_prepareonly ENDDO PREPAREDONE ; ------------------------------------------------------------------------------ ; Flash programming example DIALOG.YESNO "Program flash memory?" LOCAL &progflash ENTRY &progflash IF &progflash ( FLASH.ReProgram.ALL /Erase Data.LOAD.auto * FLASH.ReProgram.off ; Reset device SYStem.Down SYStem.Up ; Disable watchdog GOSUB DisableWatchdog ) ENDDO ; -------------------------------------------------------------------------------- ; Disable watchdog DisableWatchdog: Data.Set SD:0x40048100 %Long 0x00000000 ; this register can only be accessed once after reset. RETURN ; -------------------------------------------------------------------------------- ; Try to unsecure a secured device Unsecure: IF VERSION.BUILD()<48722. DO ~~~~/kinetis-unsecure ELSE ( ; Print security state information SYStem.Mode.Prepare PRINT "MDM-AP Status Register is 0x" Data.Long(EDBG:0x40000100) DIALOG.YESNO "Execute mass erase to unsecure chip?" LOCAL &masserase ENTRY &masserase IF &masserase ( ON.ERROR DEFault ; Unsecure device SYStem.Down FLASH.UNSECUREerase SYStem.Mode.Prepare IF (Data.Long(EDBG:0x40000100)&0x04)==0x04 ( PRINT %ERROR "Unsecure failed, MDM-AP Status Register is 0x" Data.Long(EDBG:0x40000100) SYStem.Down ENDDO ) ) ELSE ENDDO ) SYStem.Up ; Disable watchdog GOSUB DisableWatchdog RETURN ; -------------------------------------------------------------------------------- ; Try to mass erase the device MassErase: IF VERSION.BUILD.BASE()<49714. DO ~~~~/kinetis-unsecure ELSE ( ; Mass erase device by unsecure command SYStem.Down FLASH.UNSECUREerase SYStem.Mode.Prepare IF (Data.Long(EDBG:0x40000100)&0x24)!=0x20 ( PRINT %ERROR "Mass erase failed, MDM-AP Status Register is 0x" Data.Long(EDBG:0x40000100) SYStem.Down ENDDO ) ) RETURN ; -------------------------------------------------------------------------------- ; Flash declaration depending on selected CPU FlashDeclaration: LOCAL &DualPort ENTRY &DualPort LOCAL &PFlashSize LOCAL &RAMSize ; Setup configuration values IF CPUIS("MKL02Z8V*")||CPUIS("MKL04Z8V*")||CPUIS("MKL05Z8V*") ( &PFlashSize=0x2000 &RAMSize=0x400 ) ELSE IF CPUIS("MKL03Z8V*") ( &PFlashSize=0x2000 &RAMSize=0x800 ) ELSE IF CPUIS("MKL0?Z16V*") ( &PFlashSize=0x4000 &RAMSize=0x800 ) ELSE IF CPUIS("MKL02Z32*")||CPUIS("MKL04Z32V*")||CPUIS("MKL05Z32V*") ( &PFlashSize=0x8000 &RAMSize=0x1000 ) ELSE IF CPUIS("MKL03Z32*")||CPUIS("KKL03Z32*") ( &PFlashSize=0x8000 &RAMSize=0x800 ) ELSE ( PRINT %ERROR "FLASH size of CPU type is not supported by the script" ENDDO ) ; Program Flash IF &PFlashSize>=0x2000 FLASH.Create 1. 0x00000000--0x00001FFF 0x400 TARGET Long /KEEP 0x3FC--0x3FF /CENSORSHIP 0x400--0x40F IF &PFlashSize>=0x4000 FLASH.Create 1. 0x00002000--0x00003FFF 0x400 TARGET Long IF &PFlashSize>=0x8000 FLASH.Create 1. 0x00004000--0x00007FFF 0x400 TARGET Long IF &RAMSize>=0x1000 ( IF &DualPort==0 FLASH.TARGET 0x1FFFFC00 0x20000400 0x400 ~~/demo/arm/flash/long/ftfa.bin ELSE FLASH.TARGET 0x1FFFFC00 EAHB:0x20000400 0x400 ~~/demo/arm/flash/long/ftfa.bin /DualPort ) ELSE IF &RAMSize>=0x800 FLASH.TARGET 0x1FFFFE00 0x20000380 0x100 ~~/demo/arm/flash/long/ftfa.bin ELSE ( PRINT %ERROR "Memory configuration preliminary not supported, please request an update" ENDDO ) RETURN