arduino / ArduinoCore-mbed

344 stars 199 forks source link

Need Clarity on Arduino and Portenta with Native USB causing hanging #929

Open custeve opened 2 months ago

custeve commented 2 months ago

** Copied from a post on the Arduino Portenta H7 forum:

I'm struggling to understand why I am not finding more information about the best approach to handle the native USB Serial port on an H7, in my case, on a Portenta Machine Control device. After hours of trying to determine why any simple Arduino Portenta example for Ethernet connectivity hangs when the USB cable is removed from the device - the problem being Ethernet related was a red herring. Finally, commenting out all the Serial.* statements in my code, fixed the problem.

So - what is the standard approach for the typical Arduino "Serial.print" debugging approach, if Serial.print statements will brick the current running code if the USB cable is not connected? I may look at my own code at the moment to see if I can easily detect the condition, and skip the print statements, but I would expect this to be handled better by the Arduino core for the mbed devices. Removing all the Serial.print statements from a large codebase, so you can run it with the USB disconnected, is not practical, nor does it promote an Arduino standard usage.

Am I missing something here???

An example of my issue - The included WebServer.ino script in Arduino Portenta H7 Examples. Works fine with USB connected. Bricks with USB disconnected. Works with all Serial. statements commented out.

custeve commented 2 months ago

I have some more info... after tinkering some more, this morning, the issue was occurring when USB had been connected and then disconnected - regardless of the existence of the While(!Serial.... check in the setup. Eliminating the check AND rebooting the Portenta after disconnecting the USB is they key.