arduino-esp32
arduino-esp32 copied to clipboard
Fixes ESP32-S2 CDC Debug Logging
Description of Change
When using ESP32-S2 with USB CDC and debug output is set also to go to the CDC (Serial.setDebugOutput(true)
), the S2 freezes after a few line of logging.
This issue only occurs with the ESP32-S2. It works fine with ESP32-S3 and CDC.
Tests scenarios
Tested with this sketch on the ESP32-S2 and ESP32-S3. IDE must set USB CDC On Boot: "Enabled"
#include <Arduino.h>
static void test_taskfunc(void * p)
{
uint32_t tasknum = (uint32_t)p;
while (true) {
log_i("This is task instance %u running...", tasknum);
delay(10 * random(1, 10));
}
}
void setup()
{
Serial.begin(115200);
Serial.setDebugOutput(true);
delay(2000);
Serial.println("\n==============\nStarting...\n");
log_e("Starting with LOGs.");
Serial.println("==============\n\n");
delay(750);
for (auto i = 0; i < 5; i++) {
TaskHandle_t th;
// Created tasks all need to have different priorities in order to trigger lockup
UBaseType_t taskPrio = 1 + 2 + i;
if (pdPASS == xTaskCreate(test_taskfunc, "test_taskfunc", 4096, (void *)(i + 1), taskPrio, &th)) {
log_i("Task instance %u created with priority %u", i+1, 3 + i);
} else {
log_e("Task instance %u creation FAILED", i+1);
}
}
}
void loop()
{
log_i("This is the main loop running...");
delay(10 * random(1, 10));
}
Related links
Fixes #6766
The good news: After applying this change, on my ESP32-S2 dev board, redirecting debug output to the USB CDC does not hang the sketch anymore. The sketch keeps running without interruption.
The (tolerably) bad news: It appears that some messages are not completely flushed to the opened serial terminal, so that the strings appear truncated. However, when more data is written with the log_X functions, the rest of the apparently-truncated string is emitted before the next message appears.
The (tolerably) bad news: It appears that some messages are not completely flushed to the opened serial terminal, so that the strings appear truncated. However, when more data is written with the log_X functions, the rest of the apparently-truncated string is emitted before the next message appears.
I guess that this happens only because the example has 2 tasks, writing to the CDC at the same time and one may interrupt the other while still writing the log, character by character, truncating the previous message by another task.
Maybe the best way to solve it is by creating a Message Queue within the sketch and a task that consumes this queue, printing one log message at a time, in order to make sure that it will not get truncated. In this case the tasks shall enqueue the messages using a specific API, which could also sort them by some critical ordering method, for instance.
PR Update: Investigate why function tud_cdc_n_write_available
freeze?
@SuGlider @VojtechBartoska I am experiencing a similar lockup on the latest BSP (due to setDebugOutput(true)
which I need for debugging). This PR resolves this issue.
What is the status of this PR in general, and the status of it making it into the next release?
@brentru - I'll take a look and check it. But in general, I'd say that the PR is ready for review.
I can confirm too that this helps with ESP32-S2! When is it planned to be merged?
@SuGlider what about this PR, can it be reviewed or more work is supposed to be done on this?
Warnings | |
---|---|
:warning: |
Some issues found for the commit messages in this PR:
Please fix these commit messages - here are some basic tips:
|
Messages | |
---|---|
:book: | You might consider squashing your 5 commits (simplifying branch history). |
👋 Hello SuGlider, we appreciate your contribution to this project!
Click to see more instructions ...
This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.
DangerJS is triggered with each push
event to a Pull Request and modify the contents of this comment.
Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- Resolve all warnings (⚠️ ) before requesting a review from human reviewers - they will appreciate it.
- Addressing info messages (📖) is strongly recommended; they're less critical but valuable.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.
Review and merge process you can expect ...
We do welcome contributions in the form of bug reports, feature requests and pull requests.
1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.
Generated by :no_entry_sign: dangerJS against 4943e63c0b977d5a1652140a7e1df34db8231d06
@me-no-dev - Retested. The PR is necessary to use USB OTG CDC logging in ESP32-S2.
@me-no-dev - This PR should be applied to branch master and to release/v2.x to make sure it goes to a future 2.0.15