; -------------------------------------------------------------------------------- ; @Title: Flash declaration for Freescale MKW01 internal flash ; @Description: ; Reprogam internal Flash of Freescale MKW01. ; Script arguments: ; DO mkw01 [PREPAREONLY] [CPU=] [DUALPORT=<0|1>] ; PREPAREONLY only declares flash but does not execute flash programming ; CPU= selects CPU derivative ; DUALPORT=<0|1> use dual port memory access, default 1 ; Example: ; DO ~~/demo/arm/flash/mkw01 CPU=MKW01Z128CHN 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. ; ; CPU-Type ProgFlash RamSize ; [Byte] [Byte] ; -------------------------------------------------------------------------------- ; MKW01Z128CHN 128KB 16KB ; ; Flash at 0x00000000 to 0x0001FFFF ; SRAM_L: Lower SRAM All masters 0x1FFFE000 to 0x1FFFFFFF ; SRAM_U: Upper SRAM 0x20000000 to 0x20002FFF ; ROM table 0xF0002000 to 0xF0002FFF ; ; IFR (Information Flash Registers) Program Once ; Address range Size(Bytes) Field Description ; -------------------------------------------------------------------------------- ; 0x00 to 0xBF 160 Reserved ; 0xC0 to 0xFF 64 Program Once Field ; ; IRC User Trim Registers ; Address Bit(s) Register ; -------------------------------------------------------------------------------- ; 0x0000_03FC Reserved ; 0x0000_03FD Reserved ; 0x0000_03FE 0 SCFTRIM ; 0x0000_03FE 1 to 4 FCTRIM ; 0x0000_03FE 6 FCFTRIM ; 0x0000_03FF SCTRIM ; ; Flash Configuration Field ; Byte address Width Description ; -------------------------------------------------------------------------------- ; 0x0400--0x0407 8 Backdoor Comparison Key ; 0x0408--0x040B 4 Program flash protection bytes (FPROT0-3) ; 0x040C 1 Flash security key location (FSEC) ; 0x040D 1 Flash nonvolatile option byte (FOPT) ; Next registers only available for FlexNVM devices (not available for mkw0 ; series) otherwise unused ; 0x040E 1 EEPROM protection byte (FEPROT) ; 0x040F 1 Data flash protection byte (FDPROT) ; ; @Author: PHI ; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only ; -------------------------------------------------------------------------------- ; $Rev: 10516 $ ; $Id: mkw01.cmm 10516 2022-02-02 11:39:30Z bschroefel $ PRIVATE ¶meters ENTRY %LINE ¶meters PRIVATE ¶m_cpu ¶m_prepareonly ¶m_masserase ¶m_dualport ¶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=","") ¶m_dualport=STRing.SCANAndExtract(STRing.UPpeR("¶meters"),"DUALPORT=","1") ; ------------------------------------------------------------------------------ ; Setup CPU IF (SYStem.MODE()<5)||¶m_masserase ( SYStem.RESet IF "¶m_cpu"!="" SYStem.CPU ¶m_cpu IF !CPUIS("MKW01*") SYStem.CPU MKW01* 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 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?" PRIVATE &progflash ENTRY &progflash IF &progflash ( FLASH.ReProgram.ALL /Erase Data.LOAD.auto * FLASH.ReProgram.off ; Reset device SYStem.Down SYStem.Up ) ENDDO ; -------------------------------------------------------------------------------- ; Disable watchdog DisableWatchdog: ( Data.Set ST:0x40048100 %Long 0x0 RETURN ) ; -------------------------------------------------------------------------------- ; Try to unsecure a secured device Unsecure: ( ; 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?" PRIVATE &masserase ENTRY &masserase IF &masserase ( ON.ERROR DEFault ; Unsecure device (only possible if MDM-AP Status register Bit System Security isn't set) SYStem.Down FLASH.UNSECUREerase ) ELSE ENDDO SYStem.Up ; Disable watchdog GOSUB DisableWatchdog RETURN ) ; -------------------------------------------------------------------------------- ; Try to mass erase the device MassErase: ( ; Mass erase device by unsecure command SYStem.Down FLASH.UNSECUREerase RETURN ) ; -------------------------------------------------------------------------------- ; Flash declaration depending on selected CPU FlashDeclaration: ( PARAMETERS ¶m_dualport PRIVATE &FlashSize &SectorSize &flashdriver IF CPUIS("MKW01*") ( &FlashSize=0x20000 &SectorSize=0x400 &flashdriver="ftfa.bin" ) ELSE ( PRINT %ERROR "FLASH size of CPU type is not supported by the script" ENDDO ) ; Program Flash FLASH.Create 1. 0x00000000--(&FlashSize-1) &SectorSize TARGET Long /KEEP 0x3FC--0x3FF /CENSORSHIP 0x400++0xf IF (("¶m_dualport"=="0")||SYStem.ACCESS.DENIED()) FLASH.TARGET 0x20000000 (0x20000000+0x1000) 0x400 ~~/demo/arm/flash/long/&flashdriver ELSE FLASH.TARGET 0x20000000 (0x20000000+0x1000) 0x400 ~~/demo/arm/flash/long/&flashdriver /DualPort RETURN )