@@ -121,7 +121,7 @@ def erase_flash(port):
121
121
return True
122
122
123
123
124
- def write_flash (port , start_address , data , retry = 2 ):
124
+ def write_flash (port , start_address , data , retry = 2 , is_wireless = False ):
125
125
data = bytearray (data )
126
126
if len (data ) > 256 :
127
127
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):
139
139
return False
140
140
port .write (c_addr )
141
141
port .flush ()
142
+ time .sleep (0.005 if is_wireless else 0.002 )
142
143
response = port .read (1 )
143
144
debug_response (adr_to_str (c_addr ), response )
144
145
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):
155
156
send_data .insert (0 , len (send_data ) - 1 )
156
157
send_data .append (checksum )
157
158
port .write (send_data )
159
+ port .flush ()
160
+ time .sleep (0.007 if is_wireless else 0.002 )
158
161
response = port .read (1 )
159
162
debug ('STM BL RESPONSE TO WRITE: {}' .format (response ))
160
163
if response is None or len (response ) < 1 or response [0 ] != ACK :
@@ -175,14 +178,14 @@ def chunks(l, n):
175
178
yield l [i :i + n ]
176
179
177
180
178
- def upload_binary (port , file ):
181
+ def upload_binary (port , file , is_wireless = False ):
179
182
address = 0x08000000
180
183
with open (file , 'rb' ) as f :
181
184
data = bytes (f .read ())
182
185
data_segments = [data [x :x + MAX_WRITE_SIZE ] for x in range (0 , len (data ), MAX_WRITE_SIZE )]
183
186
with click .progressbar (data_segments , label = 'Uploading binary to Cortex...' ) as segments :
184
187
for segment in segments :
185
- if not write_flash (port , address , segment ):
188
+ if not write_flash (port , address , segment , is_wireless = is_wireless ):
186
189
return False
187
190
address += 0x100
188
191
return True
0 commit comments