Lolin_s2_mini ESP.restart() Exception disconnects USB port

Since the ESP32S2 chip implements the USB connection itself (it has the USB peripheral), when it restarts, it temporarily loses its USB connection and then reconnects. This is expected behavior. The same goes for other microcontrollers implementing USB themselves, such as Atmel ATSAMD21 chips.

Other microcontroller boards don’t do this if they have a dedicated USB-serial chip (e.g., CH340, CP2102, …) on them that is not affected by the restart of the main microcontroller, and thus don’t have this problem.

I’m not sure whether anything can be done against that at all – The USB disconnect is pretty much bound to happen when you ESP.restart(). I guess PlatformIO could have an option where it tries to reconnect to the lost device for a while. You can file that as a feature request in Issues · platformio/platformio-core · GitHub.