Skip to content

Commit

Permalink
Add progress display to the erase and program processes (since they'r…
Browse files Browse the repository at this point in the history
…e sooo SLOOOWW!)
  • Loading branch information
hugovincent committed Jul 6, 2011
1 parent 2717a4b commit ea0182a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions EFM32.py
@@ -1,4 +1,5 @@
from SWDCommon import *
import sys

class EFM32:
def __init__ (self, debugPort):
Expand Down Expand Up @@ -28,6 +29,7 @@ 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):
self.ahb.writeWord(0x400C0000 + 0x010, 0x200 * i) # MSC_ADDRB <- page address
self.ahb.writeWord(0x400C0000 + 0x00C, 0x00000001) # MSC_WRITECMD.LADDRIM <- 1
Expand All @@ -38,6 +40,11 @@ def flashErase (self, flash_size):
print "waiting for erase completion..."
time.sleep(0.01)
#print "Erased page %d" % i
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)
Expand All @@ -55,11 +62,17 @@ def flashProgram (self, vals):
# 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)
sys.stdout.write(" 0.0 %") ; sys.stdout.flush()
addr = 0
for i in vals:
self.ahb.writeWord(0x400C0000 + 0x010, addr) # MSC_ADDRB <- starting address
self.ahb.writeWord(0x400C0000 + 0x00C, 0x1) # MSC_WRITECMD.LADDRIM <- 1
self.ahb.writeWord(0x400C0000 + 0x018, i) # MSC_WDATA <- data
self.ahb.writeWord(0x400C0000 + 0x00C, 0x8) # MSC_WRITECMD.WRITETRIG <- 1
addr += 0x4
if addr % 0x40 == 0:
sys.stdout.write("\b" * 7)
sys.stdout.write("%5.1f %%" % (25.0 * addr / len(vals)))
sys.stdout.flush()
sys.stdout.write("\b" * 7 + "100.0 %\n")

4 changes: 2 additions & 2 deletions flashEFM32.py
Expand Up @@ -42,10 +42,10 @@ def main():
sys.exit(1)

efm32.halt()
print "Erasing Flash"
efm32.flashUnlock()
print "Erasing Flash...",
efm32.flashErase(flash_size)
print "Programming Flash"
print "Programming Flash...",
efm32.flashProgram(vals)

print "Resetting"
Expand Down

0 comments on commit ea0182a

Please sign in to comment.