2020-12-14 03:21 AM
To save the least uA in one design I leave the VDDUSB unconnected until a powered USB is plugged in. When the 5V from USB is present a transistor enables the 3.3V to reach the VDDUSB pin.
The code generated by CubeMX strightly calls MX_USB_DEVICE_Init() which never returns, if the USB is unplugged, because an error interrupt from the USB petipheral fires continuosly locking the CPU.
As far as I understand there is no /* USER CODE */ hook to change this behavior.
How can I manage this situation in a clean way to avoid to repeat changes at every code generation?
Other than delaying the USB initialization until really powered, is there some hint or example to init and deinit the USB petipheral under software control, with the assumption that the USB peripheral could suddenly be powered off when the USB is unplugged.
Any suggestion?
Thanks.
Mau.