Skip to content

Commit d8ad636

Browse files
committed
[core] Allow calling UploadContext.collect_data multiple times
1 parent d237dee commit d8ad636

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

uf2tool/models/context.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ def get_offset(self, part: str, offs: int) -> Optional[int]:
9191
return None
9292
return start + offs
9393

94+
def rewind(self) -> None:
95+
self.seq = 0
96+
9497
def read_next(self, scheme: OTAScheme) -> Optional[Tuple[str, int, bytes]]:
9598
"""
9699
Read next available data block for the specified OTA scheme.
@@ -152,6 +155,10 @@ def collect_data(self, scheme: OTAScheme) -> Optional[Dict[int, BytesIO]]:
152155
if not self.board_name:
153156
raise ValueError("This UF2 is not readable, since no board name is present")
154157

158+
# rewind to the beginning of the UF2 so collect_data can be called
159+
# multiple times
160+
self.rewind()
161+
155162
out: Dict[int, BytesIO] = {}
156163
while True:
157164
ret = self.read_next(scheme)

0 commit comments

Comments
 (0)