• Seems like hotmail /outlook is blocking emails from here so please refrain from using one of these accounts as you may not receive your authorization email.. many thanks

DPC3212 Script SPI

Status
Not open for further replies.

D3m0n

Administrator
Staff member
MyDevice = "DPC3212" #Name of device will work on EPC3212 as well
Imgfile = "images\DPC3212-ISP.jpg" #Name of image


FwBase = 0x20000
FWSize = 4063232
Fw1Base = 0x400000
Fw1Size = 4063232
BootBase = 0x0
BootSize = 65536
CfgBase = 0x10000
CfgSize = 65536
LogBase = 0x7E0000
LogSize = 131072

JTAG.MemoryType("SPI")
SPIFLASH = JTAG.MemoryInit()

t1 = Tab.Create(MyDevice)
t2 = Tab.Create(Imgfile)

Tab(t1).AddGroup("Boot",10,10,100,150)
Tab(t1).AddGroup("Firmware",110,10,100,150)
Tab(t1).AddGroup("Firmware1",210,10,100,150)
Tab(t1).AddGroup("Cfg",310,10,100,150)
Tab(t1).AddGroup("Log",110,180,200,50)
Tab(t1).AddButton("ReadBoot","Read",20,42)
Tab(t1).AddButton("WriteBoot","Write",20,102)
Tab(t1).AddButton("ReadFirmware","Read",120,42)
Tab(t1).AddButton("WriteFirmware","Write",120,102)
Tab(t1).AddButton("ReadFirmware1","Read",220,42)
Tab(t1).AddButton("WriteFirmware1","Write",220,102)
Tab(t1).AddButton("ReadCfg","Read",320,42)
Tab(t1).AddButton("WriteCfg","Write",320,102)
Tab(t1).AddButton("ReadLog","Read",120,192)
Tab(t1).AddButton("WriteLog","Write",220,192)
Tab(t2).AddImage("LOGO",ImgFile,80,30)

CreateEvent(ReadBoot)
Status("Reading the Boot")
Tab(t1).ButtonDisable()
MyData = Memory(SPIFLASH).ReadVerify(BootBase,BootSize)
if (MyData = Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save the firmware"
SaveFile(MyData,Prompt,"Boot.bin")
Status("Successfully read Boot from Flash")
Tab(t1).ButtonEnable()
EndEvent


CreateEvent(WriteBoot)
Tab(t1).ButtonDisable()
Prompt = "Choose a Boot to write into Flash"
MyData = OpenFile(Prompt,"Boot files (*.bin)|*.bin")
if (MyData = Nothing)
goto WriteBootExit
endif
if not (Len(MyData) = BootSize)
Status("Error: File is not the size of the Boot")
goto WriteBootExit
endif
Memory(SPIFLASH).Write(MyData,BootBase,BootSize)
Status("New Boot successfully written")
WriteBootExit:
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(ReadFirmware)
Status("Saving the DPC3212's Firmware")
Tab(t1).ButtonDisable()
MyData = Memory(SPIFLASH).ReadVerify(FwBase,FwSize)
if (MyData = Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save the firmware"
SaveFile(MyData,Prompt,"DPC3212.bin")
Status("Successfully read firmware from Flash")
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(WriteFirmware)
Status("Programming the DPC3212's Firmware")
Tab(t1).ButtonDisable()
Prompt = "Choose a firmware to install"
MyData = OpenFile(Prompt,"Firmware files (*.bin,*.p7)|*.bin;*.p7")
if (MyData = Nothing)
WriteErr = "User cancelled opperation"
goto ExitWriteFwErr
endif
If (HWORD(MyData,0) = 12418) #Remove header if .p7 fw
Writeline("Removing .p7 firmware header")
HeadLen = HWORD(MyData,2) + 52 #increases Headlen by 7
NewLen = Len(MyData) - HeadLen
Resize(MyData,HeadLen,NewLen) #Removes the p7 header

endif
FwLen = Len(MyData)
Memory(SPIFLASH).Write(MyData,FwBase,FwLen)
FwSize = FwLen
Status("New firmware successfully installed")
Tab(t1).ButtonEnable()
Exit
ExitWriteFwErr:
Status(WriteErr)
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(ReadFirmware1)
Status("Saving the DPC3212's Firmware")
Tab(t1).ButtonDisable()
MyData = Memory(SPIFLASH).ReadVerify(Fw1Base,Fw1Size)
if (MyData = Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save the firmware"
SaveFile(MyData,Prompt,"DPC3212_1.bin")
Status("Successfully read firmware1 from Flash")
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(WriteFirmware1)
Status("Programming the DPC3212's Firmware")
Tab(t1).ButtonDisable()
Prompt = "Choose a firmware to install"
MyData = OpenFile(Prompt,"Firmware files (*.bin,*.p7)|*.bin;*.p7")
if (MyData = Nothing)
WriteErr = "User cancelled opperation"
goto ExitWriteFwErr
endif
If (HWORD(MyData,0) = 12418) #Remove header if .p7 fw
Writeline("Removing .p7 firmware header")
HeadLen = HWORD(MyData,2) + 52 #increases Headlen by 7
NewLen = Len(MyData) - HeadLen
Resize(MyData,HeadLen,NewLen) #Removes the p7 header
endif
FwLen = Len(MyData)
Memory(SPIFLASH).Write(MyData,Fw1Base,FwLen)
Fw1Size = FwLen
Status("New firmware successfully installed")
Tab(t1).ButtonEnable()
Exit
ExitWriteFwErr:
Status(WriteErr)
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(ReadCfg)
Status("Reading the Cfg")
Tab(t1).ButtonDisable()
MyData = Memory(SPIFLASH).ReadVerify(CfgBase,CfgSize)
if (MyData = Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save the firmware"
SaveFile(MyData,Prompt,"Cfg.bin")
Status("Successfully read Cfg from Flash")
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(WriteCfg)
Tab(t1).ButtonDisable()
Prompt = "Choose a Cfg to write into Flash"
MyData = OpenFile(Prompt,"Boot files (*.bin)|*.bin")
if (MyData = Nothing)
goto WriteCfgExit
endif
if not (Len(MyData) = CfgSize)
Status("Error: File is not the size of the Boot")
goto WriteCfgExit
endif
Memory(SPIFLASH).Write(MyData,CfgBase,CfgSize)
Status("New Cfg successfully written")
WriteCfgExit:
Tab(t1).ButtonEnable()
EndEvent

CreateEvent(ReadLog)
Status("Reading the Log")
Tab(t1).ButtonDisable()
MyData = Memory(SPIFLASH).ReadVerify(LogBase,LogSize)
if (MyData = Nothing)
Status("Error: data read back failed")
Tab(t1).ButtonEnable()
Exit Event
endif
Prompt = "Choose filename to save the firmware"
SaveFile(MyData,Prompt,"Log.bin")
Status("Successfully read Log from Flash")
Tab(t1).ButtonEnable()
EndEvent


CreateEvent(WriteLog)
Tab(t1).ButtonDisable()
Prompt = "Choose a Log to write into Flash"
MyData = OpenFile(Prompt,"Log files (*.bin)|*.bin")
if (MyData = Nothing)
goto WriteLogExit
endif
if not (Len(MyData) = LogSize)
Status("Error: File is not the size of the Log")
goto WriteLogExit
endif
Memory(SPIFLASH).Write(MyData,LogBase,LogSize)
Status("New Log successfully written")
WriteLogExit:
Tab(t1).ButtonEnable()
EndEvent
 

Attachments

Status
Not open for further replies.
Top