Skip to content

Serial.begin(115200); does not reinitiate after Serial.end(); which also disables BLE and PWM functionality #5032

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

Comments

@Ryap741135
Copy link

Ryap741135 commented Apr 9, 2021

Hardware:
|Board|ESP32 Dev Module (ESP32-WROOM-32D)|
|Version/Date|1.0.5 and 1.0.6|
|IDE name|Arduino IDE 1.8.13|
|Flash Frequency|80Mhz|
|PSRAM enabled|no|
|Upload Speed|115200|
|Computer OS|Windows 10|

Description:

I am new at submitting an issue but I believe this is a critical issue where the Serial.begin(115200); no longer reinitiates after Serial.end(); Serial.end() also disables my RGB LED that use PWM and disables BLE functionality. This was not occurring and working (with compilation, upload successfully and tested with hardware) in ESP32 Board Manager version 1.0.4 but the problem was apparent in versions 1.0.5 and 1.0.6. Below is a snippet of my code (is very big and need hardware to interface with to get it working) that controls the ESP32 dev board. When an USB is plugged in it should set the CPU frequency to 240MHz, enable Serial output and when the USB is removed it should set it to 80MHz, disable Serial output. This is to conserve the unit's battery power. I have tested with an RGB LED as an indicator to see if the code flows properly since I do not have Serial Monitor when the USB is removed or connected. I have also tried to establish a BLE connection after Serial.end(); no avail with board manager 1.0.5 and 1.0.6. The Serial output works just after uploading but once I disconnect the USB and reconnect it, it does not show Serial output in the Serial Monitor (this was working in 1.0.4).

Thanks for your help!

Sketch: (leave the backquotes for code formatting)

byte sensors() {
  hdc1080();
  plantower();
  serial_debugger();
  //Serial.println(getCpuFrequencyMhz());
  boolean USB = digitalRead(V_USB);
  if (USB == HIGH && USBflag == true) {
    USBflag = false;
    setCpuFrequencyMhz(240);
    Serial.begin(115200);
    Serial.setTimeout(250);
    //blue(); //Comment out the top two lines to test the blue LED with USB detect
  }
  if (USB == LOW && USBflag == false) {
    USBflag = true;
    setCpuFrequencyMhz(80);
    //red();
    Serial.end();
    //red(); //Comment out the top one line to test the red LED with USB detect
  }
  /*else{
    USBflag = true;
    green();
    }*/
  return 1;
}

Debug Messages:

Enable Core debug level: Debug on tools menu of Arduino IDE, then put the serial output here 
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

1 participant