-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Problem with receiving data from Serial to update ESP32 OTA #6727
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
Comments
I must add, the key point for getting it to work on 1.0.6 release was setting the rx buffer to 1024. Without that the buffer will overflow and the bytes are missing. However setting the buffer in arduino > 2.0.0 do not help |
Similar to #6644 |
You are sure that |
What about setting a bigger RXBuffer, such as 4096? Would it make any difference? |
Please try this and let me know:
|
Yes, while moving to new framework i moved setRxBufferSize(1024) before begin of the serial1 because it was throwing me error that i cant set buffer when serial is already running (not a problem in 1.0.6 tho). Unfortunately setting buffer size to 4096 and even 10000 didnt fix the problem and the progress is not increasing , still about 1282730/1500912 bytes |
I don't have a modem to test it, but maybe I can try to emulate it with a Python script. Can you provide me with some sort of output that has something like this: example (time_ms, #bytes): Thanks! |
I will Try to prepare something tomorrow |
Just to verify... you say that with Arduino Core 2.0.0, you get the same issue, right. |
It is working for me in arduino 1.0.6 with setting rx buffer to 1024. Without setting buffer it is not. In arduino 2.0.0 and later it is not working regardless of setting serial buffer size or not. So the problem for me was introduced in 2.0.0 as i cant get it to work even with setting buffer size |
Did not have time today to measure the timings and bytes. I did check Reading data from the stream directly and check how many bytes did i read. 1500912 which is exactly my binary file size. So the esp32 can handle data from the modem but when i pass Stream directly to the writeStream() function, it looks like esp32 cannot keep up with Reading and writing data to flash at the same time. |
i also think so in the same kind of problem i'm facing in my issue #6644 |
Yes. Did you Try my solution in arduino 1.0.6? |
Yes, i tried that. didn't work. |
I have seen some people that uses OTA from a LTE/GPRS modem in a different way: Not sure if this way would work for you. |
i have also seen this and tried already, but again getting some different error in that process. ###Function_Code if (WiFi.status() != WL_CONNECTED) ### Debug_Output [5-11 11:40:01.3][ 17068][D][WiFiGeneric.cpp:852] _eventCallback(): Arduino Event: 0 - WIFI_READY here the while loop breaks before getting all the data from server don't know why.. |
Try this code: |
Unfortunately my binary size exceeds 1.5MB so i wont load it to spiffs. I just wonder why it works on 1.0.6 and not on > 2.0.0. I will stick to 1.0.6 for now |
i will also face this problem in future because i'm testing the OTA with only the OTA functions not with all the working functions on the device. after adding the complete code it will be about 1.7MB in size. |
There is a possible work around that may fix this issue. Pease try this code/example when starting Serial1 (used to receive data from the Modem with OTA firmware):
Please let me know if this solves the issue. |
any updates @primus192? |
Hi. I i am still on Old framework. Can not get it working on >2.0
wt., 23 sie 2022, 17:28 użytkownik Vojtěch Bartoška <
***@***.***> napisał:
… any updates @primus192 <https://github.com/primus192>?
—
Reply to this email directly, view it on GitHub
<#6727 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AVLNJLDIOUA24PJNTBDUVZDV2TU2VANCNFSM5VU24LWQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hi, |
We have done a few updates to UART in the new Arduino Core 2.0.5 version.
|
Unfortunately it does not work. Updating still hangs at 97% while on arduino 1.0.6 it works like a charm. |
Please try using lastest master branch from Arduino ESP32 Github to build you application. This PR fixes I think that it may solve the timeout issue. Please use this setup:
|
Thank you. I will check and report back tomorrow.
niedz., 4 gru 2022, 15:12 użytkownik Rodrigo Garcia <
***@***.***> napisał:
… @primus192 <https://github.com/primus192> @mudgalp
<https://github.com/mudgalp>
Please try using lastest master branch from Arduino ESP32 Github to build
you application.
There is a new PR that may fix the issue: #7525
<#7525>
This PR fixes Stream::readBytes() to make it faster using IDF in the new
Core 2.0.x
I think that it may solve the timeout issue.
Please use this setup:
void setup(){
Serial.setRxBufferSize(2048);
Serial.begin(115200,SERIAL_8N1,26,27); // RxPin = 26 & TxPin = 27
Serial.setRxTimeout(1);
Serial.setRxFIFOFull(120);
Serial.flush();
}
—
Reply to this email directly, view it on GitHub
<#6727 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AVLNJLF6AQMCNWWIA543HQDWLSREDANCNFSM5VU24LWQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I checked that, unfortunately, no success.
niedz., 4 gru 2022 o 15:12 Rodrigo Garcia ***@***.***>
napisał(a):
… @primus192 <https://github.com/primus192> @mudgalp
<https://github.com/mudgalp>
Please try using lastest master branch from Arduino ESP32 Github to build
you application.
There is a new PR that may fix the issue: #7525
<#7525>
This PR fixes Stream::readBytes() to make it faster using IDF in the new
Core 2.0.x
I think that it may solve the timeout issue.
Please use this setup:
void setup(){
Serial.setRxBufferSize(2048);
Serial.begin(115200,SERIAL_8N1,26,27); // RxPin = 26 & TxPin = 27
Serial.setRxTimeout(1);
Serial.setRxFIFOFull(120);
Serial.flush();
}
—
Reply to this email directly, view it on GitHub
<#6727 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AVLNJLF6AQMCNWWIA543HQDWLSREDANCNFSM5VU24LWQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Not completed by any means ;) |
I've just updated from 1.0.6 to 2.0.9 and am facing the same issue. Is there an ETA on resolving this or a workaround? UPDATE: After setting a cb for HardwareSerial::onReceiveError I'm now seeing additional logging [W] UART1 FIFO Overflow. Consider adding Hardware Flow Control to your Application. Adding hardware flow control isn't really an option as our product has been working fine up until this software upgrade. |
@Dave-Osborne - FIFO Overflow means that the internal ESP32 UART1 FIFO got full before the data could be read by the Arduino Sketch. |
@SuGlider - Hi, the rx buffer size is already set to 4096 before the serial begin (I've also tried setting it larger). Baud rate is 115200 |
What is the sketch used for OTA? |
It is part of OTA (via LTE-M Modem), I download smaller gzipped sections of the firmware and store on a LittleFS partition and then later stitch them together and perform an OTA update. Normally I use 300k sections, but have dropped to about 50k whilst looking into this issue. I've changed the code to only read the number of bytes available during the loop, as you can see below using this method a small number bytes in consistently read which is nowhere near the 4096 buffer limit, it looks like perhaps the Serial1.setRxBufferSize(4096); call isn't actually increasing the FIFO buffer?
UPDATE:
|
Please try using |
Thanks for @SuGlider, I'm still using readBytes() but have just found that if I don't write my buffer to LittleFs there is no issue reading serial data, so perhaps there is an underlying issue reading serial and then writing to flash? As I'm downloading the firmware in sections I'm going to transfer to PSRam, check the CRC bytes I include and then append to a larger file on LittleFs before performing the update. |
As far as I remember I checked regular read before and it did not fix my issue either, i am passing serial data from modem directly to the update class. Still sitting On 1.0.6 because of this issue.. Tried the read instead of read bytes a moment ago. No luck Maybe if we could increase hw fifo size which is limited to 1024b but hardcoded to 128b per rx tx could help but i see there was request to be able to change it but noone implemented it yet |
I can confirm that if I no longer write to flash directly I no longer get FIFO Overflows. As a quick workaround I'm now writing to a PS RAM filesystem first https://github.com/tobozo/ESP32-PsRamFS I download in 300k sections and then append each to a LittleFS file, but if you have enough PSRam you could probably update directly from the PS RAM filesystem? I'll perhaps refactor to use a PSRam stream instead at some point, but this workaround is working for me at the moment. |
Unfortunately PSRAM is not the option for me |
@primus192 - Can you please try this: Serial1.setRxBufferSize(4096);
Serial1.begin(115200,SERIAL_8N1,26,27);
Serial1.setTimeout(0); // ====> This may affect the process of time out and help with OTA
Serial1.flush(); |
Tomorrow i will try that but i think i have Tried that before with No success EDIT: No success :) Still getting fifo overflows |
Hi @primus192 did you resolved this issue? |
@primus192 Just a small idea: Did you try to put the functions reading Serial and writing Flash into IRAM? ( using Putting the functions into IRAM would make them independent of the flash and allow for execution while flash is written. |
Well that is clever idea, i will try to do that. Anyway i am using hardware
flow control now which fixed issue for me and improved stability of my
communication with modem :)
pon., 17 cze 2024, 21:18 użytkownik TheMasterofBlubb <
***@***.***> napisał:
… @primus192 <https://github.com/primus192> Just a small idea:
I guess you were writing to flash when doing the OTA, which would mean
that while you write, you can not read from flash. So consequently you can
not run code at that time as it would be read from flash.
Did you try to put the functions reading Serial and writing Flash into
IRAM? ( using IRAM_ATTR you can tell the toolchain to do that)
Putting the functions into IRAM would make them independent of the flash
and allow for execution while flash is written.
—
Reply to this email directly, view it on GitHub
<#6727 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AVLNJLDNYH7LL44CB77EBRLZH4Y77AVCNFSM5VU24LW2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMJXGQZDIMZYGY3A>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hello, This issue seems resolved. Therefore I close it. In case it occurred again, please reopen it. Thanks. |
Board
ESP32 Dev Module, custom board
Device Description
ESP32 Dev Module, custom board
Hardware Configuration
Quectel 2G modem attached to pin 26 and 27 of the esp32
Version
latest master (checkout manually)
IDE Name
PlatformIO
Operating System
Windows 11
Flash frequency
80MHz
PSRAM enabled
no
Upload speed
115200
Description
Using earlier versions of arduino framework (pre 2.0 update) i was able to receive all bytes from my GSM 2G modem and push it through the Serial1 connected to pins 26 and 27 to Esp32 to update it OTA with using Serial1.setRXBufferSize(1024) before initializing communication. Baud rate is 115200.
Now with newest Arduino 2.0.3 or 2.0.4 or master branch progress of flashing just stops at 85%, modem sent all the data but esp32 missed some during receiving and after some time prints error number 6 which means timeout. Setting different RX buffer sizes before Serial1.begin() did not help. Maybe setting rx buffer size is broken? Or other things changed which i do not think about? Thanks in advance.
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: