comparison python/stm32.py @ 246:f254b87258e6

Added hexfile to zcc
author Windel Bouwman
date Thu, 25 Jul 2013 08:11:30 +0200
parents 14e739ed03ab
children 7416c923a02a
comparison
equal deleted inserted replaced
245:66912720d712 246:f254b87258e6
25 """ 25 """
26 Implementation of the specifics of the STM32F4xx device series. 26 Implementation of the specifics of the STM32F4xx device series.
27 """ 27 """
28 def __init__(self, iface): 28 def __init__(self, iface):
29 super().__init__(iface) 29 super().__init__(iface)
30
30 def __str__(self): 31 def __str__(self):
31 return 'STM32F4 device size=0x{1:X} id=0x{0:X}'.format(\ 32 return 'STM32F4 device size=0x{1:X} id=0x{0:X}'.format(\
32 self.UID, self.FlashSize) 33 self.UID, self.FlashSize)
34
33 def calculate_F4_sector(self, address): 35 def calculate_F4_sector(self, address):
34 sectorstarts = [] 36 sectorstarts = []
35 a = STM32_FLASH_BASE 37 a = STM32_FLASH_BASE
36 for sectorsize in self.sectorsizes: 38 for sectorsize in self.sectorsizes:
37 sectorstarts.append(a) 39 sectorstarts.append(a)
57 uid_base = 0x1FFF7A10 59 uid_base = 0x1FFF7A10
58 uid1 = self.iface.read_debug32(uid_base) 60 uid1 = self.iface.read_debug32(uid_base)
59 uid2 = self.iface.read_debug32(uid_base + 0x4) 61 uid2 = self.iface.read_debug32(uid_base + 0x4)
60 uid3 = self.iface.read_debug32(uid_base + 0x8) 62 uid3 = self.iface.read_debug32(uid_base + 0x8)
61 return (uid3 << 64) | (uid2 << 32) | uid1 63 return (uid3 << 64) | (uid2 << 32) | uid1
64
62 @property 65 @property
63 def FlashSize(self): 66 def FlashSize(self):
64 f_id = self.iface.read_debug32(0x1FFF7A22) 67 f_id = self.iface.read_debug32(0x1FFF7A22)
65 f_id = f_id >> 16 68 f_id = f_id >> 16
66 return f_id * 1024 69 return f_id * 1024
70
67 @property 71 @property
68 def Running(self): 72 def Running(self):
69 return self.iface.Status == stlink.CORE_RUNNING 73 return self.iface.Status == stlink.CORE_RUNNING
74
70 # flashing commands: 75 # flashing commands:
71 def writeFlash(self, address, content): 76 def writeFlash(self, address, content):
72 flashsize = self.FlashSize 77 flashsize = self.FlashSize
73 pagesize = min(self.sectorsizes) 78 pagesize = min(self.sectorsizes)
74 79
162 print('Done!') 167 print('Done!')
163 print('Speed: {0} bytes/second'.format(size/(t2-t1))) 168 print('Speed: {0} bytes/second'.format(size/(t2-t1)))
164 return image 169 return image
165 170
166 def waitFlashBusy(self): 171 def waitFlashBusy(self):
167 """ block until flash operation completes. """ 172 """ block until flash operation completes. """
168 while self.isFlashBusy(): 173 while self.isFlashBusy():
169 pass 174 time.sleep(0.01)
170 def isFlashLocked(self): 175 def isFlashLocked(self):
171 cr = self.readFlashCr() 176 cr = self.readFlashCr()
172 mask = 1 << FLASH_F4_CR_LOCK 177 mask = 1 << FLASH_F4_CR_LOCK
173 return cr & mask == mask 178 return cr & mask == mask
174 def unlockFlashIf(self): 179 def unlockFlashIf(self):