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

3.0.0 - UART Peripheral Manager + Detach UART pins on begin()/setPins() #8697

Conversation

SuGlider
Copy link
Collaborator

@SuGlider SuGlider commented Oct 4, 2023

Description of Change

This PR implements the same changes as described in #8629
It also adds to the UART Peripheral Manager the control over UART pin and sets default console UART0 RX/TX.

The BareMinimum.ino example (empty sketch) will report RX/TX correctly when Verbose/Debug mode are set by using the Chip Debug Report feature.

Summary of changes:

  • It is now possible to dettach UART0 pins by calling Serial.end() with no previous begin()
  • It is now possible to call setPins() before begin() or in any order
  • setPins() will detach any previous pins that have been changed
  • begin(baud, rx, tx) will detach any previous attached pins
  • setPins() or begin(baud, rx, tx), when called at first, will detach console RX0/TX0, attached in boot
  • any pin set as -1 in begin() or setPins() won't be changed nor detached
  • begin(baud) will not changed any pins that have been set before this call through a previous begin(baud, rx, tx) or setPin()
  • If the application only uses RX or TX, begin(baud, -1, tx) or begin(baud, rx) will change only the assigned pin and keep the other unchanged.

Tests scenarios

Using ESP32

void setup() {
  printf("\nThis Line is printed fine because it uses TX Pin attached in Boot Time.\n\n");
  delay(100);
  Serial.end();                 // shall detach default UART0 RX/TX
  printf("1:: This Log line shall not be displayed!\n"); // using IDF console ets_printf() -- TX unattached!
  delay(100);
  
  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 
  Serial.println("3:: This line shall NOT be seen.");  // default TX is no longer attached
  Serial.flush();
  
  Serial.end();
  Serial.setPins(-1, 2); // it sets TX as GPIO2
  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

Fix #8573
Fix #8607

Close Draft PRs: #8619 #8620

Copy link
Member

@P-R-O-C-H-Y P-R-O-C-H-Y left a comment

Choose a reason for hiding this comment

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

LGTM! Tested and worked as expected.

Copy link
Collaborator

@lucasssvaz lucasssvaz left a comment

Choose a reason for hiding this comment

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

Works as expected. LGTM.

@SuGlider SuGlider removed this from the 3.0.0 milestone Oct 5, 2023
@SuGlider
Copy link
Collaborator Author

SuGlider commented Oct 5, 2023

Force Rebase to master in #8719

@SuGlider SuGlider closed this Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
3 participants