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

nRF5340 - DFU over serial mission impossible

Hi,

My system is
  - nRF5340 custom board
  - Zephyr OS build v2.3.0-rc1-ncs1
  - nRF-Connect-SDK v1.2.0
To perform DFU over UART I was told to merge MCUBoot + mcumgr + smp_srv along with my application (MyApp).
Moving some config switches allowed me to
a) Build and program mcuboot in bootloader partition (using nrjprog over SWD)
b) Build and program MyApp (or smp_srv) in slot-0 (using nrjprog over SWD)
c) Build and DFU upload MyApp in slot-1 (using mcumgr over UART)
d) Confirm slot-1 image (using mcumgr over UART)
To finish the job I have to re-initiate DFU from within MyApp, passing control to smp_srv again, otherwise all this stuff makes no sense, really.
Is there an engineer from Nordic who knows how to do it ?
Best Regards
  • To finish the job I have to re-initiate DFU from within MyApp, passing control to smp_srv again, otherwise all this stuff makes no sense, really.

     Why do you need to do this? Can't you just follow the procedure from here?

    • Test the image
      • On next reset the uploaded image will remain in slot 0
    • Reset the device
      • This can be done by clicking the reset button, or remotely
    • Confirm the image
      • This is to avoid the uploaded image to get swapped back into slot 1

    You should be aware of the following:

    "Note that if you try to send the very same image that is already flashed in slot-0 then the procedure will not complete successfully since the hash values for both slots will be identical."

    So don't upload the same image as is already present on the device

    Best regards,

    Simon

  • Since the first image (different hash) is successfully uploaded, tested and confirmed in slot-0, I cannot run mcumgr commands remotely anymore.

    The application takes control over the UART. Nobody can repeat DFU a second time via UART.

  • Can't you solve this by merging the smp_svr sample with your application? By that, I don't mean to merge the hex files, but do it on the code level. Put all the relevant functions from the smp_svr into your application. When you update the chip with a new application, make sure that contains the smp_svr related functions as well.

    Best regards,

    Simon

  • Dear Simon
    I've followed your hint and now I'm glad to announce you that it works!
    Now I have a different issue.
    It seems I cannot use UART-0 simultaneously for smp_srv and for user data exchange.
    This is a simplified version of my code.
    The init_uart() stuff does prevent smp_srv from working.

    int main(void)
    {
        int err;
        static boot foo = true;
    
        /* Enabling SMP Server functionalities */
    	err = STATS_INIT_AND_REG(smp_svr_stats, STATS_SIZE_32, "smp_svr_stats");
    	if (err < 0) {
    		printk("Error initializing stats system [%d]\n", err);
    		return -1;
    	}
    
    	os_mgmt_register_group();
    	img_mgmt_register_group();
    	stat_mgmt_register_group();
    
        /* Enabling UART-0 for user data exchange */
    	err = init_uart();
    	if (err) {
            printk("UART init failed [%d]\n", err);
    		return -1;
    	}
    
        while (1) {
            STATS_INC(smp_svr_stats, ticks); //<<<<<<<<<<<<<<<<<<<<<<< smp_srv
    
            /* wait for data from rx fifo */
            struct uart_data_t *buf = k_fifo_get(&fifo_uart_rx_data, K_FOREVER);  //<<<<<<<<< user data exchange
    
            /* parse user data */
            if (buf->data[0] = 3) {
                    foo = !foo;
            }
    
            k_free(buf);
        }
    }
    
     

  • Hi,
    I think I've fixed all major issues.
    When the application is running the init_uart is executed. The user can instruct the application to set a DFUMODE flag into flash (storage partition, NVS mode).
    On next reboot the flag state is read (to set the current mode of operation) and then immediately cleared in flash (for next reboot). When in dfu mode, the init_uart is skipped and the smp_srv management calls get executed, allowing mcumgr messages to be parsed and permitting the user to upload-test-confirm new images at will.
    Thank you for support.

Related