I think this would be a bit difficult for the following reason. After switching to the USB_SERIAL_JTAG, the host would need to re-enumerate the device. However this will require some time. The panic handler code would have to wait for the enumeration to finish, but it's not clear how long we need to wait for that to happen. If the host is not connected (or enumeration doesn't happen for some reason) then we might end up getting stuck in the panic handler.
Besides, the serial port created by the OS for the usb_serial_jtag will not be the same as the one created by the OS for TinyUSB CDC device, so your terminal program will not automatically show you the panic handler output — it will be sent to a different serial port.
I would suggest doing one of the following, instead:
- Use the internal PHY for one USB port (e.g. USB_OTG peripheral with tinyusb) and an external USB PHY for another (e.g. USB_SERIAL_JTAG). In the final product, don't populate one of the ports (debugging) on the PCB.
- Use UART for diagnostics and the built-in USB port for the USB functionality with tinyusb.