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

Calling Serial.flush() insta-kills Pico #357

Closed
maxgerhardt opened this issue Nov 2, 2021 · 3 comments
Closed

Calling Serial.flush() insta-kills Pico #357

maxgerhardt opened this issue Nov 2, 2021 · 3 comments

Comments

@maxgerhardt
Copy link

maxgerhardt commented Nov 2, 2021

Consider the sketch

void setup() {
  Serial.begin(115200);
  while(!Serial) {}
  delay(200);

  Serial.println("This is a test!");
  Serial.flush();
  Serial.println("We survived!!");
}

void loop() { Serial.println("alive.."); delay(1000); }

The output of which is

This is a test!

followed by a hangup of the serial monitor window (cannot be closed). The on-board LED starts blinking on the board in the pattern dictated by mbed_die(). The hangup persists until the Pico is physically removed from the USB port.

Now consider the same sketch, but comment out the Serial.flush();. The output is now

This is a test!
We survived!!
alive..
alive..
alive..

Conclusion: Your Serial.flush() implementation kills the Pico, instantly.

(You will have to put the Pico into bootloader mode when plugging it in and selecting a fake upload port, otherwise you cannot reprogramm the Pico).

This is using the latest-released 2.5.2 core on the latest Arduino IDE 1.8.16, selected board is the Raspberry Pi Pico.

@facchinm
Copy link
Member

facchinm commented Nov 3, 2021

Should be fixed by #341 (in master but not yet released).
@maxgerhardt would you mind applying the patch manually and reporting if it fixes the issue?

@maxgerhardt
Copy link
Author

Yes, editing the file locally in C:\Users\<user>\AppData\Local\Arduino15\packages\arduino\hardware\mbed_rp2040\2.4.1\cores\arduino\Serial.cpp with the fix and reuploading fixes the problem.

This is a test!
We survived!!
alive..
alive..

Serial.flush() crashing the board in the common Serial USB configuration seems pretty crucial to me, I'm sure some sketches and libraries rely on it. The RP2040_RTC library linked above e.g. does to print its debug output. Don't you want to do a re-release with the bugfix?

@facchinm
Copy link
Member

facchinm commented Nov 3, 2021

The plan was re-releasing this week but we are waiting a bit more to merge some more goodies, so next week the change will likely be live

@facchinm facchinm closed this as completed Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants