Permalink
Browse files

Some optimizations and more explanatory comments.

  • Loading branch information...
hugovincent committed Jul 8, 2011
1 parent ea0182a commit 38ae0776acd6f689ee4269f13e9543101f6ebcd3
Showing with 9 additions and 21 deletions.
  1. +2 −18 EFM32.py
  2. +2 −2 PirateSWD.py
  3. +5 −1 flashEFM32.py
View
@@ -30,35 +30,19 @@ def flashUnlock (self):
def flashErase (self, flash_size):
# erase page by page
sys.stdout.write(" 0.0 %") ; sys.stdout.flush()
- for i in range(flash_size * 2):
+ for i in range(flash_size * 2): # page size is 512 bytes
self.ahb.writeWord(0x400C0000 + 0x010, 0x200 * i) # MSC_ADDRB <- page address
self.ahb.writeWord(0x400C0000 + 0x00C, 0x00000001) # MSC_WRITECMD.LADDRIM <- 1
self.ahb.writeWord(0x400C0000 + 0x00C, 0x00000002) # MSC_WRITECMD.ERASEPAGE <- 1
- time.sleep(0.03)
- # poll the BUSY bit in MSC_STATUS until it clears
while (self.ahb.readWord(0x400C0000 + 0x01C) & 0x1) == 1:
- print "waiting for erase completion..."
- time.sleep(0.01)
- #print "Erased page %d" % i
+ pass # poll the BUSY bit in MSC_STATUS until it clears
if i % 8 == 0:
sys.stdout.write("\b" * 7)
sys.stdout.write("%5.1f %%" % (100.0 * i / (flash_size * 2)))
sys.stdout.flush()
sys.stdout.write("\b" * 7 + "100.0 %\n")
- # FIXME page-by-page erase is slooooow... implement whole-device erase instead
- # This is done through the AAP (see ref. manual section 6.4)
-
def flashProgram (self, vals):
- ## This is the sequence for block writing... doesn't seem the bus
- ## pirate is fast enough to support this.
- #self.ahb.writeWord(0x400C0000 + 0x010, 0x0) # MSC_ADDRB <- starting address
- #self.ahb.writeWord(0x400C0000 + 0x00C, 0x00000001) # MSC_WRITECMD.LADDRIM <- 1
- #self.ahb.writeWord(0x400C0000 + 0x018, vals[0]) # MSC_WDATA <- vals[0]
- #self.ahb.writeWord(0x400C0000 + 0x00C, 0x10) # MSC_WRITECMD.WRITETRIG <- 1
- #self.ahb.writeBlockNonInc(0x400C0000 + 0x018, vals[1:]) # keep writing data to MSC_WDATA
- #self.ahb.writeWord(0x400C0000 + 0x00C, 0x4) # MSC_WRITECMD.WRITEEND <- 1
-
# Write each word one by one .... SLOOOW!
# (don't bother with checking the busy/status bits as this is so slow it's
# always ready before we are anyway)
View
@@ -21,8 +21,8 @@ def resetBP (self, vreg = False):
if self.port.read(4) != "RAW1":
raise SWDInitError("error initializing bus pirate")
if vreg:
- self.port.write(bytearray([0x48]))
- self.port.write(bytearray([0x63,0x88]))
+ self.port.write(bytearray([0x48])) # enable voltage regulator output
+ self.port.write(bytearray([0x63,0x88])) # set speed to 400 kHz, enable output pins
self.clear(9999)
# this is the fastest port-clearing scheme I could devise
View
@@ -36,7 +36,7 @@ def main():
print "Loading '%s'..." % sys.argv[1],
vals = loadFile(sys.argv[1])
size = len(vals) * 4
- print "loaded %d bytes." % size
+ print "%d bytes." % size
if size / 1024.0 > flash_size:
print "Firmware will not fit into flash!"
sys.exit(1)
@@ -45,8 +45,12 @@ def main():
efm32.flashUnlock()
print "Erasing Flash...",
efm32.flashErase(flash_size)
+ start_time = time.time()
print "Programming Flash...",
efm32.flashProgram(vals)
+ time_passed = time.time() - start_time
+ print "Programmed %d bytes in %.2f seconds (%.2f kB/sec)." % (size,
+ time_passed, (size / 1024.0) / time_passed)
print "Resetting"
efm32.sysReset()

0 comments on commit 38ae077

Please sign in to comment.