Skip to content

Default Console UART Rx Tx defined in HardwareSerial Constructor #8620

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

Closed
wants to merge 3 commits into from

Conversation

SuGlider
Copy link
Collaborator

@SuGlider SuGlider commented Sep 8, 2023

Description of Change

ESP32 SoCs attach RX and TX pins in boot time, conneting those GPIOs to IOMUX or GPIO Matrix.
Therefore, if the user calls HardwareSerial::setPins() or HardwareSerial::end() with no previous HardwareSerial::begin(),
those default already attached pins won't be detached, preventing them to be used for other purpose.

This PR shall be merged along with #8619 in order to make full effect with HardwareSerial::setPins()

Tests scenarios

void setup() {
  ets_printf("\nThis Line is printed fine because it uses TX Pin attached in Boot Time.\n\n");
  Serial.end();                 // shall detach default UART0 RX/TX
  ets_printf("1:: This Log line shall not be displayed!\n"); // using IDF console ets_printf() -- TX unattached!
  
  Serial.begin(115200);  // set default RX/TX pin because nothing was defined in the call
  Serial.println("2:: This line shall be seen.");
  Serial.flush();

  Serial.setPins(-1, 2);    // shall set UART0 to GPIO2 and detach default TX -- DEPENDS on MERGING #8619 
  Serial.println("3:: This line shall NOT be seen.");  // default TX is no longer attached
  Serial.flush();
  
  Serial.end();
  Serial.setPins(-1, 2); // it has not effect because Serial is ended... 
  Serial.begin(115200);  // This shall not set default TX pin because the previous setPin() was executed
  Serial.println("4:: This line shall NOT be seen.");  // default TX is no longer attached
  Serial.flush();
}

void loop() {}

Related links

Closes #8324
Closes #8573

@SuGlider SuGlider added this to the 3.0.0 milestone Sep 8, 2023
@SuGlider SuGlider self-assigned this Sep 8, 2023
@SuGlider SuGlider marked this pull request as draft September 8, 2023 20:03
@@ -97,14 +97,18 @@ void serialEvent2(void) {}

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
#if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC
HardwareSerial Serial0(0);
// sets UART0 (default console) RX/TX default pins already configured in boot
HardwareSerial Serial0(0, SOC_RX0, SOC_TX0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is for UART0 only, would it not be safer to keep the old signature and handle the default pins in the constructor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a better way, less intrusive.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@me-no-dev - This PR will remain as draft. Please review and merge #8629 to 2.0.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
2 participants