-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
ESP-IDF esp_modem.c data corruption (IDFGH-5435) #7176
Comments
Hi @zvasicek56 How often do you see this happening, does it only happen in the It might be possible, however, that we could get these two events in the transition mode, but again in the transition |
thank you for your response. The issue is observed in the According to the source codes, the function It looks that also |
@zvasicek56 Thanks for the investigation and sharing more details. I still wasn't able to reproduce the issue, but I think I understand the potential cause of the trouble. It might be possible, that the pattern detection in the uart driver generates more events before the modem thread gets to receive them and thus reading data behind the currently processing event, causing the potential corruption you described above. Could you please apply the patch and see if this fixes the issue? |
@david-cermak, the patch actually does not address the root of the problem. Data loss still persists and moreover, the patch leads to new errors: a) partial line is given to The issue is that both UART and PATTERN interrupts are enabled at the same time as a consequence of the Please have look at the latest log after patch. The first issue is here: Event Could you please comment the first solution proposed in the initial submission. Is it safe to just ignore all the UART DATA events if the modem driver is in command mode? Anyway, UART driver needs to be patched to fix
|
@zvasicek56 Thanks for testing the patch. It looks like my assumption was wrong. In this case, I'm afraid, I'm running out of ideas. I've been testing this exact scenario quite extensively, simulating both events at the same time, but no luck in understanding what was happening in your case.
I don't like the idea of skipping the data processing based on the operational mode. Both handlers must work in both modes, as they seem to work in my case. Another reason is support for the transition mode, where we could receive both data and commands at once. Have seen issues with processing commands (already in the command mode), just after switching from PPP mode. therefore the data event has to work correctly in a plain command mode. Have you tried disabling the pattern detection interrupts altogether? Could you please check once? This should work the same way. |
Hi @zvasicek56 I wasn't able to reproduce the issue, but I believe there is a potential problem of these two events competing and causing data races. I was thinking of processing the pattern detection manually for some time already (I've done so in the |
Thanks for reporting, would you please help share if any updates for the issue? Thanks. |
Thank you very much @david-cermak. I can confirm that your patch, which only uses the |
@zvasicek56 Thanks for the feedback! I also think this is a good change. I will clean the patch up and get it merged. This issue is to be closed once merged and synced. |
Just curious why do you use a union keep the "line_buffer_size" since it's no longer used? |
Not used, but still a kind of public API, so wanted to keep it compatible so that both the new option and the old one is accepted. |
I think I hit a bug with the change in a90817c. In esp_handle_uart_data() I check the uart data (It's actually multiple lines): OK However, it then stop working. Remove the MODEM_CHECK from this line, then it works. Looks like the MODEM_CHECK causes the second line "OK" never received. |
Thanks for the early feedback, I'll look into it and fix it (I've tested this multiline scenario, expecting that the line handlers return |
Hey! I'm sorry to rise up this issue, but can you tell me in which version of esp-idf this issue has been resolved? I suppose it would be enough to use
right? Thank you! |
Environment
git describe --tags
to find it):// v4.4-dev-1594-g1d7068e4b
Problem Description
There is a bug in the recent version of
examples\protocols\pppos_client\components\modem\src\esp_modem.c
introduced probably in55d41. The data from the UART's RX buffer are consumed in two events: UART_DATA and UART_PATTERN_DET. This causes duplicate events which manifests in data corruption. Data received in UART_DATA event handler can be overwritten in UART_PATTERN_DET handler under some circumstances. The issue is that both handlers wrongly supposes the esp_dte->buffer is empty despite of the fact that it can contain data written in a previous event.
Debug Log
This issue is hard to debug, so please see the isolated sequence of events (bold), states and actions causing the data corruption:
Data (two characters 'OK' added in the fourth event) are overwritten in the last event.
Solution
It is not clear why the data are processed in UART_DATA handler in command mode.
uart_read_bytes(...,esp_dte->buffer + strlen(esp_dte->buffer),...)
instead ofuart_read_bytes(...,esp_dte->buffer,...)
?The text was updated successfully, but these errors were encountered: