-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
UART0 freezing RTL8710 + flash layout talks #91
Comments
Can you add some printf's in |
Thanks for your quick answer! You can see correct init for log uart2 first and uart0 freezes:
Seems to freeze at 'UART_Init':
|
Found the issue - turns out that I probably haven't tested Serial on RTL at all... there was a system call missing. Also, I found out that Serial interrupts (reading data) didn't work, so I'm fixing that too. The fix will be included in the structure-refactor branch. |
Thanks! Is there an easy way to test the fix? If I specify
(side note: how to specify a platform branch in esphome.yaml?) |
Yeah, you'd need to git clone the ltchiptool repository on the refactor branch, and install it inside the PlatformIO virtualenv. Not that straightforward, but doable. |
Hmm, that ltchiptool thing completely broke my platformio installation :) In the end it was easier to backport the essential lines of 046f7df and voila:
It no longer crashes! At the time of writing, I don't have a Modbus slave device available, so I'll have to test later to see if any data is actually flowing. |
The installation will be automatic when I release this. So it won't break platformio installations :) |
Hi @hn EDIT: let's keep the issue open so that I remember to add that "MX1290" to the list of supported chips. |
Yes, that's #13, a lucky one. For some reason AP mode works just fine when used in a simple Arduino sketch, but not in ESPHome. |
The ESPhome AP seemed to collapse after some seconds, didn't work at all. With plain arduino AP mode via This is what I remember from one single test last week, no details today :) |
That's the second part of the issue. On esphome it's just not visible at all, and on Arduino it is but DHCP sometimes doesn't work. |
Hehe, I experienced very strange errors with some received ModBus messages. After further investigating I saw that zero (0x00) bytes were missing from the input stream. After checking cabling, beating up the ModBus lib and so on I noticed that the following fix is simply missing from your backport:
|
Ah, yes, sorry for that. Will you be fine having that fix only locally for now? I don't want to clutter the master branch, and I think the refactor is coming close to be finished soon. |
For me it's fine, the inverter reliably reads various ModBus registers and pushes data to ESPhome / HA, that's really great! Side note: OTA seems to be broken? Logs are ok
But no new firmware is showing up. So I'm still working with serial uploads. |
Not really, I don't recall it being broken. Does your board have 2MB of flash? Can you dump it via serial and post it here? You can mask out your SSID/pass as long as you keep it the same length. |
I have to double-check the OTA thing. I think it might be related to the fact that so far I solely flashed |
Yes, you should always flash the UF2, unless you want to break something. There's some information at 0x9000 that indicate OTA2 address, and it's possible that yours is different from the standard 0xD0000. |
Hm, AliOs OTA2 seems to be at 0x100000 while LibreTuya expects 0xD0000:
Is there a way to conveniently "force" ltchiptool to overwrite system at 0x9000 or do I have to manually read->change->write the system block? PS: From the dump I see that the ESPhome OTA routine has placed the image at 0xD0000 so this (very first) part of the update process seems to be successful. |
I believe generic-rtl8710bx-4mb-980k has exactly that offset. I presume your flash is 4MB then. You might want to override the MCU name and clock frequency in PlatformIO options. |
Hm, the datasheet says "2M bytes XIP flash". On the other hand, the reconstructed partition table lists some addresses above 0x200000. Hard to believe that they put in more memory than printed in the datasheet ... |
That partition table doesn't look real. There's no such thing as "recovery", "OTA storage" on AmebaZ, and the application is always at 0xB000. Do you have a full flash dump of the stock firmware that you can post? |
Ah, I see. The "2ndboot" is what's stored at 0xB000, and it probably performs tasks like OTA unpackaging (from 0x150000) and booting the main app (from 0x19000), hence it's called "recovery". Nevertheless, if you've been flashing to 0xB000 manually, the 2ndboot is long gone, so only Realtek's bootloader remains. Now, when you flash an OTA update from an UF2 file (through web_server), it gets written to 0xD0000. The "system" partition is then switched to boot from OTA2, but since there's nothing valid at 0x100000, the Realtek bootloader jumps back to 0xB000. LibreTuya, when used as an Arduino framework, has a |
The AliOs guys have added an own layer to the AmebaZ standard. Their "application" is jsut the "2ndboot boot loader" which has its own AliOs update mechanism. I wiped out their stuff by overwriting 2ndboot. You can see their partition table I'll patch system part to 0xd0000 and see what happens then. |
With patched system block the OTA seems to work :-) I'm still confused with the 2MB/4MB thing, though. You can read from 0x2a2000 (WiFi credentials), 0x2a4000 (AliOs cloud credentials) and so on. But 0x2a0000 is not within 2MB ... I had to use Python2-rtltool to upload the system block, ltchiptool fails with:
|
Oops, thanks for the error report, fixed in v3.0.3. If you can read at these addresses, the flash is most definitely 4 MiB. Also, an OTA partition of 0x100000 size wouldn't fit on 2 MiB flash, as there's another OTA partition to fit as well. |
Hm, things are getting even more strange. Playing with Arduino LT.getFlashChipSize() and others show:
So do we have an 8MB flash? I did not find a quick way (yet) to map the getFlashChipId() values to anything meaningful. I dumped 10MB flash address space with rtltool and after 0x800000 the same byte pattern appears. Somewhat reinforces the idea that it really is 8MB flash. ltchiptool does not allow to dump more than 2MB for this chip:
|
Anyway, using this ESPhome config
I can successfully upload and OTA-update the EMW3080 (with 0x9000 system block set back to stock AliOS OTA2=0x100000). |
It appears so, yes. The Most of other About ltchiptool - I didn't find a reliable way to detect the flash size during download mode, yet. Maybe I'll just skip the size validity check at some point. I'll also try to add an option to customize flash partition layout, so that one can use any compatible board and just change whatever they need in the flash layout. Maybe I'll include that in the refactor, but most likely it'll be later. |
I would vote to change the hard check to a warning. If someone explicitly sets start address or length, they should know what they are doing.
Nice. Maybe even provide a way to add local MCU definitions inherited from the official ones. I don't know how this would fit into the ESPhome environment, but it should be doable somehow. |
Will do.
What do you mean by this? I'm not sure what are MCU definitions, and what official ones. |
I was roughly thinking of a local |
So something like |
Regarding ESPHome, I will probably add dedicated options to set some of the There's still another problem: OTA. Currently, the flashing file ( I'm thinking of embedding the partition table in the UF2 in all cases. That way you could freely change the partition table, and OTA will always respect it before booting the new firmware. That will not work on older devices, though (which will just ignore the "partition table block"), so they'll have to be flashed to new firmware first. |
Sounds quite cool. I was just lazy brainstorming how a local
But ... in my case it might be easier not to use a json and just overwrite the needed things with |
You can set everything you posted in the It's possible to override vendor/name, but there's actually no point since they're not used anywhere except in docs. If you want, you can actually create a PR to add the EMW3080 board to the list of supported boards. But since the boards will change a bit after the refactor, you'd have to make it to the other branch... Or you can wait till I merge the refactor and create the PR then 🙂 |
I just pushed a beta version of the Solis S3 WiFi stick ESPhome replacement firmware . Things are doing really well, except after some hours the ModBus traffic somehow gets out of sync and fails with CRC errors. I have to dig deeper into this later (but I think it is caused by the a-little-bit-shaky modbus component and not by LibreTuya). LibreTuya Wishlist ;-) :
|
IIRC, NTP works just fine. I tested it some time ago and there was no issues. Captive portal is working on the refactor branch, but only for the first time (i.e. it won't work after disconnecting from the WiFi, and being unable to join the network). In fact, it won't even reconnect to the network after losing connection - I wasn't able to get the RTL SDK to reconnect, but maybe that's an issue with my network only. |
Ahh, great, I just misunderstood your first posting.
The EMW3080 seems not to be very common. And they produce an 8MB version without publishing matching datasheets. This gives me the slight feeling that it is not appropriate for them to get their own JSON :) But, I'll think about this later. |
Source YAML. I have not checked this in detail as the LibreTuya page denies support for NTP.
Ok, I'll re-check when the refactor branch has been published. |
use :
version dev should be used instead of latest |
Same error here with:
I just changed the string. Do I need to somehow re-download/configure libretuya? |
It should do it automatically. "latest" is the latest one published on platformio, "dev" is pulling the libretuya platform from git |
Not a LibreTuya problem: (Debian) system package |
In your guide I can see you're installing packages manually, while you should do it with |
Sorry to disturb you again. Things are generally working very well. But after a few hours, sometimes the ModBus/UART traffic gets out of sync and cannot be resynchronised except by rebooting the stick. More detail: The correct ModBus response string is
I wonder if this is a problem of LibreTuya or the ModBus component. It's somewhat hard to debug because you have to wait more or less half a day until it appears. The ModBus component just checks if bytes are available() ( I have a very vague suspicion that the serial.available()=false status may be wrong (and thus the last byte remains in the buffer) and is only set to true again by the arrival of the next real ModBus response. Hmmm. |
Connect to the UART with a USB-RS232 adapter, send 1 byte at a time, and see if it shows up when there is only 1 byte in the buffer? |
I'm still having problems with ModBus traffic getting de-sync-ed (as described above). I've tried numerous things and in the end it depends on one single line in SerialClass.cpp. Believe it or not:
Obviously, this line makes no sense. I don't know if the println changes some timing edge case or some inner workings inside the UART or something .. just strange. I'll double/triple-check this during the next days and/or try the structure-refactor branch when it is released (yeah!).
|
A lot of topics have been discussed in this issue and it may be too long overall. In particular, the original problem has been solved, so I am closing the issue. I've opened a new issue to track the ModBus desync problem. |
I'm trying to replace the stock (AliOs) firmware of a Ginlong Solis Solar Inverter. The device is based on the EMW3080 MCU, which is an (identical?) clone of the RTL8710BN (my project page with datasheet, more info on the MCU, link to AliOs EMW3080).
libretuya is booting (fantastic work, thanks!), WiFi and GPIOs for reset pin and status LEDs seem to work fine (basic tests done: WiFi connect/DHCP, button press, blinking LEDs, ...).
If I try to use hardware serial port 0 (for interfacing modbus later), the system freezes, e.g. with plain libretuya:
The MCU freezes at
Serial0.begin
, the 'Started modbus serial' is never reached (and main loop is not started as well).Same test with libretuya-esphome
If I remove the comments for 'uart' the MCU freezes at 'Setting up UART...' log output.
Any help on how to fix or debug this is welcome!
The text was updated successfully, but these errors were encountered: