Skip to content

Commit 8d6ec04

Browse files
committed
Update TR6260Flasher.cs
1 parent 066f61d commit 8d6ec04

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

BK7231Flasher/Flashers/TR6260Flasher.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,32 @@ bool PrepareSession(bool needUbootProtocol, int? requestedBaudOverride = null)
296296
Thread.Sleep(1000);
297297
}
298298

299+
// If sync failed at DEFAULT_BAUD, a previous session may have left the device in uboot
300+
// at a higher negotiated baud. Try the user's configured baud before giving up.
301+
if(syncResp != TRS_ROM_SYNC_ACK && syncResp != TRS_UBOOT_SYNC_ACK)
302+
{
303+
int fallbackBaud = GetRequestedBaud(requestedBaudOverride);
304+
if(serial != null && fallbackBaud != serial.BaudRate)
305+
{
306+
addLogLine($"Sync failed at {serial.BaudRate}, retrying at {fallbackBaud}...");
307+
serial.BaudRate = fallbackBaud;
308+
for(int loop = 1; loop <= 5; loop++)
309+
{
310+
syncResp = SyncOnce();
311+
if(syncResp == TRS_ROM_SYNC_ACK || syncResp == TRS_UBOOT_SYNC_ACK)
312+
break;
313+
314+
if(sessionPortUnavailable || cancellationToken.IsCancellationRequested)
315+
break;
316+
317+
Thread.Sleep(500);
318+
}
319+
// If fallback also failed, restore default baud for consistent error state
320+
if(syncResp != TRS_ROM_SYNC_ACK && syncResp != TRS_UBOOT_SYNC_ACK)
321+
serial.BaudRate = DEFAULT_BAUD;
322+
}
323+
}
324+
299325
if(syncResp != TRS_ROM_SYNC_ACK && syncResp != TRS_UBOOT_SYNC_ACK)
300326
{
301327
addErrorLine("Sync failed");

0 commit comments

Comments
 (0)