Mercurial > lcfOS
diff python/stm32.py @ 256:225f444019b1
Added build and flash menu option
author | Windel Bouwman |
---|---|
date | Sun, 04 Aug 2013 18:32:04 +0200 |
parents | 7416c923a02a |
children | b2f94b4951f1 |
line wrap: on
line diff
--- a/python/stm32.py Sun Aug 04 15:10:10 2013 +0200 +++ b/python/stm32.py Sun Aug 04 18:32:04 2013 +0200 @@ -1,4 +1,5 @@ import time +import logging from devices import Device, registerDevice, STLinkException, Interface import stlink @@ -100,7 +101,7 @@ self.unlockFlashIf() self.writeFlashCrPsiz(2) # writes are 32 bits aligned self.setFlashCrPg() - self.logger.info('writing {0} bytes'.format(len(content)), end='') + self.logger.info('writing {0} bytes'.format(len(content))) offset = 0 t1 = time.time() while offset < len(content): @@ -113,10 +114,10 @@ # Use simple mem32 writes: self.iface.write_mem32(address + offset, chunk) offset += size - print('.', end='', flush=True) + self.logger.info('.') t2 = time.time() - print('Done!') - print('Speed: {0} bytes/second'.format(len(content)/(t2-t1))) + self.logger.info('Done!') + self.logger.info('Speed: {0} bytes/second'.format(len(content)/(t2-t1))) self.lockFlash() # verfify program: self.verifyFlash(address, content) @@ -135,12 +136,14 @@ self.waitFlashBusy() self.clearFlashCrMer() self.lockFlash() + def verifyFlash(self, address, content): device_content = self.readFlash(address, len(content)) ok = content == device_content - print('Verify:', ok) + self.logger.info('Verify: {}'.format(ok)) + def readFlash(self, address, size): - print('Reading {1} bytes from 0x{0:X}'.format(address, size), end='') + self.logger.info('Reading {1} bytes from 0x{0:X}'.format(address, size)) offset = 0 tmp_size = 0x1800 t1 = time.time() @@ -159,14 +162,14 @@ image += mem[:tmp_size] # indicate progress: - print('.', end='', flush=True) + self.logger.info('.') # increase for next piece: offset += tmp_size t2 = time.time() assert size == len(image) - print('Done!') - print('Speed: {0} bytes/second'.format(size/(t2-t1))) + self.logger.info('Done!') + self.logger.info('Speed: {0} bytes/second'.format(size/(t2-t1))) return image def waitFlashBusy(self):