Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Itead Sonoff CC2652P usb stick bootloader invoke toggle #114

Merged
merged 1 commit into from
Jan 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions cc2538-bsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def open(self, aport=None, abaudrate=500000):

self.sp.open()

def invoke_bootloader(self, dtr_active_high=False, inverted=False):
def invoke_bootloader(self, dtr_active_high=False, inverted=False, sonoff_usb=False):
# Use the DTR and RTS lines to control bootloader and the !RESET pin.
# This can automatically invoke the bootloader without the user
# having to toggle any pins.
Expand All @@ -232,15 +232,32 @@ def invoke_bootloader(self, dtr_active_high=False, inverted=False):
set_bootloader_pin = self.sp.setDTR
set_reset_pin = self.sp.setRTS

set_bootloader_pin(1 if not dtr_active_high else 0)
set_reset_pin(0)
set_reset_pin(1)
set_reset_pin(0)
# Make sure the pin is still asserted when the chip
# comes out of reset. This fixes an issue where
# there wasn't enough delay here on Mac.
time.sleep(0.002)
set_bootloader_pin(0 if not dtr_active_high else 1)
if sonoff_usb:
mdebug(5,'sonoff')
# this bootloader toggle is added specifically for the
# ITead Sonoff Zigbee 3.0 USB Dongle. This dongle has an odd
# connection between RTS DTR and reset and IO15 (imply gate):
# DTR RTS | RST IO15
# 1 1 | 1 1
# 0 0 | 1 1
# 1 0 | 0 1
# 0 1 | 1 0
set_bootloader_pin(0)
set_reset_pin(1)

set_bootloader_pin(1)
set_reset_pin(0)
else:
set_bootloader_pin(1 if not dtr_active_high else 0)
set_reset_pin(0)
set_reset_pin(1)

set_reset_pin(0)
# Make sure the pin is still asserted when the chip
# comes out of reset. This fixes an issue where
# there wasn't enough delay here on Mac.
time.sleep(0.002)
set_bootloader_pin(0 if not dtr_active_high else 1)

# Some boards have a co-processor that detects this sequence here and
# then drives the main chip's BSL enable and !RESET pins. Depending on
Expand Down Expand Up @@ -1021,7 +1038,7 @@ def print_version():

def usage():
print("""Usage: %s [-DhqVfewvr] [-l length] [-p port] [-b baud] [-a addr] \
[-i addr] [--bootloader-active-high] [--bootloader-invert-lines] [file.bin]
[-i addr] [--bootloader-active-high] [--bootloader-invert-lines] [--bootloader-sonoff-usb] [file.bin]
-h, --help This help
-q Quiet
-V Verbose
Expand All @@ -1041,6 +1058,7 @@ def usage():
-i, --ieee-address addr Set the secondary 64 bit IEEE address
--bootloader-active-high Use active high signals to enter bootloader
--bootloader-invert-lines Inverts the use of RTS and DTR to enter bootloader
--bootloader-sonoff-usb Toggles RTS and DTR in the correct pattern for Sonoff USB dongle
-D, --disable-bootloader After finishing, disable the bootloader
--version Print script version

Expand Down Expand Up @@ -1068,6 +1086,7 @@ def usage():
'ieee_address': 0,
'bootloader_active_high': False,
'bootloader_invert_lines': False,
'bootloader_sonoff_usb':False,
'disable-bootloader': 0
}

Expand All @@ -1079,7 +1098,8 @@ def usage():
['help', 'ieee-address=','erase-page=',
'disable-bootloader',
'bootloader-active-high',
'bootloader-invert-lines', 'version'])
'bootloader-invert-lines',
'bootloader-sonoff-usb', 'version'])
except getopt.GetoptError as err:
# print help information and exit:
print(str(err)) # will print something like "option -a not recognized"
Expand Down Expand Up @@ -1121,6 +1141,8 @@ def usage():
conf['bootloader_active_high'] = True
elif o == '--bootloader-invert-lines':
conf['bootloader_invert_lines'] = True
elif o == '--bootloader-sonoff-usb':
conf['bootloader_sonoff_usb'] = True
elif o == '-D' or o == '--disable-bootloader':
conf['disable-bootloader'] = 1
elif o == '--version':
Expand Down Expand Up @@ -1180,7 +1202,8 @@ def usage():
cmd = CommandInterface()
cmd.open(conf['port'], conf['baud'])
cmd.invoke_bootloader(conf['bootloader_active_high'],
conf['bootloader_invert_lines'])
conf['bootloader_invert_lines'],
conf['bootloader_sonoff_usb'])
mdebug(5, "Opening port %(port)s, baud %(baud)d"
% {'port': conf['port'], 'baud': conf['baud']})
if conf['write'] or conf['verify']:
Expand Down