Skip to content

Commit

Permalink
Merge pull request #165 from Ayush1325/fix-force-speed
Browse files Browse the repository at this point in the history
fix: check force_speed
  • Loading branch information
JelmerT authored Mar 18, 2024
2 parents eb0f8aa + 70c7cbc commit 0142853
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cc2538-bsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
from subprocess import Popen, PIPE

import sys
import getopt
import glob
import math
import time
Expand All @@ -56,6 +55,9 @@
# Verbose level
QUIET = 5

# Default Baud
DEFAULT_BAUD = 500000

try:
import serial
except ImportError:
Expand Down Expand Up @@ -180,7 +182,7 @@ class CommandInterface(object):
ACK_BYTE = 0xCC
NACK_BYTE = 0x33

def open(self, aport=None, abaudrate=500000):
def open(self, aport=None, abaudrate=DEFAULT_BAUD):
# Try to create the object using serial_for_url(), or fall back to the
# old serial.Serial() where serial_for_url() is not supported.
# serial_for_url() is a factory class and will return a different
Expand Down Expand Up @@ -1050,7 +1052,7 @@ def cli_setup():
parser.add_argument('-r', '--read', action='store_true', help='Read')
parser.add_argument('-l', '--len', type=int, default=0x80000, help='Length of read')
parser.add_argument('-p', '--port', help='Serial port (default: first USB-like port in /dev)')
parser.add_argument('-b', '--baud', type=int, default=500000, help='Baud speed')
parser.add_argument('-b', '--baud', type=int, help=f"Baud speed (default: {DEFAULT_BAUD})")
parser.add_argument('-a', '--address', type=int, help='Target address')
parser.add_argument('-i', '--ieee-address', help='Set the secondary 64 bit IEEE address')
parser.add_argument('--bootloader-active-high', action='store_true', help='Use active high signals to enter bootloader')
Expand All @@ -1065,6 +1067,13 @@ def cli_setup():
if __name__ == "__main__":
args = cli_setup()

force_speed = False

if args.baud:
force_speed = True
else:
args.baud = DEFAULT_BAUD

if args.V:
QUIET = 10
elif args.q:
Expand Down Expand Up @@ -1147,7 +1156,7 @@ def cli_setup():
if not args.address:
args.address = device.flash_start_addr

if args.force_speed != 1 and device.has_cmd_set_xosc:
if not force_speed and device.has_cmd_set_xosc:
if cmd.cmdSetXOsc(): # switch to external clock source
cmd.close()
args.baud = 1000000
Expand Down

0 comments on commit 0142853

Please sign in to comment.