Skip to content

Commit

Permalink
Fix SONOFF chip reset after flashing
Browse files Browse the repository at this point in the history
There's nothing too wacky about the connections on the SONOFF dongle,
it's just that:

    DTR = RESET_N (active low)
    RTS = !DIO_15 (inverted with transistor)

The chip will return to the bootloader after cmdReset if the bootloader
pin is not de-asserted after entering the bootloader. To fix this, this
patch de-asserts the bootloader pin after a delay.
  • Loading branch information
sultanqasim committed Apr 23, 2024
1 parent 0142853 commit 008d90c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cc2538-bsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def invoke_bootloader(self, dtr_active_high=False, inverted=False, sonoff_usb=Fa
# DTR: connected to the bootloader pin
# RTS: connected to !RESET
# If inverted is True, pin connections are the other way round
if inverted:
if inverted or sonoff_usb:
set_bootloader_pin = self.sp.setRTS
set_reset_pin = self.sp.setDTR
else:
Expand All @@ -232,15 +232,16 @@ def invoke_bootloader(self, dtr_active_high=False, inverted=False, sonoff_usb=Fa
# 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
# 1 1 | 0 0
# 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)
set_reset_pin(0) # Enter reset
set_bootloader_pin(1) # Necessary for some reason
set_bootloader_pin(0) # Assert bootloader pin
set_reset_pin(1) # Exit reset
time.sleep(0.002) # Wait for chip to enter bootloader
set_bootloader_pin(1) # De-assert bootloader pin
else:
set_bootloader_pin(1 if not dtr_active_high else 0)
set_reset_pin(0)
Expand Down

0 comments on commit 008d90c

Please sign in to comment.