3 from SerialPort_linux import *
5 # serial device to communicate with
7 # baudrate used for initialization
9 # baudrate used for communication after init
12 # contains the last received checksum from a READ, WRITE or CHECKSUM command
16 time.sleep(0.001) # just to get sure, wait 1ms
22 sendByte((word >> 8) & 0xFF)
25 sendByte(dword & 0xFF)
26 sendByte((dword >> 8) & 0xFF)
27 sendByte((dword >> 16) & 0xFF)
28 sendByte((dword >> 24) & 0xFF)
31 return ord(tty.read())
36 last_checksum = recvByte()
37 last_checksum |= (recvByte() << 8)
39 def cmdREAD(address, size):
42 if (recvByte() != 0xF1):
45 if (recvByte() != 0x82):
47 # tell desired address and size
50 # get binary stream of data
52 for i in range(0, size):
53 data.append(recvByte())
58 def cmdWRITE(address, size, data):
61 if (recvByte() != 0xF1):
64 if (recvByte() != 0x83):
66 # tell desired address and size
69 # write binary stream of data
70 for i in range(0, size):
75 def cmdBAUDRATE(baudrate):
78 # send BAUDRATE command
80 if (recvByte() != 0xF1):
83 if (recvByte() != 0x86):
85 # send desired baudrate
86 sendByte(baudrate & 0xFF)
87 sendByte((baudrate >> 8) & 0xFF)
88 sendByte((baudrate >> 16) & 0xFF)
89 sendByte((baudrate >> 24) & 0xFF)
91 print "Initializing serial port..."
92 tty = SerialPort(DEVICE, 100, INIT_BAUDRATE)
94 print "Please press RESET on your 1337 board..."
100 if tty.read() == 'F':
102 except SerialPortException:
103 # timeout happened, who cares ;-)
106 print "OK, trying to set baudrate..."
109 cmdBAUDRATE(REAL_BAUDRATE)
110 tty = SerialPort(DEVICE, 100, REAL_BAUDRATE)
121 # write something to the begin of the IRAM
124 for i in range(0, 0x400):
126 data_wr.append(value)
127 checksum = (checksum + value) % (2**16)
129 print "Calculated checksum:", checksum
130 print "Writing", data_wr, "to the IRAM..."
131 cmdWRITE(0x00030000, len(data_wr), data_wr)
132 print "Received Checksum:", last_checksum
135 print "Reading from the IRAM again..."
136 data_re = cmdREAD(0x00030000, len(data_wr))
137 print "Received data:", data_re, "Checksum:", last_checksum