Skip to content

serial.begin(baudrate) resets the full configuration of serial #5026

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
fabianoriccardi opened this issue Apr 8, 2021 · 4 comments
Closed
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@fabianoriccardi
Copy link

Hi,
Looking at HardwareSerial.h:

serial.begin(9600);

This calls does not only set the baud rates, but it resets the full configuration to the default values (even rx and tx pins). Is it an intended behavior or is a bug?

I think that if I do not specify further parameters, these shouldn't be changed.

I tested this behavior on latest commit 371f382

@lbernstone
Copy link
Contributor

The function has default parameters. So, if you don't set them, it will use the defaults. If you want to call begin again, you must supply those custom paramteres again. If you just want to change frequency, use updateBaudRate.

@fabianoriccardi
Copy link
Author

fabianoriccardi commented Apr 8, 2021

I have read the header file, I know I can do everything.
The problem is that I'm using a library that calls begin(baudrate), and it also resets the rx and tx pins. This is an unintended side effect since there is no way to change serial pins if not in the class constructor in other Arduino cores.

Nothing wrong with this implementation, but in this case, portability among cores seems not trivial.

TD-er added a commit to TD-er/ESPEasy that referenced this issue Apr 27, 2021
When calling Serial::begin() (on ESP32) you apparently need to give all parameters or else it may use default parameters (makes no sense!)
Serial::end() may cause a hang or crash -> timing issue

See crash/hang:
- espressif/arduino-esp32#5047
- espressif/arduino-esp32#5004
- espressif/arduino-esp32@81b7c47
- espressif/arduino-esp32#5112
- espressif/arduino-esp32#5032

Switch back to default:
- espressif/arduino-esp32#5026
@stale
Copy link

stale bot commented Jun 18, 2021

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Jun 18, 2021
@stale
Copy link

stale bot commented Jul 11, 2021

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Jul 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

2 participants