; -------------------------------------------------------------------------------- ; @Title: Example Script for programming of TI F28M36 Cortex-M3 internal flash ; ; @Description: ; Script arguments: ; ; DO f28m36 [PREPAREONLY] [AUTOECC=0|1] [DUALPORT=0|1] ; ; AUTOECC default value is 1 ; ; PREPAREONLY only declares flash but does not execute flash programming example ; ; 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. ; ; Example: ; ; DO ~~/demo/arm/flash/f28m36 DUALPORT=1 AUTOECC=0 PREPAREONLY ; ; List of F28M36 derivatives and their flash Size: ; ; CPU-Type Flash size ; [kByte] ; -------------------------------------------------------------------------------- ; F28M36H33B 512. ; F28M36H33C 512. ; F28M36H53B 512. ; F28M36H53C 512. ; F28M36P53C 512. ; F28M36P63C 1024. ; ; @Author: FLC ; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only ; -------------------------------------------------------------------------------- ; $Rev: 10516 $ ; $Id: f28m36.cmm 10516 2022-02-02 11:39:30Z bschroefel $ LOCAL ¶meters ENTRY %LINE ¶meters LOCAL ¶m_prepareonly ¶m_prepareonly=(STRing.SCAN(STRing.UPpeR("¶meters"),"PREPAREONLY",0)!=-1) LOCAL &AutoECCGeneration &AutoECCGeneration=STRing.SCANAndExtract(STRing.UPpeR("¶meters"),"AUTOECC=","1") LOCAL ¶m_dualport ¶m_dualport=0 IF VERSION.BUILD.BASE()>=43441. ¶m_dualport=STRing.SCANAndExtract(STRing.UPpeR("¶meters"),"DUALPORT=","0") ; ------------------------------------------------------------------------------ ; CPU setup IF SYStem.MODE()<5 ( SYStem.RESet IF !CPUIS(F28M36*) SYStem.CPU F28M36* SYStem.CONFIG.DEBUGPORTTYPE JTAG SYStem.JtagClock 2MHz SYStem.Option.DUALPORT ON SYStem.MemAccess DAP SYStem.Up ; Setup target GOSUB UnlockInternalSRAM GOSUB readOTPSECLOCK GOSUB unlockCSMZ1 GOSUB unlockCSMZ2 GOSUB unlockECSLZ1 GOSUB unlockECSLZ2 GOSUB readFlashEXEZ1 GOSUB readFlashEXEZ2 GOSUB grabSectors GOSUB DeviceConfig GOSUB initRAM ) ; ------------------------------------------------------------------------------ ; Flash declaration FLASH.RESet GOSUB FlashDeclaration ¶m_dualport GOSUB initSYSCLK GOSUB initRWAIT GOSUB disableFlashECC ; 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 ) ENDDO ; -------------------------------------------------------------------------------- ; Flash declaration depending on CPU configuration FlashDeclaration: LOCAL &DualPort ENTRY &DualPort LOCAL &FlashSize IF CPUIS(F28M36P63C2) &FlashSize=0x100000 ; [Byte] ELSE &FlashSize=0x80000 ; [Byte] IF &AutoECCGeneration!=0 ( FLASH.Create 1. 0x00200000--0x0021FFFF 0x8000 TARGET Byte FLASH.Create 1. 0x00220000--0x0023ffff 0x20000 TARGET Byte IF &FlashSize>=0x100000 ( FLASH.Create 1. 0x00240000--0x002bffff 0x20000 TARGET Byte ) FLASH.Create 1. 0x002C0000--0x002dffff 0x20000 TARGET Byte FLASH.Create 1. 0x002e0000--0x002fffff 0x8000 TARGET Byte IF &DualPort==0 FLASH.TARGET 0x20000000 0x20002000 0x1000 ~~/demo/arm/flash/byte/f021m3.bin ELSE FLASH.TARGET 0x20000000 EAHB:0x20002000 0x1000 ~~/demo/arm/flash/byte/f021m3.bin /DualPort /STACKSIZE 0x120 ) ELSE ( ; Flash FLASH.Create 1. 0x00200000--0x0021FFFF 0x8000 TARGET Byte /EraseALIAS 0x00600000--0x00603fff FLASH.Create 1. 0x00220000--0x0023ffff 0x20000 TARGET Byte /EraseALIAS 0x00604000--0x00607fff ; Flash ECC bits FLASH.Create 1. 0x00600000--0x00603fff 0x1000 TARGET Byte /EraseALIAS 0x00200000--0x0021ffff FLASH.Create 1. 0x00604000--0x00607fff 0x4000 TARGET Byte /EraseALIAS 0x00220000--0x0023ffff IF &FlashSize>=0x100000 ( ; Flash FLASH.Create 1. 0x00240000--0x002bffff 0x20000 TARGET Byte /EraseALIAS 0x00608000--0x00617fff ; Flash ECC bits FLASH.Create 1. 0x00608000--0x00617fff 0x4000 TARGET Byte /EraseALIAS 0x00240000--0x002bffff ) ; Flash FLASH.Create 1. 0x002c0000--0x002dffff 0x20000 TARGET Byte /EraseALIAS 0x00618000--0x0061bfff FLASH.Create 1. 0x002e0000--0x002fffff 0x8000 TARGET Byte /EraseALIAS 0x0061c000--0x0061ffff ; Flash ECC bits FLASH.Create 1. 0x00618000--0x0061bfff 0x4000 TARGET Byte /EraseALIAS 0x002c0000--0x002dffff FLASH.Create 1. 0x0061c000--0x0061ffff 0x1000 TARGET Byte /EraseALIAS 0x002e0000--0x002fffff IF &DualPort==0 FLASH.TARGET 0x20000000 0x20002000 0x1000 ~~/demo/arm/flash/byte/f021m3noecc.bin ELSE FLASH.TARGET 0x20000000 EAHB:0x20002000 0x1000 ~~/demo/arm/flash/byte/f021m3noecc.bin /DualPort /STACKSIZE 0x120 ) FLASH.CLocK.AUTO ; Flash ECC bit access MAP.BUS16 0x00600000--0x0061ffff RETURN ; -------------------------------------------------------------------------------- ; Preliminary to unlock empty device UnlockInternalSRAM: LOCAL &tmp &addr &tmp=Data.Long(SD:0x00681000) &addr=0x00200000 RePeaT 9. ( &tmp=Data.Long(SD:&addr) &addr=&addr+4 ) &addr=0x002FFFDC RePeaT 9. ( &tmp=Data.Long(SD:&addr) &addr=&addr+4 ) RETURN ; -------------------------------------------------------------------------------- ; Initialize ECC/parity RAM initRAM: Data.Set SD:0x400FB240 %Long Data.Long(SD:0x400FB240)|0x00000055 ; Initialize C0, C1, C2, C3 RAM's Data.Set SD:0x400FB260 %Long Data.Long(SD:0x400FB260)|0x00000001 ; Initialize MtoC MSG RAM's WAIT Data.Long(SD:0x400FB270)==0x55 WAIT Data.Long(SD:0x400FB288)==0x01 RETURN ; -------------------------------------------------------------------------------- ; Initialize System Clock for the case of empty device initSYSCLK: ON.ERROR GOSUB ( ON.ERROR NOTHING IF STATE.RUN() Break.direct Data.Set SD:0x400FB80C %Long 0x0 Data.Set SD:0x400FB810 %Long 0x0 PRINT "DSLPCLKCFG:DSDIVOVRIDE and M3SSDIVSEL changed to /1 to increase FCLK" FLASH.Program.ALL RETURN ) FLASH.Program.ALL ON.ERROR FLASH.Program.off IF FLASH.CLocK.Frequency()<1000000. ( Data.Set SD:0x400FB80C %Long 0x0 Data.Set SD:0x400FB810 %Long 0x0 PRINT "DSLPCLKCFG:DSDIVOVRIDE and M3SSDIVSEL changed to /1 to increase FCLK" ) RETURN ; -------------------------------------------------------------------------------- ; Initialize RWAIT for flash read waitstate initRWAIT: LOCAL &rwait FLASH.Program.ALL FLASH.Program.off &rwait=FLASH.CLocK.Frequency()/40000000. Data.Set SD:0x400FA000 %Long &rwait<<8. RETURN ; -------------------------------------------------------------------------------- ; Disable flash ECC disableFlashECC: Data.Set 0x400FA600 %Long 0x00 RETURN ; -------------------------------------------------------------------------------- ; Enable flash ECC enableFlashECC: Data.Set 0x400FA600 %Long 0x0A RETURN ; -------------------------------------------------------------------------------- ; Unlock CSM Zone 1 unlockCSMZ1: ; Perform dummy reads of the password locations Data.In SD:0x00200000 /Long Data.In SD:0x00200004 /Long Data.In SD:0x00200008 /Long Data.In SD:0x0020000C /Long ; Write passwords to the KEY registers. 0xFFFFFFFF's are dummy passwords. ; User should replace them with the correct password Data.Set SD:0x400FB400 %Long 0xFFFFFFFF Data.Set SD:0x400FB404 %Long 0xFFFFFFFF Data.Set SD:0x400FB408 %Long 0xFFFFFFFF Data.Set SD:0x400FB40C %Long 0xFFFFFFFF RETURN ; -------------------------------------------------------------------------------- ; Unlock CSM Zone 2 unlockCSMZ2: ; Perform dummy reads of the password locations Data.In SD:0x002FFFF0 /Long Data.In SD:0x002FFFF4 /Long Data.In SD:0x002FFFF8 /Long Data.In SD:0x002FFFFC /Long ; Write passwords to the KEY registers. 0xFFFFFFFF's are dummy passwords. ; User should replace them with the correct password Data.Set SD:0x400FB418 %Long 0xFFFFFFFF Data.Set SD:0x400FB41C %Long 0xFFFFFFFF Data.Set SD:0x400FB420 %Long 0xFFFFFFFF Data.Set SD:0x400FB424 %Long 0xFFFFFFFF RETURN ; -------------------------------------------------------------------------------- ; Unlock ECSL Zone 1 unlockECSLZ1: ; Perform dummy reads of the password locations Data.In SD:0x00200010 /Long Data.In SD:0x00200014 /Long ; Write passwords to the KEY registers. 0xFFFFFFFF's are dummy passwords. ; User should replace them with the correct password Data.Set SD:0x400FB410 %Long 0xFFFFFFFF Data.Set SD:0x400FB414 %Long 0xFFFFFFFF RETURN ; -------------------------------------------------------------------------------- ; Unlock ECSL Zone 2 unlockECSLZ2: ; Perform dummy reads of the password locations Data.In SD:0x002FFFE8 /Long Data.In SD:0x002FFFEC /Long ; Write passwords to the KEY registers. 0xFFFFFFFF's are dummy passwords. ; User should replace them with the correct password Data.Set SD:0x400FB428 %Long 0xFFFFFFFF Data.Set SD:0x400FB42C %Long 0xFFFFFFFF RETURN ; -------------------------------------------------------------------------------- ; Read OTP sector lock in OTP readOTPSECLOCK: ; Perform dummy read Data.In SD:0x00681000 /Long ; Read OTPSECLOCK RETURN ; -------------------------------------------------------------------------------- ; Zone select settings grabSectors: ; Perform dummy read Data.In SD:0x00200018 /Long ; Read Z1_grabSect Data.In SD:0x0020001C /Long ; Read Z1_GRABRAM Data.In SD:0x002FFFE4 /Long ; Read Z2_grabSect Data.In SD:0x002FFFE0 /Long ; Read Z2_GRABRAM RETURN ; -------------------------------------------------------------------------------- ; Read of flash execute-only location Zone 1 readFlashEXEZ1: ; Perform dummy read Data.In SD:0x00200020 /Long RETURN ; -------------------------------------------------------------------------------- ; Read of flash execute-only location Zone 2 readFlashEXEZ2: ; Perform dummy read Data.In SD:0x0027FFDC /Long RETURN ; -------------------------------------------------------------------------------- ; The below is usually performed in the boot ROM, but if during debug, ; Boot ROM execution is bypassed, then the following must be executed DeviceConfig: Data.Set SD:0x400FE004 %Long Data.Long(SD:0x00680430) Data.Set SD:0x400FB900 %Long Data.Long(SD:0x00680410) Data.Set SD:0x400FB904 %Long Data.Long(SD:0x00680414) Data.Set SD:0x400FB930 %Long Data.Long(SD:0x0068042C) Data.Set SD:0x400FE014 %Long Data.Long(SD:0x00680400) Data.Set SD:0x400FE01C %Long Data.Long(SD:0x00680404) Data.Set SD:0x400FE024 %Long Data.Long(SD:0x00680408) Data.Set SD:0x400FE194 %Long Data.Long(SD:0x0068040C) Data.Set SD:0x400FB910 %Long Data.Long(SD:0x00680418) Data.Set SD:0x400FB914 %Long Data.Long(SD:0x0068041C) Data.Set SD:0x400FB918 %Long Data.Long(SD:0x00680420) Data.Set SD:0x400FB91C %Long Data.Long(SD:0x00680424) Data.Set SD:0x400FB920 %Long Data.Long(SD:0x00680428) Data.Set SD:0x400FB8C0 %Long Data.Long(SD:0x400FB8C0)|0x00030001 ; Release C28 from Reset RETURN