Hello Stefan,
I am sorry for the late reply. I am not sure what SDK project are you referring but I will take dev_cdc_vcom_bm as an example.
First you need to enable detach feature by setting the following define in usb_device_config.h file.
#define USB_DEVICE_CONFIG_DETACH_ENABLE (1U)
This will enable notification to the device callback through USB_DeviceAttachNotification and USB_DeviceDetachNotification functions.
#if USB_DEVICE_CONFIG_DETACH_ENABLE
case kUSB_DeviceNotifyDetach:
status = USB_DeviceDetachNotification(handle, message);
break;
case kUSB_DeviceNotifyAttach:
status = USB_DeviceAttachNotification(handle, message);
break;
#endif
Now you can implement what you like to do in USB_DeviceCallback when this events occurred. I just print message in console.
usb_status_t USB_DeviceCallback(usb_device_handle handle, uint32_t event, void *param)
{
usb_status_t error = kStatus_USB_Error;
uint16_t *temp16 = (uint16_t *)param;
uint8_t *temp8 = (uint8_t *)param;
switch (event)
{
case kUSB_DeviceEventAttach:
usb_echo("USB device attached\r\n");
break;
case kUSB_DeviceEventDetach:
usb_echo("USB device detached\r\n");
break;

I hope this helps!
Have a great day,
Felipe
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored.
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
------------------------------------------------------------------------------