Skip to content

Serial.setDebugOutput(0) doesnt actually turn off debug output #98

Closed
@codewise-nicolas

Description

@codewise-nicolas

In the latest snapshop of the github code it seems the new function
Serial.setDebugOutput(0)
to turn off debug output is not working.

Usage:

 Serial.begin(115200);
 Serial.setDebugOutput(0);
 delay(10);

I traced the problem down to setDebugOutput() in HardwareSerial.cpp where there is a an if statement

if(uart_get_debug() == _uart_nr) {
            uart_set_debug(UART_NO);
}

that will fail to do its thing because uart_get_debug() (s_uart_debug_nr) will never be _uart_nr IF the function uart_set_debug() is never called with that value.
All places that uart_set_debug() is called are inside IF statements that wont run, kind of like a catch-22 situation.

Temp Solution
The temporary solution is to run a function that will set s_uart_debug_nr to something that will satisfy the IF statement above:

Serial.setDebugOutput(1); //sets s_uart_debug_nr to _uart->uart_nr

We can then turn it off,

Serial.setDebugOutput(0);

And it will properly be turned off.

 Serial.begin(115200);
  Serial.setDebugOutput(1);
  Serial.setDebugOutput(0);
  delay(10);

Semi permanent solution
A fix that works in the code comment out the inner IF inside setDebugOutput() as such:

//if(uart_get_debug() == _uart_nr) {
            uart_set_debug(UART_NO);
//}

However that may not make the function do whats intended.

True problem
The true problem is that the code inside uart_set_debug() is never run to initialize the settings that function does. Possibly run this function on .begin() to set things to a known state?
Something like:

void ICACHE_FLASH_ATTR HardwareSerial::begin(unsigned long baud, byte config) {
    uart_set_debug(uart_get_debug());  //new line

    // disable debug for this interface
    if(uart_get_debug() == _uart_nr) {

Another possible solution/error
Or possibly that last line in begin() is a typo and should be

void ICACHE_FLASH_ATTR HardwareSerial::begin(unsigned long baud, byte config) {
    // disable debug for this interface
    if(uart_get_debug() == UART_NO) {

Any one of these will fix the problem, it comes down to what is the intended sequence of the code. I hope this helps get it fixed and helps others.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions