libretiny-eu / libretiny

PlatformIO development platform for IoT modules
http://docs.libretiny.eu/
MIT License
382 stars 55 forks source link

BK7231Q WA2 Module effettive support #249

Open dianlight opened 5 months ago

dianlight commented 5 months ago

I have in my hands 3 no-name Tuya switches equipped with the WA2 module on which I can't actually find any information. I anticipate that all the systems for reading or writing the flash have not worked. I tried with "cloudcutter" until soldering but it never seems to respond.

Let me start by saying that I have about 20 conversions from Tuya to ESPHome done with various modules and systems and this is the first time I have come across this type of module and I am stuck with it.

The module is the WA2 equipped with a BK BK7231Q referenced as Tuya but not present on tuya site :(

I haven't found many references online on libretiny that the card exists as supported while on the only forums I've found it seems that some are able to flash but without ever making it work.

Ref: https://www.elektroda.com/rtvforum/topic3929272.html Ref: https://community.home-assistant.io/t/unkown-tuya-chip/153591/17

I'm on the first step... flashing! :(

All my attempts have failed and my doubt is that the bootloader is actually not usable and requires flashing via direct SPI.

Before doing so, however, I would like to understand if the module is actually supported and has anyone managed to use it or not. (in the second case I suggest inserting the note for posterity in the documentation! :) )

Every test with every system result always with the same result:

➜ Firmwares > ltchiptool flash read BK7231Q wifi-switch-module_tiya_orgfw.bin -d /dev/cu.usbserial-0001
I: Connecting to 'Beken 7231Q' on /dev/cu.usbserial-0001 @ 115200
I: Connect UART1 of the BK7231 to the USB-TTL adapter:
I:
I:     --------+        +------------------------
I:          PC |        | BK7231
I:     --------+        +------------------------
I:          RX | ------ | TX1 (GPIO11 / P11)
I:          TX | ------ | RX1 (GPIO10 / P10)
I:         RTS | ------ | CEN (or RST, optional)
I:             |        |
I:         GND | ------ | GND
I:     --------+        +------------------------
I:
I: Make sure to use a good 3.3V power supply, otherwise the adapter might
I: lose power during chip reset. Usually, the adapter's power regulator
I: is not enough and an external power supply is needed (like AMS1117).
I:
I: If you didn't connect RTS to CEN, after running the command you have
I: around 20 seconds to reset the chip manually. In order to do that,
I: you need to bridge CEN to GND with a wire.
E: TimeoutError: Timed out attempting to link with chip
E: |-- File "**/Library/Python/3.9/lib/python/site-packages/bk7231tools/serial/__init__.py", line 42, in connect

or

➜  Firmwares > ltchiptool flash read BK7231Q wifi-switch-module_tiya_orgfw.bin -d /dev/cu.usbserial-0001
I: Connecting to 'Beken 7231Q' on /dev/cu.usbserial-0001 @ 115200
I: Connect UART1 of the BK7231 to the USB-TTL adapter:
I:
I:     --------+        +------------------------
I:          PC |        | BK7231
I:     --------+        +------------------------
I:          RX | ------ | TX1 (GPIO11 / P11)
I:          TX | ------ | RX1 (GPIO10 / P10)
I:         RTS | ------ | CEN (or RST, optional)
I:             |        |
I:         GND | ------ | GND
I:     --------+        +------------------------
I:
I: Make sure to use a good 3.3V power supply, otherwise the adapter might
I: lose power during chip reset. Usually, the adapter's power regulator
I: is not enough and an external power supply is needed (like AMS1117).
I:
I: If you didn't connect RTS to CEN, after running the command you have
I: around 20 seconds to reset the chip manually. In order to do that,
I: you need to bridge CEN to GND with a wire.
E: ValueError: No response received
E: |-- File "/**/Library/Python/3.9/lib/python/site-packages/bk7231tools/serial/protocol.py", line 210, in command
➜  Firmwares > ltchiptool flash read BK7231Q wifi-switch-module_tiya_orgfw.bin -d /dev/cu.usbserial-0001
I: Connecting to 'Beken 7231Q' on /dev/cu.usbserial-0001 @ 115200
E: ValueError: No response received
E: |-- File "/**/Library/Python/3.9/lib/python/site-packages/bk7231tools/serial/protocol.py", line 210, in command

I'have already try to use a banch power supply to power the module.

L.

kuba2k2 commented 5 months ago

BK7231Q is the oldest Beken chip, and is currently unsupported: https://docs.libretiny.eu/docs/status/supported/#feature-support

The Beken "FreeRTOS BDK", which is the (formerly public) SDK used for BK7231T and N chips does only support T and N chips. BK7231Q support would require finding another SDK and writing another LibreTiny core from scratch.

Additionally, the bootloader is buggy and doesn't unprotect flash properly. Linking with the chip requires a power-cycle most of the times.

My post in the mentioned thread: https://www.elektroda.com/rtvforum/viewtopic.php?p=20624538#20624538