added further exit function, so the board restarts after reset
[pyfrprog.git] / pkernel / kernel.py
index 54a9fd3f351ba07dd2915831ec341a90cdfc79b6..8bf955b377dd0ec822f430910f666829292d0684 100755 (executable)
@@ -9,9 +9,6 @@ KERNEL_BAUDRATE=38400
 
 def recvByte():
        i = tty.read()
-       while len(i)==0:
-               time.sleep(0.03)
-               i = tty.read()
        return ord(i)
 
 def sendByte(byte):
@@ -29,6 +26,15 @@ def sendDWord(dword):
        sendByte((dword >> 16) & 0xFF)
        sendByte((dword >> 24) & 0xFF)
 
+def pkernCHIPERASE():
+       sendByte(0x15)
+       if (recvByte() != 0x45):
+               raise Exception
+       print "wait..."
+       if (recvByte() != 0x23):
+               raise Exception
+       print "Chip erasing done."
+
 def pkernERASE(address, size):
        sendByte(0x12)
        if (recvByte() != 0x11):
@@ -50,18 +56,10 @@ def pkernWRITE(address, size, data):
        sendDWord(address)
        sendWord(size)
 
-       if (recvByte() != 0x04):
-               raise Exception
-       print "Received Metadata."
-
        # write binary stream of data
        for i in range(0, size):
                sendByte(data[i])
 
-       if (recvByte() != 0x08):
-               raise Exception
-       print "Received Data."
-
        if (recvByte() != 0x28):
                raise Exception
        print "Flashing done."
@@ -77,7 +75,7 @@ flashseqs = []
 
 
 print "Initializing serial port..."
-tty = SerialPort(DEVICE, 0, KERNEL_BAUDRATE)
+tty = SerialPort(DEVICE, None, KERNEL_BAUDRATE)
 
 # check command line arguments
 if len(sys.argv) != 2:
@@ -125,14 +123,22 @@ for seq in flashseqs:
 
 
 # let the fun begin!
+"""
 for seq in flashseqs:
        print "Erasing", len(seq.data), "bytes at address", hex(seq.address)
        pkernERASE(seq.address, len(seq.data))
+"""
+print "ChipErase..."
+pkernCHIPERASE()
+
 
 for seq in flashseqs:
        print "Flashing", len(seq.data), "bytes at address", hex(seq.address)
        pkernWRITE(seq.address, len(seq.data), seq.data)
 
-sendByte(0x99);
-
+"""
+sendByte(0x99) #exit and wait
 print "Reset your board now to run code from Flash"
+"""
+
+sendByte(0x97) #exit and restart