Permalink
Browse files

add testflash file, add code to write binfile pagewise, things are no…

…t working yet
  • Loading branch information...
1 parent c1f76ec commit d3f027385417a2bb06da4bd596285addf265d995 @pascalhahn committed Jan 4, 2012
Showing with 41 additions and 11 deletions.
  1. +26 −5 NUC1XX.py
  2. BIN nuc1xx-firmware/blink.bin
  3. +15 −6 test.py
View
@@ -6,6 +6,7 @@
__author__ = 'Pascal Hahn <ph@lxd.bz>'
+import binascii
import SWDCommon
class NotReadyForCommandException(Exception):
@@ -25,6 +26,8 @@ class NUC1XX(object):
ISPCMD_ADDR = 0x5000C00C
ISPTRG_ADDR = 0x5000C010
+ IPRSTC_ADDR = 0x50000008
+
DHCSR_ADDR = 0xE000EDF0
DCRSR_ADDR = 0xE000EDF4
@@ -47,7 +50,7 @@ def step(self):
self.ahb.writeWord(NUC1XX.DHCSR_ADDR, 0xA05F0005)
def reset(self):
- self.ahb.writeWord(NUC1XX.AIRCR_ADDR, 0x05FA0004)
+ self.ahb.writeWord(NUC1XX.IPRSTC_ADDR, 0x01)
def flashUnlock(self):
if self.ahb.readBlock(NUC1XX.REGRWPROT_ADDR, 0x01) != [0x00]:
@@ -64,6 +67,10 @@ def flashUnlock(self):
# enable ISP
self.ahb.writeWord(NUC1XX.ISPCON_ADDR, 0x00000031)
+ def changeBS(self):
+ val = self.ahb.readWord(NUC1XX.ISPCON_ADDR)
+ self.ahb.writeWord(NUC1XX.ISPCON_ADDR, val | 2)
+
def issueISPCommand(self, adr, cmd, data):
if self.ahb.readBlock(NUC1XX.ISPTRG_ADDR, 0x01) != [0x00]:
raise NotReadyForCommandException('not yet ready for command')
@@ -88,10 +95,11 @@ def writeFlash(self, addr, data):
print 'writing %s to %s' % (hex(addr), hex(data))
self.issueISPCommand(addr, 0x21, data)
- def readFlash(self, addr):
- self.issueISPCommand(addr, 0x00, 0x00)
- print 'reading %s: %s' % (
- hex(addr), hex(self.ahb.readWord(NUC1XX.ISPDAT_ADDR)))
+ def readFlash(self, addr, length):
+ for counter in range(0, length, 8):
+ self.issueISPCommand(addr + counter, 0x00, 0x00)
+ print 'reading %s: %s' % (
+ hex(addr + counter), hex(self.ahb.readWord(NUC1XX.ISPDAT_ADDR)))
def eraseFlash(self):
self.issueISPCommand(0x00100000, 0x22, 0x00)
@@ -121,3 +129,16 @@ def readConfig(self):
self.issueISPCommand(NUC1XX.CONFIG0_ADDR, 0x00, 0x00)
print 'readConfig: %s' % hex(
self.ahb.readWord(NUC1XX.CONFIG0_ADDR))
+
+ def writeBinToFlash(self, binstr):
+ start_addr = 0x00100000
+ print 'length: %i' % len(binstr)
+ for counter in range(0, len(binstr), 512):
+ self.writeFlash(
+ start_addr + counter,
+ int('0x%s' % binascii.b2a_hex(binstr[counter:counter + 512]), 16))
+
+def readFlashFile(filename):
+ flashfile = open(filename, 'rb')
+ return flashfile.read()
+
View
Binary file not shown.
View
21 test.py
@@ -1,19 +1,28 @@
#!/usr/bin/python
-import serial
+import NUC1XX
import PirateSWD
+import serial
import SWDCommon
-import NUC1XX
+import sys
import time
+
if __name__ == '__main__':
+ filename = sys.argv[1]
+ flash_data = NUC1XX.readFlashFile(filename)
pirate = PirateSWD.PirateSWD('/dev/ttyUSB0')
debugport = SWDCommon.DebugPort(pirate)
nuc1xx = NUC1XX.NUC1XX(debugport)
nuc1xx.halt()
+ nuc1xx.changeBS()
+ nuc1xx.reset()
+ nuc1xx.flashUnlock()
+ nuc1xx.writeBinToFlash(flash_data)
#nuc1xx.readAllRom()
#nuc1xx.readConfig()
- nuc1xx.flashUnlock()
- nuc1xx.eraseFlash()
- nuc1xx.writeFlash(0x00100000, 0xdeadbeef)
- nuc1xx.readFlash(0x00100000)
+ #nuc1xx.eraseFlash()
+ #nuc1xx.readFlash(0x00000000)
+ #nuc1xx.writeFlash(0x00000000, 0xdeadbeef)
+ nuc1xx.readFlash(0x00100000, len(flash_data))
+ #nuc1xx.readFlash(0x00000000)

0 comments on commit d3f0273

Please sign in to comment.