diff --git a/usb/device/USBDevice/USBDevice.cpp b/usb/device/USBDevice/USBDevice.cpp index 0788358b21..3c73170c4b 100644 --- a/usb/device/USBDevice/USBDevice.cpp +++ b/usb/device/USBDevice/USBDevice.cpp @@ -1248,6 +1248,12 @@ USBDevice::USBDevice(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint1 _device.suspended = false; } +USBDevice::~USBDevice() +{ + MBED_ASSERT(!_initialized); + deinit(); +} + uint32_t USBDevice::endpoint_max_packet_size(usb_ep_t endpoint) { lock(); diff --git a/usb/device/USBDevice/USBDevice.h b/usb/device/USBDevice/USBDevice.h index d5a91f1b26..a1b491574b 100644 --- a/usb/device/USBDevice/USBDevice.h +++ b/usb/device/USBDevice/USBDevice.h @@ -82,6 +82,14 @@ public: */ USBDevice(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release); + /** + * Cleanup this USBDevice + * + * This USBDevice must be uninitialized when the destructor is + * called or the behavior is undefined. + */ + virtual ~USBDevice(); + /** * Initialize this instance *