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 UART pin detach on Serial.end() #7402

Merged
merged 3 commits into from
Nov 2, 2022

Conversation

SuGlider
Copy link
Collaborator

@SuGlider SuGlider commented Oct 26, 2022

Description of Change

When Serial.end() is executed, the UART driver doesn't detach RX/TX/CTS/RTS pins.
As consequense, those pins pads connected using IOMUX by IDF layer will continue to send/receive data to/from the peripheral, causing the impression that Serial is still working.

This PR fixes it by adding a pin detach function used in Serial.end().

Tests scenarios

Tested using ESP32 and ESP32C3.

Necessary to use Arduino Serial Monitor for the default Board Serial port (Serial) and then some other UART<->USB converter board for reading the messages from pin 5 (new TX).

#define New_RX 4   // ESP32, S2, S3, C3
#define New_TX 5   // ESP32, S2, S3, C3

HardwareSerial NewSerial(0);

void setup() {
  Serial.begin(115200);
  delay(2000);

  Serial.println("\n\nStarting on Serial, default pins, and ending Serial");
  Serial.flush();
  Serial.end();
  delay(2000);

  NewSerial.begin(115200, SERIAL_8N1, New_RX, New_TX);
  delay(2000);
  
  NewSerial.println("\n\n...now printing on NewSerial, others pins .. " );
  NewSerial.println(" but the message appears also on Serial Monitor ... " );
  NewSerial.flush();
  Serial.println("\n\n printing on Serial");  // No output: OK serial is closed
  Serial.flush();
  NewSerial.println("\n\n and once more printing on NewSerial");
  NewSerial.flush();
}

void loop() {
  // put your main code here, to run repeatedly:
}

Related links

Fixes #7359

@SuGlider SuGlider added the Area: Peripherals API Relates to peripheral's APIs. label Oct 26, 2022
@SuGlider SuGlider added this to the 2.0.6 milestone Oct 26, 2022
@SuGlider SuGlider self-assigned this Oct 26, 2022
@fanfanlatulipe26
Copy link

Just need to add a "HardwareSerial NewSerial(0);" in the testcase

@SuGlider
Copy link
Collaborator Author

Just need to add a "HardwareSerial NewSerial(0);" in the testcase

Thanks! Added that line to the testcase!

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.

Good PR @SuGlider , tested on remaining chips S2/S3 and works great 👍

@me-no-dev me-no-dev merged commit 2cebee4 into espressif:master Nov 2, 2022
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.
Projects
Development

Successfully merging this pull request may close these issues.

Serial.end() does not disconnect the Serial monitor
4 participants