This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

DFU and Serial communication over USB

I am trying to enable DFU over USB with the nRF52480, while keeping the possibility for Serial communication. I got a working example with both separate, however when I try to combine the examples I get a lot problems.

As of my understanding I have to use the nrf_dfu_trigger_usb.h library, however I can't seem to figure out how. The documentation says to call "nrf_dfu_trigger_usb_init()" after USB is initialized but before it is enabled. Do you have an example of how to do this, i.e. how to use DFU over USB while still using the USB for something else (Serial communication)?

I guess my main problem is that the DFU library initialises the variable "m_app_cdc_acm" and thus I cannot use do that myself for the Serial communication. Should I access this variable through something like: "extern const app_usbd_cdc_acm_t m_app_cdc_acm", or am I missing some basic understanding of how this works Slight smile

Also when compiling I get a lot of undefined reference to f.x. `slip_decode_add_byte' and `crc32_compute'. I have added the files containing these functions to my makefile, but I am wondering if the order of the includes makes a difference? 

Thanks Smiley

Parents
  • Thanks for your answer Susheel!

    EDIT:

    I now understand how the bootloader works, and must admit I had it all wrong, and learned a lot from: https://devzone.nordicsemi.com/nordic/short-range-guides/b/software-development-kit/posts/getting-started-with-nordics-secure-dfu-bootloader

    I have now build the "open bootloader" and flashed that AND my application containing my project. The bootloader works, and I can enter the bootloader by pressing the RESET button. I can also succesfully flash new firmware using the nRF Connect app. SO far so good! 

    Next, I have been trying to get the USB DFU Trigger to work, however with no success. I have added to my sdk_config:

    // <q> APP_USBD_NRF_DFU_TRIGGER_ENABLED
    #ifndef APP_USBD_NRF_DFU_TRIGGER_ENABLED
    #define APP_USBD_NRF_DFU_TRIGGER_ENABLED 1
    #endif
    
    // <q> NRF_USB_DFU_TRIGGER_USB_SHARED  - Flag indicating whether USB is used for other purposes in the application.
    #ifndef NRF_DFU_TRIGGER_USB_USB_SHARED
    #define NRF_DFU_TRIGGER_USB_USB_SHARED 1
    #endif
    
    // <o> NRF_USB_DFU_TRIGGER_INTERFACE_NUM - The USB interface to use for the DFU Trigger library.  <0-255>
    
    // <i> According to the USB Specification, interface numbers cannot have
    // <i> gaps. Tailor this value to adhere to this limitation.
    #ifndef NRF_DFU_TRIGGER_USB_INTERFACE_NUM
    #define NRF_DFU_TRIGGER_USB_INTERFACE_NUM 1
    #endif

    And my USB init function looks like (called in beginning of main):

    void usb_init()
    {
        ret_code_t ret;
        static const app_usbd_config_t usbd_config = {
            .ev_state_proc = usbd_user_ev_handler
        };
    
        ret = nrf_drv_clock_init();
        APP_ERROR_CHECK(ret);
        
        nrf_drv_clock_lfclk_request(NULL);
    
        // Wait for the LFCLK
        while(!nrf_drv_clock_lfclk_is_running()){}
    
        // Initiate the USB 
        app_usbd_serial_num_generate();
    
        ret = app_usbd_init(&usbd_config);
        APP_ERROR_CHECK(ret);
    
        app_usbd_class_inst_t const * class_cdc_acm = app_usbd_cdc_acm_class_inst_get(&m_app_cdc_acm);
        ret = app_usbd_class_append(class_cdc_acm);
        APP_ERROR_CHECK(ret);
    
        nrf_dfu_trigger_usb_init();
    
        ret = app_usbd_power_events_enable();
        APP_ERROR_CHECK(ret);
    }

    I have inserted the nrf_dfu_trigger_usb_init() before I enable the USB bus, however I see that nrf_dfu_trigger_usb_init does most of this by it self. How should I approach this?

    If anyone has an example of how to use the USB DFU Trigger library, I would be very glad Smiley

Reply
  • Thanks for your answer Susheel!

    EDIT:

    I now understand how the bootloader works, and must admit I had it all wrong, and learned a lot from: https://devzone.nordicsemi.com/nordic/short-range-guides/b/software-development-kit/posts/getting-started-with-nordics-secure-dfu-bootloader

    I have now build the "open bootloader" and flashed that AND my application containing my project. The bootloader works, and I can enter the bootloader by pressing the RESET button. I can also succesfully flash new firmware using the nRF Connect app. SO far so good! 

    Next, I have been trying to get the USB DFU Trigger to work, however with no success. I have added to my sdk_config:

    // <q> APP_USBD_NRF_DFU_TRIGGER_ENABLED
    #ifndef APP_USBD_NRF_DFU_TRIGGER_ENABLED
    #define APP_USBD_NRF_DFU_TRIGGER_ENABLED 1
    #endif
    
    // <q> NRF_USB_DFU_TRIGGER_USB_SHARED  - Flag indicating whether USB is used for other purposes in the application.
    #ifndef NRF_DFU_TRIGGER_USB_USB_SHARED
    #define NRF_DFU_TRIGGER_USB_USB_SHARED 1
    #endif
    
    // <o> NRF_USB_DFU_TRIGGER_INTERFACE_NUM - The USB interface to use for the DFU Trigger library.  <0-255>
    
    // <i> According to the USB Specification, interface numbers cannot have
    // <i> gaps. Tailor this value to adhere to this limitation.
    #ifndef NRF_DFU_TRIGGER_USB_INTERFACE_NUM
    #define NRF_DFU_TRIGGER_USB_INTERFACE_NUM 1
    #endif

    And my USB init function looks like (called in beginning of main):

    void usb_init()
    {
        ret_code_t ret;
        static const app_usbd_config_t usbd_config = {
            .ev_state_proc = usbd_user_ev_handler
        };
    
        ret = nrf_drv_clock_init();
        APP_ERROR_CHECK(ret);
        
        nrf_drv_clock_lfclk_request(NULL);
    
        // Wait for the LFCLK
        while(!nrf_drv_clock_lfclk_is_running()){}
    
        // Initiate the USB 
        app_usbd_serial_num_generate();
    
        ret = app_usbd_init(&usbd_config);
        APP_ERROR_CHECK(ret);
    
        app_usbd_class_inst_t const * class_cdc_acm = app_usbd_cdc_acm_class_inst_get(&m_app_cdc_acm);
        ret = app_usbd_class_append(class_cdc_acm);
        APP_ERROR_CHECK(ret);
    
        nrf_dfu_trigger_usb_init();
    
        ret = app_usbd_power_events_enable();
        APP_ERROR_CHECK(ret);
    }

    I have inserted the nrf_dfu_trigger_usb_init() before I enable the USB bus, however I see that nrf_dfu_trigger_usb_init does most of this by it self. How should I approach this?

    If anyone has an example of how to use the USB DFU Trigger library, I would be very glad Smiley

Children
No Data
Related