Skip to content

Commit

Permalink
we can readback preloader version
Browse files Browse the repository at this point in the history
  • Loading branch information
RushOnline committed Nov 28, 2012
1 parent a715841 commit 63b72b9
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/readback/readback
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python

import sys
import serial
import os.path
import time
from struct import pack, unpack
from socket import ntohs

class MTKSerial(serial.Serial):

def echo(self, command):
self.flushInput()
self.write(command)
self.flush()
return port.read(len(command))

if __name__ == '__main__':

print 'waiting device connected'
while not os.path.exists('/dev/ttyACM0'):
time.sleep(1)
print '.',
print

port = None
connected = False
while not connected:
print 'opening port'
try:
port = MTKSerial('/dev/ttyACM0', 921600, timeout = 1 )
connected = True
except serial.serialutil.SerialException:
print 'port is busy'

print 'reading startup sequence'
echo = port.read(10)
if 'READY' not in echo:
raise Exception('device not ready')

print 'device ready, trying to be master'

mastered = False
while not mastered:
mastered = port.echo("\xA0") == "\x5F"

print 'device agreed to be slave, completing sequence'
assert port.echo("\x0A") == "\xF5"
assert port.echo("\x50") == "\xAF"
assert port.echo("\x05") == "\xFA"

print 'device communication channel is ok, asking preloader version'
assert port.echo("\xFD") == "\xFD"
version, status = unpack('hh', port.read(4))
print 'status:', ntohs(status)
print 'preloader version reported:', hex(ntohs(version))

0 comments on commit 63b72b9

Please sign in to comment.