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

Support for RTL8710CM? #44

Open
craggyh opened this issue Nov 23, 2022 · 60 comments
Open

Support for RTL8710CM? #44

craggyh opened this issue Nov 23, 2022 · 60 comments
Labels
new platform About support for new chips/platforms

Comments

@craggyh
Copy link

craggyh commented Nov 23, 2022

Is there support for RTL8710CM yet?
I have a couple of devices (Tapo L920 LED controllers) using this chip and would love to be able to flash them with libretuya/esphome.

@kuba2k2
Copy link
Member

kuba2k2 commented Nov 23, 2022

No, not yet. See #37 and #36.

@Nold360
Copy link

Nold360 commented May 11, 2023

anything we can do to push support forward? idk what's missing/required :(

@kuba2k2
Copy link
Member

kuba2k2 commented May 11, 2023

Not really, unless you either know C/C++ well and are comfortable working in crappy vendor SDKs, or can buy me more time 😄

@Rain
Copy link

Rain commented Jul 24, 2023

I've successfully compiled and ran the PinScan example (amazingly helpful, btw!) and flashed libretiny-esphome on a RTL8710CM with your recent changes.

Everything I was able to test seems to work using the generic-rtl8720cf-2mb-992k board (with the exception of esphome OTAs, but it doesn't look like OTAs are implemented for any of the libretiny-supported RTL MCUs at the moment). The boards I'm playing with (TP-Link EP25/KP125 Smart Plugs) are extremely simple though so outside of WiFi & GPIOs there isn't much. Only minor issue is I cannot seem to read the onboard BL0937 (see: HLW8012). I might have it configured incorrectly, though; I need follow the traces again and/or try interfacing directly instead of using esphome.

It seems compiling a project with PlatformIO and/or libretiny doesn't pull in the AT command CLI from the SDK. Is there a configuration option and/or flag I've glossed over that enables it? This would allow use of the built-in OTA functionality. I had to flash the flash.bin image directly onto the SPI flash because the EP25s refuse to go into UART download mode (even after flashing a libretiny-built project).

@kuba2k2
Copy link
Member

kuba2k2 commented Jul 24, 2023

RTL8720C only has very draft support. Some people (incl. me) have reported ESPHome to work, but not stable.

OTA is implemented for Beken and RTL8710B - only RTLC doesn't support it at present.

The AT CLI is a default "demo" application of the SDK - it isn't (and won't be) available in LibreTiny. The built-in OTA functionality is very basic and also will not be supported. Instead, UF2 OTA will be implemented (at some point...), just like on Beken and the other Realtek. This is a universal and safe format that we're using for everything in LibreTiny.

Download mode hasn't been documented yet (as in: very draft support), but can be activated by pulling PA0 and PA13 to 3.3V, and resetting the chip/power cycling while doing that. It takes a few attempts to do so, but gets easy after you get it.

Note: after you first flash LT, download mode can be entered automatically (or by sending ping\n on UART2). That's not tested well enough, and from my attempts writing has been failing sometimes in this mode.

As for the BL0937, see https://upk.libretiny.eu/ - find a plug with power monitoring, generate a YAML for it, and see which pins usually need the invert: true flag.

@Rain
Copy link

Rain commented Jul 24, 2023

Thanks for the information!

Yes, I realized support for the RTL8720C family is in the very early stages. Just figured I'd report my findings.

That makes sense regarding the AT CLI. Since the stock TP-Link EP25 had it I assumed it was standard and always built w/ the RTL MCUs. Their firmware must be based off the "demo" (which makes sense, I guess).

A quick perusal through their stock firmware revealed that there seems to be a way to trigger the SDK-included OTA function remotely. It may be possible replace the stock firmware on these smart plugs wirelessly without opening them up! 😎

I'll poke around some more with download mode. I've tried ping\n on UART2 but I wasn't aware of the PA0/PA13 combination. These EP25 plugs are hard enough to get open so anything that makes re-flashing easier will be helpful.

@kuba2k2
Copy link
Member

kuba2k2 commented Jul 24, 2023

Eventually OTA will be supported.

Have you dumped the original firmware prior to flashing? If yes, you can always mess with it by just flashing it back.

@asozio
Copy link

asozio commented Oct 20, 2023

I've got a couple of tp-link KP115 Kasa Smart Wi-Fi Plug (slim energy monitoring) which appear to contain RTL8710CF modules (12-pin pcb mounted through hole on the main board)

20231020_191713
20231020_190758
20231020_194117
20231020_194914

I'm keen to test these out with libretiny if someone has some pointers for how I get started?

@kuba2k2
Copy link
Member

kuba2k2 commented Oct 20, 2023

As indicated in this thread (and in LibreTiny docs -> boards, chips, features) RTL8720C is not yet fully supported. Thus, the documentation pages are also not fully written.

@asozio
Copy link

asozio commented Oct 20, 2023

Kinda why I was asking here ;-)

I'm an out of practice embedded C/C++ developer who is willing to have a play with it, but thought rather than re-doing work that's already been done I'd ask the question.

@nmschulte
Copy link

I was playing with a Tuya WBR3-laden ME81H (thermostat for a heater). I see above documentation that I found from this page during my trials: https://developer.tuya.com/en/docs/iot/burn-and-authorize-wbr-series-modules?id=Ka78imt8pf85p#title-7-Method%202%3A%20Separated%20solutions%20for%20flashing%20and%20authorization

After fixing up ltchiptool to support Linux (libretiny-eu/ltchiptool#13), I was able to dump the OEM Flash and ROM, and to burn a build of ESPHome/generic-rtl8720cf-2mb-992k to the module. Booting this image however is troublesome; I run into a bootloader verification failure, and so booting halts:

INFO Starting log output from /dev/ttyACM1 with baud rate 115200
[19:48:39]
[19:48:39]== Rtl8710c IoT Platform ==
[19:48:39]Chip VID: 5, Ver: 3
[19:48:39]ROM Version: v3.0
[19:48:39]
[19:48:39]== Boot Loader ==
[19:48:39]Dec  5 2019:14:02:18
[19:48:39]
[19:48:39]fwx SELE[fffffffe]
[19:48:39]fw SELE Bitidx 1, fw1 valid 0, sn 0, fw2 valid 1, sn 1
[19:48:39]fw2 USE, return sn 1
[19:48:40]
[19:48:40]== Rtl8710c IoT Platform ==
[19:48:40]Chip VID: 5, Ver: 3
[19:48:40]ROM Version: v3.0
[19:48:40]
[19:48:40]== Boot Loader ==
[19:48:40]Dec  5 2019:14:02:18
[19:48:40]
[19:48:40]fwx SELE[fffffffe]
[19:48:40]fw SELE Bitidx 1, fw1 valid 0, sn 0, fw2 valid 1, sn 1
[19:48:40]fw2 USE, return sn 1
[19:48:40][MISC Err]Hash Result Incorrect!
[19:48:40]Boot Load Err!

Comparing the dumped images, it seems the initial (and trailing?) portions of Flash are the same; I see "hash" related strings at the same offsets (I have not poked with Ghidra yet, lacking the time currently).

I wonder if using the Tuya "RTL8720CF chip burning tool" would program the correct hash, or if this has been reversed yet?

Download and run the RTL8720CF chip burning tool."

Anyway, it seems I'm at a dead end with this board, and support is in progress, so kudos for everything so far and in the works. In the mean time, I've ordered an ESP32-C3-12F module to replace this unit (which seems to operate fine without the Tuya module installed, in case anyone needed to know).

As such, let me know if there's anything I can test or help reverse to support the Tuya WBR3/RTL8720CF.

@kuba2k2
Copy link
Member

kuba2k2 commented Nov 2, 2023

@nmschulte
I can look into this if you post the OEM firmware dump - it contains the hash keys, so that I can check if they are the same as used in LT.

@nmschulte
Copy link

I can look into this if you post the OEM firmware dump

me81h_16-wbr3-oem-dump.tar.gz

@kuba2k2
Copy link
Member

kuba2k2 commented Nov 2, 2023

This firmware uses OTA1 address of 0x10000, while the board you've chosen has it at 0xC000 - it's incompatible with WBR3.

As you've noticed, support is in progress. The WBR3 board (with correct offsets) is available in feature/realtek-update branch of LibreTiny. If you checkout that branch (I believe you can use version: dev under framework: and then add source: https://github.com/libretiny-eu/libretiny#feature/realtek-update, or something similar) you'll be able to use board: wbr3.

That being said, when RTL8720CF support rolls out, it will automatically adjust flash addresses to match the chosen board code (same will be done for RTL8710BN shortly).

@nmschulte
Copy link

The WBR3 board (with correct offsets) is available in feature/realtek-update

You rock. I'll give it a whirl.

@nmschulte
Copy link

nmschulte commented Nov 2, 2023

You rock. I'll give it a whirl.

Success!

INFO Successfully uploaded program.
INFO Starting log output from /dev/ttyACM1 with baud rate 115200
[12:10:22]
[12:10:22]Boot Loader <==
[12:10:22]
[12:10:22]== RAM Start ==
[12:10:22]I [      0.000] LibreTiny v1.4.1+sha.d41d328 on wbr3, compiled at Nov  2 2023 11:53:56, GCC 10.3.1 (-Os)
[12:10:33]Interface 0 IP address : 192.168.1.176[I][wifi:560]: WiFi Connected!
[12:10:33][D][wifi:569]: Disabling AP...
[12:10:33][C][ota:097]: Over-The-Air Updates:
[12:10:33][C][ota:098]:   Address: thermostat.local:8892
[12:10:33][C][api:025]: Setting up Home Assistant API server...
[12:10:33][I][app:062]: setup() finished successfully!
[12:10:33][I][app:102]: ESPHome version 2023.11.0-dev compiled on Nov  2 2023, 11:51:43
[12:10:33][C][lt.component:013]: LibreTiny:
[12:10:33][C][lt.component:014]:   Version: v1.4.1+sha.d41d328 on wbr3, compiled at Nov  2 2023 11:51:25, GCC 10.3.1 (-Os)
[12:10:33][C][lt.component:015]:   Loglevel: 3
[12:15:22][I][ota:117]: Boot seems successful, resetting boot loop counter.
[12:15:22][D][lt.preferences:104]: Saving 1 preferences to flash...
[12:15:22][D][lt.preferences:132]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed

WiFi shortly there-after disassociated but subsequently reconnected:

[12:15:48]wifi link err:001f0002
[12:15:48]dissconn reason code: 4
[12:15:48]receive deassoc
[12:15:48]handshake done, connected stage, recv deauth/deassoc
[12:15:52]Interface 0 IP address : 192.168.1.176[W][component:214]: Component wifi took a long time for an operation (4.33 s).
[12:15:52][W][component:215]: Components should block for at most 20-30ms.
[12:15:52][I][wifi:560]: WiFi Connected!
[12:15:52][D][wifi:569]: Disabling AP...
[12:15:52][W][component:214]: Component wifi took a long time for an operation (0.06 s).
[12:15:52][W][component:215]: Components should block for at most 20-30ms.

And later, after another (minutes after) diss-/re-assoc; perhaps this is expected, as I'm unfamiliar w/ ESPHome and didn't do anything but let the code run:

[12:25:33][E][api:128]: No client connected to API. Rebooting...
[12:25:33][I][app:127]: Forcing a reboot...
[12:25:33]trace task is needed to print trace log
[12:25:33]hci_uart_deinit: deinit c}ll twice
[12:25:33]
[12:25:33]== Rtl8710c IoT Platform ==
[12:25:33]Chip VID: 5, Ver: 3
[12:25:33]ROM Version: v3.0
[12:25:33]Test Mode: boot_cfg1=0x20
[12:25:33]Download Image over UART2[tx=16,rx=15] baud=115200

@nmschulte
Copy link

nmschulte commented Nov 2, 2023

If you checkout that branch (I believe you can use version: dev under framework: and then add source: https://github.com/libretiny-eu/libretiny#feature/realtek-update, or something similar) you'll be able to use board: wbr3.

Initially, I hacked my way through this, unaware that I could specify these things in the device YAML; I platformio install'd the libretiny branch, and then manually ran generate_components.py and patched ltchiptool. But, to use this mechanism, one must specify like so in the device YAML, to have PlatformIO/ESPHome automatically pull the correct version:

rtl87xx:
  board: wbr3
  framework:
    version: 0.0.0
    source: https://github.com/libretiny-eu/libretiny.git#feature/realtek-updates

Mainly, version needs to be a proper semver, and cannot match something listed in ARDUINO_VERSIONS, otherwise this error arises:

Framework version needs to be explicitly specified when custom source is used.

It seems the trend is to use a version: 0.0.0 spec in this kind of scenario.

I guess ltchiptool could be installed in the same way w/ platformio install https://github.com/libretiny-eu/ltchiptool.git#feature/flasher-update (or perhaps pip install git+https://github.com/libretiny-eu/ltchiptool.git#feature/flasher-update); I still manually patched whichever instance is in use.

@nmschulte
Copy link

nmschulte commented Nov 3, 2023

Also, it seems the firmware insists on outputting to UART2 (LOG_TX / LOG_RX), messages from WiFi driver:
[Driver]: ....

As well, I can't seem to configure ESPHome to output on the other exposed UART (TXD / RXD; 13 and 14 I believe). This is stumping me.

@nmschulte
Copy link

nmschulte commented Nov 3, 2023

After modifying libretiny to define PIN_SERIAL0_RX and PIN_SERIAL0_TX, I now have a Tuya Climate device working seemingly well on the WBR3. Kudos!

@kuba2k2
Copy link
Member

kuba2k2 commented Nov 3, 2023

UART2 is the default port for log messages, same applies for Tuya firmware. Why did you need to change it, and how did you try to do so?
Setting LT_UART_DEFAULT_PORT to 0 or 1 should redirect all UART output to that port. If you need to get rid of the WiFi messages specifically, try using LT_UART_SILENT_ALL.

PS I notice that PIN_SERIAL0_RX_0 is defined instead; this is because WBR3 has two GPIOs which can be used as Serial0 pins. i assume that your issue is that Serial0 is not defined because of the additional _0 suffix. This has been fixed on feature/i2c-spi branch already, and thus will be available on the master branch at some point.

@nmschulte
Copy link

nmschulte commented Nov 3, 2023

UART2 is the default port for log messages, same applies for Tuya firmware. Why did you need to change it, and how did you try to do so?

I didn't need to change the logging UART. Though, because I was unable to use the other UARTS (HW_UART1 and HW_UART2, because the hardcoded checks against PIN_SERIALn_RX/..._TX, which seem to default to -1/255), I did try disabling the logging and connect this UART (HW_UART2) to the Tuya comm interface ... but because the WBR3 firmware/driver outputs to/configures it regardless, this failed (ME81H seems to require 9600 baud, as well).

Then, I noticed in the debug output that the UART0 and UART1 RX/TX pins were outputting as -1/255 (due to falling into SoftwareSerial) and so discovered the issue that feature/i2c-spi purportedly resolves; I couldn't find any uses of PINS_SERIALn_..., and so just jammed in PIN_SERIAL0_... with 13 and 14, and then ESPHome/LT picked up the Tuya uart: YAML and configured the correct UART for Tuya comms (UART0; WBR3 TXD/RXD pins).

diff --git a/boards/variants/wbr3.h b/boards/variants/wbr3.h
index 40f6595..d40a1d5 100644
--- a/boards/variants/wbr3.h
+++ b/boards/variants/wbr3.h
@@ -28,8 +28,10 @@
 // ------------
 #define PIN_SERIAL0_RX_0 12u // PIN_A12
 #define PIN_SERIAL0_RX_1 13u // PIN_A13
+#define PIN_SERIAL0_RX   13u // PIN_A13
 #define PIN_SERIAL0_TX_0 11u // PIN_A11
 #define PIN_SERIAL0_TX_1 14u // PIN_A14
+#define PIN_SERIAL0_TX   14u // PIN_A14
 #define PIN_SERIAL1_CTS  4u  // PIN_A4
 #define PIN_SERIAL1_RX_0 2u  // PIN_A2
 #define PIN_SERIAL1_RX_1 0u  // PIN_A0

Setting LT_UART_DEFAULT_PORT to 0 or 1 should redirect all UART output to that port. If you need to get rid of the WiFi messages specifically, try using LT_UART_SILENT_ALL.

The build is already proceeding w/ these defines, yet the WiFi output still persists. This is not an issue though as it's on the logging UART:
-DLT_UART_SILENT_ALL=1, -DLT_UART_SILENT_ENABLED=1

@ferbulous
Copy link

Hi @nmschulte just wondering how stable is LT running on the thermostat since?

@uioi
Copy link

uioi commented Dec 16, 2023

I have a TP-Link Tapo P100 smart plug which has a RTL8720CF. Tried board:generic-rtl8720cf-2mb-992k, got the "Hash result incorrect" message on boot. Then I tried board: WBR3 with the following:

rtl87xx:
  board: wbr3
  framework:
    version: 0.0.0
    source: https://github.com/libretiny-eu/libretiny.git#feature/realtek-updates

The device can boot and connect to WiFi. But I can't switch the relay on. I tried all GPIO from 0 to 23. None of them switch on the relay or the LED indicator.

Any thoughts?

@nmschulte
Copy link

nmschulte commented Dec 16, 2023

Any thoughts?

https://www.youtube.com/watch?v=P8cm8HFuG6s
2023-12-15_20h05m56s_screenshot
2023-12-15_20h05m48s_screenshot
image

Though it looks like it may differ by specific model, though I expect the GPIO is the same (no idea why they'd change it): https://www.youtube.com/watch?v=99iAK1JeAeo

@uioi
Copy link

uioi commented Dec 16, 2023

Did you make it work with ESPhome? What is your gpio configuration for the relay, LED, and button?

@uioi
Copy link

uioi commented Dec 17, 2023

I've successfully compiled and ran the PinScan example (amazingly helpful, btw!) and flashed libretiny-esphome on a RTL8710CM with your recent changes.

Everything I was able to test seems to work using the generic-rtl8720cf-2mb-992k board (with the exception of esphome OTAs, but it doesn't look like OTAs are implemented for any of the libretiny-supported RTL MCUs at the moment). The boards I'm playing with (TP-Link EP25/KP125 Smart Plugs) are extremely simple though so outside of WiFi & GPIOs there isn't much. Only minor issue is I cannot seem to read the onboard BL0937 (see: HLW8012). I might have it configured incorrectly, though; I need follow the traces again and/or try interfacing directly instead of using esphome.

It seems compiling a project with PlatformIO and/or libretiny doesn't pull in the AT command CLI from the SDK. Is there a configuration option and/or flag I've glossed over that enables it? This would allow use of the built-in OTA functionality. I had to flash the flash.bin image directly onto the SPI flash because the EP25s refuse to go into UART download mode (even after flashing a libretiny-built project).

How can you use pinscan? I want to find the correct pin in a TP-Link Tapo P100 smart plug which has a RTL8720CF.

@Rain
Copy link

Rain commented Dec 19, 2023

How can you use pinscan? I want to find the correct pin in a TP-Link Tapo P100 smart plug which has a RTL8720CF.

Ensure you have PlatformIO installed. Review the Quick Start Guide if you haven't used PlatformIO directly before.

Clone the PinScan repo. Edit src/pinscan.h and change USE_WIFI to 1 and enter your WiFi information into WIFI_SSID/WIFI_PASS. Add the following to platformio.ini:

[env:rtl8720cf]
board = generic-rtl8720cf-2mb-992k

You should then be able to build by running pio run -e rtl8720cf. Flash the firmware to the device you're working with. Let it connect to your WiFi network (monitor your DHCP server to figure out what IP address it got). You should then be able to telnet into the device and use PinScan as described in the README.

Be careful what pins you manipulate arbitrarily, though. Don't have the device plugged into the mains when manipulating it. Power the 3.3v rail only (as you would when flashing). There may be pin configurations that damage/break the device; I'd highly recommend tracing the PCB traces as much as possible before switching random pins to OUTPUT and toggling them on and off.


As an aside, how difficult was it to get into the TP-Link Tapo P100? The TP-Link EP25/KP125 Smart Plugs were an absolute pain to open without causing visible damage. Maybe with practice you could do it. They seem like great plugs that are well-built. With libretiny, Esphome seems to run great. I'm waiting on OTA support before I can really start using them, though.

@uioi
Copy link

uioi commented Dec 19, 2023

How can you use pinscan? I want to find the correct pin in a TP-Link Tapo P100 smart plug which has a RTL8720CF.

Ensure you have PlatformIO installed. Review the Quick Start Guide if you haven't used PlatformIO directly before.

Clone the PinScan repo. Edit src/pinscan.h and change USE_WIFI to 1 and enter your WiFi information into WIFI_SSID/WIFI_PASS. Add the following to platformio.ini:

[env:rtl8720cf]
board = generic-rtl8720cf-2mb-992k

You should then be able to build by running pio run -e rtl8720cf. Flash the firmware to the device you're working with. Let it connect to your WiFi network (monitor your DHCP server to figure out what IP address it got). You should then be able to telnet into the device and use PinScan as described in the README.

Be careful what pins you manipulate arbitrarily, though. Don't have the device plugged into the mains when manipulating it. Power the 3.3v rail only (as you would when flashing). There may be pin configurations that damage/break the device; I'd highly recommend tracing the PCB traces as much as possible before switching random pins to OUTPUT and toggling them on and off.

As an aside, how difficult was it to get into the TP-Link Tapo P100? The TP-Link EP25/KP125 Smart Plugs were an absolute pain to open without causing visible damage. Maybe with practice you could do it. They seem like great plugs that are well-built. With libretiny, Esphome seems to run great. I'm waiting on OTA support before I can really start using them, though.

I successfully flashed the PinScan example. (I need to use the board= wbr3 and feature/realtek-update branch though. Otherwise, it boots with a hash error).

However, by using the PinScan tool, I still cannot find the GPIO of the relay or the status LED. Very weird.

The TP-Link Tapo P100 is also very hard to open.

@Rain
Copy link

Rain commented Dec 20, 2023

I successfully flashed the PinScan example. (I need to use the board= wbr3 and feature/realtek-update branch though. Otherwise, it boots with a hash error).

However, by using the PinScan tool, I still cannot find the GPIO of the relay or the status LED. Very weird.

I'm glad you got it flashed. It definitely took some fiddling to figure out the pinout and PinScan over telnet was a bit finicky. Two things to keep in mind:

  • If you're powering the device from a USB UART adapter, it may not provide enough power to drive the relay (ie: you won't hear it click). A multimeter may help.
  • The LEDs on these devices are commonly "active low." If you only tried switching pins to OUTPUT and turning them HIGH, also try toggling them to LOW.

@geedsen
Copy link

geedsen commented Sep 24, 2024

@rtorrente That worked :-) I was able to compile esphome firmware without issue. However, when I try to install the firmware with ltchiptool it fails after about 5% write with this error:

send error: expected ACK; got b'\x15' for block 16

Anyone seen this before or know the reason?

Did you ever resolve this? I am seeing the same problem. And this is the topic was the only result googling for it.

@trianglesis
Copy link

Hello,
There is one other variant here:
Product: eightree smart plug et20

image

Unfortunately, I can't find this chip layout at:

But it is RTL8720CF.
I cannot load the firmware back and forth.

I will patiently wait for updates.

Thank you for all your work.

@k-w-1
Copy link

k-w-1 commented Nov 28, 2024

Just wanted to share that after traveling down miles of rabbit-holes, I came to the unusual discovery that RTL8710CF (which I want to point out is slightly different chip ID from the OP's RTL8710CM, and also different from RTL8720CF that was discussed later -- if there's no meaningful difference in the hardware, apologies for the noise) can actually be compiled & successfully flashed with the following ESPHome yaml snippet:

rtl87xx:
  board: wbr3
  family: rtl8720c
  framework:
    version: 0.0.0
    source: https://github.com/libretiny-eu/libretiny#feature/realtek-update

FWIW, my RTL8710CF was found inside a Kasa HS200(US) hardware v5 (e.g. the smaller one compared to some of the earlier HS200's, I haven't opened one of those yet to see what's inside). Initially, having read this and other issues plus the LibreTiny documentation discussing the Ameba chip nomenclature, I didn't actually realize I had an RTL8710CF and not an RTL8720CF or RTL8710CM.

@frostworx
Copy link

Oh, interesting. Thank you for the heads-up, @k-w-1!

I guess I can re-add the M515EGWT blinds I once bought (with a wbr3 chipset) into my queue :)

(pointing the other threads here accordingly)

@kuba2k2
Copy link
Member

kuba2k2 commented Nov 28, 2024

The RTL8710/8720/CM/CF chips are similar and compatible. The difference between 8710 and 8720 is Bluetooth support in 8720. The difference between CN and CF is memory, CF having built-in flash memory, CM having built-in PSRAM.

Keep in mind that while ESPHome works on these chips, certain features are not supported and the firmware might be unstable. A notable example of such features is OTA updating.

@frostworx
Copy link

Thank you very much for the detailed information, @kuba2k2!
Very appreciated!

@thealanberman
Copy link

Just wanted to share that after traveling down miles of rabbit-holes, I came to the unusual discovery that RTL8710CF (which I want to point out is slightly different chip ID from the OP's RTL8710CM, and also different from RTL8720CF that was discussed later -- if there's no meaningful difference in the hardware, apologies for the noise) can actually be compiled & successfully flashed with the following ESPHome yaml snippet:

rtl87xx:
  board: wbr3
  family: rtl8720c
  framework:
    version: 0.0.0
    source: https://github.com/libretiny-eu/libretiny#feature/realtek-update

FWIW, my RTL8710CF was found inside a Kasa HS200(US) hardware v5 (e.g. the smaller one compared to some of the earlier HS200's, I haven't opened one of those yet to see what's inside). Initially, having read this and other issues plus the LibreTiny documentation discussing the Ameba chip nomenclature, I didn't actually realize I had an RTL8710CF and not an RTL8720CF or RTL8710CM.

This is very timely news indeed, since I have just popped open my Kasa EP10 smart plug and discovered it has an RTL8710CF in it!

@trianglesis
Copy link

Has anyone found a proper pinout for such a chip/board yet?

#44 (comment)

@ThxAndBye
Copy link

ThxAndBye commented Dec 1, 2024

I successfully flashed the PinScan example. (I need to use the board= wbr3 and feature/realtek-update branch though. Otherwise, it boots with a hash error).
However, by using the PinScan tool, I still cannot find the GPIO of the relay or the status LED. Very weird.

I'm glad you got it flashed. It definitely took some fiddling to figure out the pinout and PinScan over telnet was a bit finicky. Two things to keep in mind:

* If you're powering the device from a USB UART adapter, it may not provide enough power to drive the relay (ie: you won't hear it click). A multimeter may help.

* The LEDs on these devices are commonly "active low." If you only tried switching pins to `OUTPUT` and turning them `HIGH`, also try toggling them to `LOW`.

I have opened and measured my Tapo P100(EU) / V2.0 (RTL8720CF) but haven't flashed any firmware yet.

Here is what I found out:

  • The Relais is conncted to 3.3V VD33_OUT (TP1) and then via an NPN Transistor (Q1) and a fuse (F1) to GND. The Pin on the MCU connecting to the base of the transistor is GPIOA_8. Connected via a 515R resistor (R155).
  • The LED (D10) is a Bi-Color Bi-Polar LED that is connected to GPIOA_9 and GPIOA_10 with a 100R Resistor (R5) in series. If GPIOA_9 is source and GPIOA_10 is the drain then the LED is orange. It illuminates green in the other direction.
  • The external switch (SW3) is connected to ground and then with a 100R resistor (R145) to GPIOA_17. It is also connected with a separate 10k resistor (R144) to VD33_FLASH (I/O power), VD1833_LPC (LPCsram power) and VA33_TR (analog circuit power) and with a 25R resistor (R128) to CHIP_EN. So a press of the button should completely reset the micro-controller?
  • The testpoint GPIO0 is connected to GPIOA_0
  • Testpoint TX1 is connected to GPIOA_16 and RX1 to GPIOA_15

If someone might be able to assist me in converting this to a configuration and tell me how to flash it to the chip I'd appreciate the help. I have a BW15-Kit with the same IC but was not able to successfully flash anything to it yet with ltchiptool (not completing the flash) and flashing with the Realtek AmebaZ2 PG Tool (v1.2.47) just led to invalid RAM signature errors on the serial output from the bootloader.

@prokoma
Copy link

prokoma commented Dec 3, 2024

Hi @ThxAndBye, you must've been reading my mind, because I also started tinkering with P100 EU this weekend to control some Christmas lights. If I had your message, I wouldn't have to desolder the board, because I traced the same pinout as you, so nice job!

After some picking and prodding I managed to get LibreTiny and ESPHome to work on this board including OTA. I found two bugs in the flashing code, which prevented the bootloader and partition table from flashing and caused a hash error. I fixed those and hacked together OTA support, because the P100 is difficult to open.

Here are the instructions to flash ESPHome onto the P100:

0. Install ltchiptool. Until libretiny-eu/ltchiptool#46 is merged, you need to use my fork, otherwise the first 256 bytes are not flashed when flashing UF2. I use Linux, so here are commands for that (how to use venv on Windows):

python3 -m venv tapo-p100
. tapo-p100/bin/activate
pip install git+https://github.com/prokoma/ltchiptool.git@ambz2-fix
ltchiptool -V

1. Open the device. I used some old plastic cards to pry the side wall away from the device. There are two clips on each of the 4 sides, when you get an opening, stick a piece of the card in so it doesn't close again when you work on the other side. Start on the side with the button first, because it is the weakest. Do not use anything metal, because you could scratch or knock some components off the board, there are tiny resistors and traces near the edge.

2. Connect a 3.3V UART interface to the test points. RX to TX1, TX to RX1, V3.3, GND, everything is marked on the board. Also hook a wire to GPIO0, which is used to enter the bootloader. Be 100% sure that your UART converter doesn't output 5V on the VCC, some cheap ones do and will fry the chip. You can check with your multimeter before connecting it to the board. GPIO0 has to be pulled to 3.3V before powering the chip to enter the bootloader. I first powered GPIO0 and then V33.

3. (optional, but recommended) Make a backup dump of the flash, so you can revert to the stock firmware.

ltchiptool flash read -c realtek-ambz2 path/to/store/dump.bin

3. Build an ESPHome firmware and download the UF2 firmware file. You can use vanilla ESPHome, the magic is in the rtl87xx.framework, thanks @kuba2k2 for this extension point. You can use my config as a starting point, just fill in the secrets.

4. Flash the firmware to the board using ltchiptool. Make sure that you are using the modified version of ltchiptool, otherwise you'll get the hash error on boot.

ltchiptool flash write path/to/firmware.uf2

5. The device should boot up. If you use my config, the orange led should light up for a few seconds while it is connecting to your wifi. Disconnect GPIO0 and try the OTA a few times before closing the device, because you don't want to open it twice. Report if there are any issues.

@prokoma
Copy link

prokoma commented Dec 3, 2024

This is a picture of my setup, I used some wires from an old IDE cable, because they are thin and easy to solder.

pic

And proof that it works and shows up in HA. Thank you again @kuba2k2 for your hard work on LibreTiny.

image

@kuba2k2
Copy link
Member

kuba2k2 commented Dec 3, 2024

Nice work!
I've left some more comments on the ltchiptool thread. I think that some of your changes (particularly the OTA support) could be added to LibreTiny before the realtek-update branch. After all, I can't tell when will that be merged and people can't wait until the chip gets proper support 🙂

@ThxAndBye
Copy link

ThxAndBye commented Dec 3, 2024

3. Build an ESPHome firmware and download the UF2 firmware file. You can use vanilla ESPHome, the magic is in the rtl87xx.framework, thanks @kuba2k2 for this extension point. You can use my config as a starting point, just fill in the secrets.

@prokoma Thank you for providing the detailed guide and configuration. I've been able to connect and read the flash of the controller but when compiling ESPHome I get an error when the UF2 is build:

Building UF2 OTA image
|-- esphome_2024.11.2_generic-rtl8720cf-2mb-992k_rtl8720cf_lt1.7.0.uf2
|-- firmware.uf2
|-- firmware.bin
|-- FileNotFoundError: [Errno 2] No such file or directory: '/data/build/tapo-p100/.pioenvs/tapo-p100/image_firmware_is_ota.0x00C000.bin'
|   |-- File "/root/.platformio/penv/.libretiny/lib/python3.11/site-packages/uf2tool/models/image.py", line 79, in read_file_1

I had no issue to build an image with the feature/realtek-update branch but your ambz2-fix doesn't seem to compile correctly. A file with the name image_firmware_is.0x00C000.bin (538K) is created but the image_firmware_is_ota.0x00C000.bin is missing.
ESPHome 2024.11.2 is running on a HA Yellow (CM4), maybe it doesn't compile correctly on the Pi? If I can provide any more details please let me know.

@prokoma
Copy link

prokoma commented Dec 3, 2024

@ThxAndBye This error means that LibreTiny itself is from my branch, but the ltchiptool it imports is the original version. You can try to delete the /root/.platformio/penv/.libretiny directory, that should force re-download of my forked ltchiptool. Also change something in the YAML, so it runs the linker again. If it doesn't work then, please provide the full build log from ESPHome.

@prokoma
Copy link

prokoma commented Dec 3, 2024

@ThxAndBye I've changed the reference to use a specific commit hash of ltchiptool instead of branch name, that could also help. You also have to use a commit hash in the framework.source directive, because it pulls only when the URL changes:

rtl87xx:
  board: generic-rtl8720cf-2mb-992k
  framework:
    version: 0.0.0
    source: https://github.com/prokoma/libretiny#55aacc8

@ThxAndBye
Copy link

@prokoma restarting the ESPHome Container in HA has helped as this cleared all the files. (Using "Clean Build Files" didn't help). I was able to compile the .uf2 and it's working on my P100. Thank you for your help and work in getting the RTL8720CF and Tapo P100 working with ESPHome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new platform About support for new chips/platforms
Projects
None yet
Development

No branches or pull requests