summaryrefslogtreecommitdiff
path: root/tools/pydfu.py
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2018-07-30 12:33:44 -0700
committerGitHub <noreply@github.com>2018-07-30 12:33:44 -0700
commita6d94b68453b8535398ff0b61cd6c4a0c7f77f8b (patch)
tree8defd6392975b8145dc11f0cce9c39a4e440b32a /tools/pydfu.py
parent433a29bb70d51abb84c77a911ced43c6ff14706e (diff)
parentb1006170f1dcfa3a9499ef31c19c8f20736b136a (diff)
Merge pull request #1068 from dhalbert/micropython-25ae98f-merge
Micropython 25ae98f merge
Diffstat (limited to 'tools/pydfu.py')
-rwxr-xr-xtools/pydfu.py44
1 files changed, 24 insertions, 20 deletions
diff --git a/tools/pydfu.py b/tools/pydfu.py
index 8c0220de8..a7adda37c 100755
--- a/tools/pydfu.py
+++ b/tools/pydfu.py
@@ -5,7 +5,7 @@
# details.
"""This module implements enough functionality to program the STM32F4xx over
-DFU, without requiringdfu-util.
+DFU, without requiring dfu-util.
See app note AN3156 for a description of the DFU protocol.
See document UM0391 for a dscription of the DFuse file.
@@ -81,6 +81,7 @@ def init():
if len(devices) > 1:
raise ValueError("Multiple DFU devices found")
__dev = devices[0]
+ __dev.set_configuration()
# Claim DFU interface
usb.util.claim_interface(__dev, __DFU_INTERFACE)
@@ -167,7 +168,7 @@ def write_memory(addr, buf, progress=None, progress_addr=0, progress_size=0):
print ("Addr 0x%x %dKBs/%dKBs..." % (xfer_base + xfer_bytes,
xfer_bytes // 1024,
xfer_total // 1024))
- if progress and xfer_count % 256 == 0:
+ if progress and xfer_count % 2 == 0:
progress(progress_addr, xfer_base + xfer_bytes - progress_addr,
progress_size)
@@ -175,7 +176,9 @@ def write_memory(addr, buf, progress=None, progress_addr=0, progress_size=0):
set_address(xfer_base+xfer_bytes)
# Send DNLOAD with fw data
- chunk = min(64, xfer_total-xfer_bytes)
+ # the "2048" is the DFU transfer size supported by the ST DFU bootloader
+ # TODO: this number should be extracted from the USB config descriptor
+ chunk = min(2048, xfer_total-xfer_bytes)
__dev.ctrl_transfer(0x21, __DFU_DNLOAD, 2, __DFU_INTERFACE,
buf[xfer_bytes:xfer_bytes + chunk], __TIMEOUT)
@@ -391,24 +394,25 @@ def get_memory_layout(device):
intf = cfg[(0, 0)]
mem_layout_str = get_string(device, intf.iInterface)
mem_layout = mem_layout_str.split('/')
- addr = int(mem_layout[1], 0)
- segments = mem_layout[2].split(',')
- seg_re = re.compile(r'(\d+)\*(\d+)(.)(.)')
result = []
- for segment in segments:
- seg_match = seg_re.match(segment)
- num_pages = int(seg_match.groups()[0], 10)
- page_size = int(seg_match.groups()[1], 10)
- multiplier = seg_match.groups()[2]
- if multiplier == 'K':
- page_size *= 1024
- if multiplier == 'M':
- page_size *= 1024 * 1024
- size = num_pages * page_size
- last_addr = addr + size - 1
- result.append(named((addr, last_addr, size, num_pages, page_size),
- "addr last_addr size num_pages page_size"))
- addr += size
+ for mem_layout_index in range(1, len(mem_layout), 2):
+ addr = int(mem_layout[mem_layout_index], 0)
+ segments = mem_layout[mem_layout_index + 1].split(',')
+ seg_re = re.compile(r'(\d+)\*(\d+)(.)(.)')
+ for segment in segments:
+ seg_match = seg_re.match(segment)
+ num_pages = int(seg_match.groups()[0], 10)
+ page_size = int(seg_match.groups()[1], 10)
+ multiplier = seg_match.groups()[2]
+ if multiplier == 'K':
+ page_size *= 1024
+ if multiplier == 'M':
+ page_size *= 1024 * 1024
+ size = num_pages * page_size
+ last_addr = addr + size - 1
+ result.append(named((addr, last_addr, size, num_pages, page_size),
+ "addr last_addr size num_pages page_size"))
+ addr += size
return result