Skip to content
This repository was archived by the owner on Jan 31, 2019. It is now read-only.

Commit 6dd0c65

Browse files
committed
Tweak delays for uploading
1 parent 2ad18a9 commit 6dd0c65

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

prosflasher/bootloader.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def erase_flash(port):
121121
return True
122122

123123

124-
def write_flash(port, start_address, data, retry=2):
124+
def write_flash(port, start_address, data, retry=2, is_wireless=False):
125125
data = bytearray(data)
126126
if len(data) > 256:
127127
click.echo('Tried writing too much data at once! ({} bytes)'.format(len(data)))
@@ -139,6 +139,7 @@ def write_flash(port, start_address, data, retry=2):
139139
return False
140140
port.write(c_addr)
141141
port.flush()
142+
time.sleep(0.005 if is_wireless else 0.002)
142143
response = port.read(1)
143144
debug_response(adr_to_str(c_addr), response)
144145
if response is None or len(response) < 1 or response[0] != ACK:
@@ -155,6 +156,8 @@ def write_flash(port, start_address, data, retry=2):
155156
send_data.insert(0, len(send_data) - 1)
156157
send_data.append(checksum)
157158
port.write(send_data)
159+
port.flush()
160+
time.sleep(0.007 if is_wireless else 0.002)
158161
response = port.read(1)
159162
debug('STM BL RESPONSE TO WRITE: {}'.format(response))
160163
if response is None or len(response) < 1 or response[0] != ACK:
@@ -175,14 +178,14 @@ def chunks(l, n):
175178
yield l[i:i + n]
176179

177180

178-
def upload_binary(port, file):
181+
def upload_binary(port, file, is_wireless=False):
179182
address = 0x08000000
180183
with open(file, 'rb') as f:
181184
data = bytes(f.read())
182185
data_segments = [data[x:x + MAX_WRITE_SIZE] for x in range(0, len(data), MAX_WRITE_SIZE)]
183186
with click.progressbar(data_segments, label='Uploading binary to Cortex...') as segments:
184187
for segment in segments:
185-
if not write_flash(port, address, segment):
188+
if not write_flash(port, address, segment, is_wireless=is_wireless):
186189
return False
187190
address += 0x100
188191
return True

prosflasher/ports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def create_serial(port, parity):
4141
# port.port = port_str if port_str != '' else None
4242
port.timeout = 0.5
4343
# port.write_timeout = 5.0
44-
port.inter_byte_timeout = 0.25
44+
port.inter_byte_timeout = 0.2
4545
return port
4646

4747

prosflasher/upload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def upload(port, y, binary, no_poll=False, ctx=proscli.utils.State()):
112112
return False
113113
if not prosflasher.bootloader.erase_flash(port):
114114
return False
115-
if not prosflasher.bootloader.upload_binary(port, binary):
115+
if not prosflasher.bootloader.upload_binary(port, binary, is_wireless=sys_info.is_wireless):
116116
if sys_info.is_wireless:
117117
click.echo('Binary failed to upload. You may now need to upload via a USB connection because too many '
118118
'packets were dropped. Move the joystick closer to the microcontroller for a more reliable '

0 commit comments

Comments
 (0)