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

Automatically start BSL mode on ITead SONOFF Zigbee 3.0 USB Dongle Plus stick adapters #11

Closed
Hedda opened this issue Nov 9, 2021 · 7 comments

Comments

@Hedda
Copy link

Hedda commented Nov 9, 2021

Nice with an option to automatically start BSL mode on ITead SONOFF Zigbee 3.0 USB Dongle Plus stick adapters?

https://itead.cc/product/sonoff-zigbee-3-0-usb-dongle-plus/

ITead SONOFF Zigbee 3.0 USB Dongle Plus has a metal enclosure so currently the user need to remove screws to open it in order to access the BOOT button to activate BSL mode. Would be great if couyld activate BSL mode via software instead.

https://electrolama.com/radio-docs/bsl/#auto-bsl

At least automatic boot to bootloader is currently not working with the SONOFF Zigbee 3.0 USB Dongle Plus from ITead (and the main difference with it compared to zzh or zzhp is that the Sonoff USB Plus dongle is using CP2102N USB-to-UART bridge chip).

So today Auto BSL is not working in llama-bsl (or cc2538-bsl) with this Sonoff USB Plus dongle, but a modified uartLog.py script attached in Sonoff doc manages to automatically enter BSL mode without the user having to manually enter whether the script should use active high signals to enter bootloader or inverts the use of RTS and DTR to enter bootloader (i.e. both active low). So we at least know that the Sonoff USB Plus dongle hardware does support Auto BSL.

https://sonoff.tech/wp-content/uploads/2021/09/Zigbee-3.0-USB-dongle-plus-firmware-flashing-1-1.docx

Attatched: uartLog.zip

I have confirmed that running the attached uartLog.py script does indeed make ITead's Sonoff Zigbee 3.0 Plus adapter enter bootloader mode and after that I could flash it directly with llama-bsl.py -p COM5 -b 115200 -evw CC1352P2_CC2652P_launchpad_coordinator_20210708.hex without having open its enclosure and pressing the BRL button which I think is very convenient. The script also lists all active COM ports on MS Windows (tested on Windows 10) and have you enter the number of the COM port, but note that the script is hardcoded for Windows COM ports.


""" 测试mcu进入boot """


def setDTRState(serialPort, state):
    serialPort.setDTR(state)


def setRTSState(serialPort, state):
    serialPort.setRTS(state)
    # Work-around for adapters on Windows using the usbser.sys driver:
    # generate a dummy change to DTR so that the set-control-line-state
    # request is sent with the updated RTS state and the same DTR state
    # 为了绕过Windows系统下驱动的问题,同时更新 RTS 和 DTR状态
    serialPort.setDTR(serialPort.dtr)


def enterBoot(serialPort, delay=False):
    # delay is a workaround for bugs with the most common auto reset
    # circuit and Windows, if the EN pin on the dev board does not have
    # enough capacitance.
    # 如果开发板上EN管脚没有足够电容
    last_error = None

    # issue reset-to-bootloader:
    # RTS = either CH_PD/EN or nRESET (both active low = chip in reset
    # DTR = GPIO0 (active low = boot to flasher)
    #
    # DTR & RTS are active low signals,
    # ie True = pin @ 0V, False = pin @ VCC.
    setDTRState(serialPort, False)  # IO0=HIGH
    # setDTRState(serialPort, True)   # IO0=LOW
    setRTSState(serialPort, True)  # EN=LOW, chip in reset
    time.sleep(0.1)
    if delay:
        # Some chips are more likely to trigger the esp32r0
        # watchdog reset silicon bug if they're held with EN=LOW
        # for a longer period
        time.sleep(1.2)

    setDTRState(serialPort, True)  # IO0=LOW
    setRTSState(serialPort, False)  # EN=HIGH, chip out of reset
    if delay:
        # Sleep longer after reset.
        # This workaround only works on revision 0 ESP32 chips,
        # it exploits a silicon bug spurious watchdog reset.
        time.sleep(0.4)  # allow watchdog reset to occur
    time.sleep(1)

    setDTRState(serialPort, False)  # IO0=HIGH, done
    setRTSState(serialPort, False)
    time.sleep(1)

    return last_error
@Hedda
Copy link
Author

Hedda commented Nov 17, 2021

Please see discussion in upstream cc2538-bsl by JelmerT here -> JelmerT#113

@omerk
Copy link

omerk commented Nov 19, 2021

Hi @Hedda, I don't have that hardware so can't really test it here.

I'll happily merge a PR from someone who can, as long as it doesn't disturb the operation of all the other boards.

@omerk omerk added the help wanted Extra attention is needed label Nov 19, 2021
@JelmerT
Copy link

JelmerT commented Nov 26, 2021

I added a PR that should support this HW JelmerT#114

@Hedda
Copy link
Author

Hedda commented Dec 6, 2021

I added a PR that should support this HW JelmerT#114

@omerk Maybe adapter model USB discovery as discussed in #9 could be used to automatically enable that "sonoff" parameter?

FYI, ITead said they would add a unique Product Description String in future batches but there is, unfortunately, no news on it yet.

That is, got a reply from ITead that they will write to EEPROM in CP2102N to change the default “CP2102 USB to UART Bridge Controller” text in the Product Description String value field to "Sonoff Zigbee 3.0 USB Dongle Plus” in their next batch of dongles.

@Hedda Hedda changed the title Add option for Auto BSL to try both high and low signals to enter bootloader? Automatically start BSL mode on ITead SONOFF Zigbee 3.0 USB Dongle Plus stick adapters Dec 13, 2021
@Hedda
Copy link
Author

Hedda commented Dec 13, 2021

FYI, ITead said they would add a unique Product Description String in future batches but there is, unfortunately, no news on it yet.

That is, got a reply from ITead that they will write to EEPROM in CP2102N to change the default “CP2102 USB to UART Bridge Controller” text in the Product Description String value field to “Sonoff Zigbee 3.0 USB Dongle Plus” in their next batch of dongles.

FYI, ITead now posted a script that should let users themselves update the product description string value to “Sonoff Zigbee 3.0 USB Dongle Plus” on already shipped Sonoff dongles to supposedly match the same description already written to CP2102N EEPROM the latest batch of their dongles:

https://www.facebook.com/SONOFF.official/posts/2927251720919807

Tested that program myself on a Windows 10 computer and it did not work for me (program just closed without any messages).

Sad that ITead did not instead choose to release a script tool based on this open-source cp210x-program by VCTLabs:

https://github.com/VCTLabs/cp210x-program

Again, the point of having a custom product description in USB-to-UART chip is to allow USB auto-discovery, like the example in:

https://community.home-assistant.io/t/community-help-wanted-to-whitelist-all-compatible-zigbee-and-z-wave-usb-adapters-for-automatic-discovery-in-home-assistant-os/344412

@Hedda
Copy link
Author

Hedda commented Jan 20, 2022

@omerk JelmerT has now merged JelmerT#114 so wondering if could update this patch from upstream cc2538-bsl to llama-bsl?

JelmerT#114

JelmerT#118

Off-topic; FYI, while merged there is not yet a new release version of cc2538-bsl on GitHub or PyPI so not easy for users to get it:

JelmerT#89

JelmerT#103

@omerk
Copy link

omerk commented Mar 28, 2023

We don't have plans to add this on llama-bsl as we are focusing on customisations for Electrolama designs but happy to accept a PR if anyone were to raise it.

@omerk omerk closed this as completed Mar 28, 2023
@omerk omerk removed the help wanted Extra attention is needed label Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants