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

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

Closed
codewise-nicolas opened this issue Apr 22, 2015 · 1 comment
Closed

Comments

@codewise-nicolas
Copy link

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.

@Links2004
Copy link
Collaborator

the fix is even simpler.
uart_get_debug() return the variable s_uart_debug_nr and this one is init as UART_NO but infarct the default for the SDK is output on uart0 so changing the init value fix the problem.
now at begin the uart_get_debug() return the good value and then disabling the debug output.

thanks for the good bug report.

@igrr igrr closed this as completed Apr 23, 2015
igrr added a commit that referenced this issue Apr 26, 2015
* esp8266: (21 commits)
  HardwareSerial: add other configs than 8N1
  Delete jre-8u31.zip.sha
  Fix Windows build
  Add boot loader compatible speed of 74880 to serial.
  update SDK to esp_iot_sdk_v1.0.1_15_04_24
  include stdlib_noniso.h in Arduino.h see #110
  strnlen implementation
  missing strn program space wrappers
  uart_interrupt_handler is now in ram
  move libm to flash (.irom0.text) saves 3544 Byte in ram see #104
  Revert c_types.h
  fix bug #98
  add INPUT_PULLDOWN support
  add prototypes for ets_vsnprintf and ets_vprintf fix some compiler warnings
  update SDK to 1.0.1_b2_15_04_10 + SSL Patch
  update SDK to 1.0.1_b1_15_04_02
  add files to ignore (use hardlink) to get git hardware in arduino dir
  Add method to configure softAP IP address
  test for #86
  add to ESP class: getChipId getSDKversion getBootVersion getBootMode getCPUfreqMHz
  ...
igrr pushed a commit that referenced this issue Oct 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants