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

Fixes ESP32-S2 CDC Debug Logging #7284

Merged
merged 5 commits into from
Dec 20, 2023

Conversation

SuGlider
Copy link
Collaborator

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

@SuGlider SuGlider added Type: Bug 🐛 All bugs Chip: ESP32-S2 Issue is related to support of ESP32-S2 Chip Area: Peripherals API Relates to peripheral's APIs. labels Sep 21, 2022
@SuGlider SuGlider added this to the 2.0.6 milestone Sep 21, 2022
@SuGlider SuGlider self-assigned this Sep 21, 2022
@avillacis
Copy link

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.

@SuGlider
Copy link
Collaborator Author

SuGlider commented Sep 23, 2022

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.

@VojtechBartoska
Copy link
Contributor

PR Update: Investigate why function tud_cdc_n_write_available freeze?

@SuGlider SuGlider marked this pull request as draft November 1, 2022 13:59
@VojtechBartoska VojtechBartoska removed this from the 2.0.6 milestone Nov 30, 2022
@VojtechBartoska VojtechBartoska added this to the 3.0.0 milestone Dec 14, 2022
@brentru
Copy link

brentru commented May 11, 2023

@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?

@SuGlider
Copy link
Collaborator Author

@brentru - I'll take a look and check it. But in general, I'd say that the PR is ready for review.

@paclema
Copy link
Contributor

paclema commented May 19, 2023

I can confirm too that this helps with ESP32-S2! When is it planned to be merged?

@VojtechBartoska
Copy link
Contributor

@SuGlider what about this PR, can it be reviewed or more work is supposed to be done on this?

@VojtechBartoska VojtechBartoska added the Status: Awaiting triage Issue is waiting for triage label Nov 28, 2023
@SuGlider SuGlider marked this pull request as ready for review December 18, 2023 13:53
@SuGlider SuGlider modified the milestones: 3.0.0, 3.0.0-RC1 Dec 18, 2023
Copy link
Contributor

github-actions bot commented Dec 18, 2023

Warnings
⚠️

Some issues found for the commit messages in this PR:

  • the commit message "Fixes ESP32-S2 CDC Debug Logging":
    • summary looks empty
    • type/action looks empty

Please fix these commit messages - here are some basic tips:

  • follow Conventional Commits style
  • correct format of commit message should be: <type/action>(<scope/component>): <summary>, for example fix(esp32): Fixed startup timeout issue
  • allowed types are: change,ci,docs,feat,fix,refactor,remove,revert
  • sufficiently descriptive message summary should be between 20 to 72 characters and start with upper case letter
  • avoid Jira references in commit messages (unavailable/irrelevant for our customers)

TIP: Install pre-commit hooks and run this check when committing (uses the Conventional Precommit Linter).

Messages
📖 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 🚫 dangerJS against 4943e63

@SuGlider SuGlider added Status: Review needed Issue or PR is awaiting review and removed Status: Awaiting triage Issue is waiting for triage labels Dec 18, 2023
@SuGlider
Copy link
Collaborator Author

@me-no-dev - Retested. The PR is necessary to use USB OTG CDC logging in ESP32-S2.

@SuGlider
Copy link
Collaborator Author

@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

@SuGlider SuGlider added Status: Pending Merge Pull Request is ready to be merged and removed Status: Review needed Issue or PR is awaiting review labels Dec 20, 2023
@me-no-dev me-no-dev merged commit edf5ecf into espressif:master Dec 20, 2023
46 checks passed
me-no-dev pushed a commit that referenced this pull request Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Peripherals API Relates to peripheral's APIs. Chip: ESP32-S2 Issue is related to support of ESP32-S2 Chip Status: Pending Merge Pull Request is ready to be merged Type: Bug 🐛 All bugs
Projects
Development

Successfully merging this pull request may close these issues.

Issue realted ESP32-S2 CDC to the Serial.setDebugOutput(true);
6 participants