speed = SpeedCalc(size) with open(fout_path, 'wb') as fout: for i in range(0, size, CHUNKSIZE): cur_size = min(CHUNKSIZE, size - i) fout.write(reader(offset, cur_size)) offset += cur_size speed.trigger(cur_size) speed.finish() elif function == 'write': offset, fpath = parse_addr(args[0]), args[1] speed = SpeedCalc(os.stat(fpath).st_size) cnt = 0 with open(fpath) as fin: while True: data = fin.read(CHUNKSIZE) if not data: break cnt += len(data) writer(data, offset) offset += len(data) speed.trigger(len(data)) speed.finish() print '{} bytes written'.format(cnt) elif function == 'erase': start = parse_addr(args[0]) / FLASH_BLOCK_SIZE * FLASH_BLOCK_SIZE stop = start + \ parse_addr(args[1]) / FLASH_BLOCK_SIZE * FLASH_BLOCK_SIZE for i in range(start, stop + 1, FLASH_BLOCK_SIZE): ctl.erase_flash(i) print 'erase {} finished'.format(hex(i))
class SingleStepMemtransController(MemtransController): def _do_write_data(self, data): for i in data: raw_input('write {!r} {} {}'.format(i, hex(ord(i)), bin(ord(i)))) self.ser.write(i) #ctl = SingleStepMemtransController(ser) ctl = MemtransController(ser) for i in range(1, 512): print i ctl.write_flash('\x00' * 20, i * 1024 - 10) ctl.erase_flash(0) for i in range(1, 512): data = ctl.read_flash(i * 1024 - 10, 20) print i, repr(data) #ctl.erase_flash(0) #ctl.write_flash(data, 0) #print repr(ctl.read_flash(0, len(data))) ctl.write_ram(data, 0) #print repr(ctl.read_ram(0, len(data))) #print repr(ctl.read_ram(0, 4)) print repr(ctl.read_ram(0, 32))
ser = serial.Serial('/dev/ttyUSB0', 115201, stopbits=2, parity=serial.PARITY_NONE, timeout=1) class SingleStepMemtransController(MemtransController): def _do_write_data(self, data): for i in data: raw_input('write {!r} {} {}'.format(i, hex(ord(i)), bin(ord(i)))) self.ser.write(i) #ctl = SingleStepMemtransController(ser) ctl = MemtransController(ser) for i in range(1, 512): print i ctl.write_flash('\x00' * 20, i * 1024 - 10) ctl.erase_flash(0) for i in range(1, 512): data = ctl.read_flash(i * 1024 - 10, 20) print i, repr(data) #ctl.erase_flash(0) #ctl.write_flash(data, 0) #print repr(ctl.read_flash(0, len(data))) ctl.write_ram(data, 0) #print repr(ctl.read_ram(0, len(data))) #print repr(ctl.read_ram(0, 4)) print repr(ctl.read_ram(0, 32))