Mercurial > lcfOS
comparison python/stm32.py @ 255:7416c923a02a
Added more logging
author | Windel Bouwman |
---|---|
date | Sun, 04 Aug 2013 15:10:10 +0200 |
parents | f254b87258e6 |
children | 225f444019b1 |
comparison
equal
deleted
inserted
replaced
254:bd26dc13f270 | 255:7416c923a02a |
---|---|
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 self.logger = logging.getLogger('stm32') | |
30 | 31 |
31 def __str__(self): | 32 def __str__(self): |
32 return 'STM32F4 device size=0x{1:X} id=0x{0:X}'.format(\ | 33 return 'STM32F4 device size=0x{1:X} id=0x{0:X}'.format(\ |
33 self.UID, self.FlashSize) | 34 self.UID, self.FlashSize) |
34 | 35 |
83 if address + len(content) > STM32_FLASH_BASE + flashsize: | 84 if address + len(content) > STM32_FLASH_BASE + flashsize: |
84 raise STLinkException('Flashing above flash size') | 85 raise STLinkException('Flashing above flash size') |
85 if address & 1 == 1: | 86 if address & 1 == 1: |
86 raise STLinkException('Unaligned flash') | 87 raise STLinkException('Unaligned flash') |
87 if len(content) & 1 == 1: | 88 if len(content) & 1 == 1: |
88 print('unaligned length, padding with zero') | 89 self.logger.warning('unaligned length, padding with zero') |
89 content += bytes([0]) | 90 content += bytes([0]) |
90 if address & (pagesize - 1) != 0: | 91 if address & (pagesize - 1) != 0: |
91 raise STLinkException('Address not aligned with pagesize') | 92 raise STLinkException('Address not aligned with pagesize') |
92 # erase required space | 93 # erase required space |
93 sectors = self.calcSectors(address, len(content)) | 94 sectors = self.calcSectors(address, len(content)) |
94 print('erasing {0} sectors'.format(len(sectors))) | 95 self.logger.info('erasing {0} sectors'.format(len(sectors))) |
95 for sector, secsize in sectors: | 96 for sector, secsize in sectors: |
96 print('erasing sector {0} of {1} bytes'.format(sector, secsize)) | 97 self.logger.info('erasing sector {0} of {1} bytes'.format(sector, secsize)) |
97 self.eraseFlashSector(sector) | 98 self.eraseFlashSector(sector) |
98 # program pages: | 99 # program pages: |
99 self.unlockFlashIf() | 100 self.unlockFlashIf() |
100 self.writeFlashCrPsiz(2) # writes are 32 bits aligned | 101 self.writeFlashCrPsiz(2) # writes are 32 bits aligned |
101 self.setFlashCrPg() | 102 self.setFlashCrPg() |
102 print('writing {0} bytes'.format(len(content)), end='') | 103 self.logger.info('writing {0} bytes'.format(len(content)), end='') |
103 offset = 0 | 104 offset = 0 |
104 t1 = time.time() | 105 t1 = time.time() |
105 while offset < len(content): | 106 while offset < len(content): |
106 size = len(content) - offset | 107 size = len(content) - offset |
107 if size > 0x8000: | 108 if size > 0x8000: |