<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>DFU and Serial communication over USB</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/60232/dfu-and-serial-communication-over-usb</link><description>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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 18 Apr 2020 21:46:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/60232/dfu-and-serial-communication-over-usb" /><item><title>RE: DFU and Serial communication over USB</title><link>https://devzone.nordicsemi.com/thread/245355?ContentTypeID=1</link><pubDate>Sat, 18 Apr 2020 21:46:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7dd5707b-6767-4df8-a8f7-4c5fed19bc7e</guid><dc:creator>MrSolidGeek</dc:creator><description>&lt;p&gt;Finally, I got it working! The &amp;quot;nRF Connect DFU Trigger&amp;quot; now shows in the device manager, and the nRF Connect tool recognizes and triggers the DFU correctly.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1587246003091v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;For anyone in the future who might need to do the same I will try to document my findings as good as possible. This issue on Github gave me a lot of clues:&amp;nbsp;&lt;a href="https://github.com/NordicSemiconductor/pc-nrfconnect-programmer/issues/116"&gt;https://github.com/NordicSemiconductor/pc-nrfconnect-programmer/issues/116&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I used the example USBD_CDC_ACM (&amp;quot;\examples\peripheral\usbd_cdc_acm&amp;quot;) as a starting point, as this has most of the configuration already. I added/changed a few things to the sdk_config:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// &amp;lt;s&amp;gt; APP_USBD_PID - Product ID.
#ifndef APP_USBD_PID
#define APP_USBD_PID 0xC00A
#endif

// &amp;lt;q&amp;gt; APP_USBD_CONFIG_SELF_POWERED  - Self-powered device, as opposed to bus-powered.
#ifndef APP_USBD_CONFIG_SELF_POWERED
#define APP_USBD_CONFIG_SELF_POWERED 0
#endif

// &amp;lt;q&amp;gt; APP_USBD_NRF_DFU_TRIGGER_ENABLED
#ifndef APP_USBD_NRF_DFU_TRIGGER_ENABLED
#define APP_USBD_NRF_DFU_TRIGGER_ENABLED 1
#endif

// &amp;lt;q&amp;gt; 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

// &amp;lt;o&amp;gt; NRF_USB_DFU_TRIGGER_INTERFACE_NUM - The USB interface to use for the DFU Trigger library.  &amp;lt;0-255&amp;gt;
#ifndef NRF_DFU_TRIGGER_USB_INTERFACE_NUM
#define NRF_DFU_TRIGGER_USB_INTERFACE_NUM 0
#endif&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And changed the interface numbers for the actual USB:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// As DFU Trigger uses interface 0, CDC must use 1 and 2
#define CDC_ACM_COMM_INTERFACE  1
#define CDC_ACM_DATA_INTERFACE  2&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I added the function usb_init which is called just at the beginning of main:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;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);

    while(!nrf_drv_clock_lfclk_is_running()){}

    ret = app_timer_init();
    APP_ERROR_CHECK(ret);

    app_usbd_serial_num_generate();

    ret = app_usbd_init(&amp;amp;usbd_config);
    APP_ERROR_CHECK(ret);

    // Enable DFU Trigger library over USB (should happen right after usbd_init)
    nrf_dfu_trigger_usb_init();

    // USBD CDC ACM example started
    app_usbd_class_inst_t const * class_cdc_acm = app_usbd_cdc_acm_class_inst_get(&amp;amp;m_app_cdc_acm);
    ret = app_usbd_class_append(class_cdc_acm);
    APP_ERROR_CHECK(ret);

    if (USBD_POWER_DETECTION)
    {
        ret = app_usbd_power_events_enable();
        APP_ERROR_CHECK(ret);
    }
    else
    {
        // No USB power detection enabled. Starting USB now
        app_usbd_enable();
        app_usbd_start();
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And of course, imported the needed libraries:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;INC_FOLDERS += \
  $(SDK_ROOT)/components/libraries/bootloader/dfu \
  $(SDK_ROOT)/components/libraries/usbd/class/nrf_dfu_trigger \
  $(SDK_ROOT)/components/libraries/block_dev \

SRC_FILES += \
  $(SDK_ROOT)/components/libraries/usbd/class/nrf_dfu_trigger/app_usbd_nrf_dfu_trigger.c \
  $(SDK_ROOT)/components/libraries/bootloader/dfu/nrf_dfu_trigger_usb.c \&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I guess it was quite easy after all, it was just hard to find the documentation needed to do so. An example added to the SDK would be a good way to go in the future :D&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU and Serial communication over USB</title><link>https://devzone.nordicsemi.com/thread/245099?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2020 21:56:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:014fb78e-2253-4111-8068-81f1ad8bacb0</guid><dc:creator>MrSolidGeek</dc:creator><description>&lt;p&gt;Thanks for your answer Susheel!&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;EDIT:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I now understand how the bootloader works, and must admit I had it all wrong, and learned a lot from:&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://devzone.nordicsemi.com/nordic/short-range-guides/b/software-development-kit/posts/getting-started-with-nordics-secure-dfu-bootloader"&gt;https://devzone.nordicsemi.com/nordic/short-range-guides/b/software-development-kit/posts/getting-started-with-nordics-secure-dfu-bootloader&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I have now build the &amp;quot;open bootloader&amp;quot; and flashed that AND&amp;nbsp;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!&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Next, I have been trying to get the USB DFU Trigger to work, however with no success. I have added to my sdk_config:&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// &amp;lt;q&amp;gt; APP_USBD_NRF_DFU_TRIGGER_ENABLED
#ifndef APP_USBD_NRF_DFU_TRIGGER_ENABLED
#define APP_USBD_NRF_DFU_TRIGGER_ENABLED 1
#endif

// &amp;lt;q&amp;gt; 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

// &amp;lt;o&amp;gt; NRF_USB_DFU_TRIGGER_INTERFACE_NUM - The USB interface to use for the DFU Trigger library.  &amp;lt;0-255&amp;gt;

// &amp;lt;i&amp;gt; According to the USB Specification, interface numbers cannot have
// &amp;lt;i&amp;gt; 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&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And my USB init function looks like (called in beginning of main):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;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(&amp;amp;usbd_config);
    APP_ERROR_CHECK(ret);

    app_usbd_class_inst_t const * class_cdc_acm = app_usbd_cdc_acm_class_inst_get(&amp;amp;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);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I have inserted the&amp;nbsp;nrf_dfu_trigger_usb_init() before I enable the USB bus, however I see that&amp;nbsp;nrf_dfu_trigger_usb_init does most of this by it self. How should I approach this?&lt;br /&gt;&lt;br /&gt;If anyone has an example of how to use the USB DFU Trigger library, I would be very glad &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f603.svg" title="Smiley"&gt;&amp;#x1f603;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU and Serial communication over USB</title><link>https://devzone.nordicsemi.com/thread/245025?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2020 13:47:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b31373aa-0a69-4326-b6fc-60025be02aae</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;MrSolidGeek,&lt;/p&gt;
[quote user=""]As of my understanding I have to use the&amp;nbsp;nrf_dfu_trigger_usb.h library, however I can&amp;#39;t seem to figure out how. The documentation says to call &amp;quot;&lt;span&gt;nrf_dfu_trigger_usb_init()&amp;quot;&amp;nbsp;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)?&lt;/span&gt;[/quote]
&lt;p&gt;Unfortunately, we have not tried the combo to work together ourselves. So I am not sure what are the efforts and challenges involved to integrate them. Sorry that this answer is not much of any help. Lets wait out to see if any other forum members experimented with it.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>