Interruption when USB is connected

Hi.

Could you please tell me how to trigger an interrupt when changing the USBREGSTATUS register?

I can monitor the state of this register in polling mode, but I don't know how to trigger an interrupt when it changes. Could you please provide a code example how to do it rationally with minimal memory usage of the microcontroller?

Thanks.

Parents Reply
  • Hi Hakon. Thank you for your response with an example.

    But I am not yet able to implement this function in my application. I'm getting errors that I can't fix.

    Here's my code -->

    #include <stdio.h>
    #include <zephyr/kernel.h>
    #include <zephyr/drivers/gpio.h>
    #include <zephyr/usb/usb_device.h>
    
    #include <zephyr/logging/log.h>
    LOG_MODULE_REGISTER(v52820, LOG_LEVEL_DBG);
    
    static void usbd_status(enum usb_dc_status_code cb_status, const uint8_t *param)
    {
    	switch (cb_status) {
    	case USB_DC_CONNECTED:
    		LOG_DBG("USB_DC_CONNECTED");
    		break;
    	case USB_DC_DISCONNECTED:
    		LOG_DBG("USB_DC_DISCONNECTED");
    		break;
    	default:
    		break;
    	}
    }
    
    int main(void)
    {
    	int err;
    
    	err = usb_enable(usbd_status);
    	if (err) {
    		LOG_ERR("usb_enable: %d", err);
    		return false;
    	}
    
    	while (1){
    	
    		k_msleep(1000);			
    	}
    
    	return 0;
    }

    prj.conf file -->

    CONFIG_GPIO=y
    CONFIG_LOG=y
    CONFIG_USB_DEVICE_STACK=y

    Here are the errors I see while building the project -->

    ...

    Can you please tell me where I'm making a mistake?

    Does the prj.conf file need to include anything else besides CONFIG_USB_DEVICE_STACK?

    Thanks.

Children
Related