Combining DTM and dfu-next samples

I am trying to get the nrf/sampoles/bluetooth/direct_test_mode working together with the code from zephyr/samples/subsys/usb/dfu-next. 
I have the DTM mode running correctly, but can't integrate the dfu mode to this sample. 
I started with the dtm sample, added the dfu logic in to dfu.h/dfu.c and added dfu_init to the dtm main.c. 
Unfortunately I've hit two stumble blocks: 
- the remote_shell part of the multi image build seems to be somehow hardcoced to the samples directory - whatever I try the build system always searches for remote_shell in the nrf/samples/nrf5340/remote_shell directory. I would however like to alter the code "locally", not in the SDK folder. You can overwrite settings for remote_shell (see below), but I can't figure out how to overwrite source files (e.g. main.c) with custom code. 
- When enabling DFU mode in the project sysbuild/remote_shell/prj.conf overwrite. There seems to be a logic problem: the direct_test_mode sample needs to be compiled for cpunet core (see readme of the sample). However, dfu mode needs to be enabled for the app core. alter the (SDK sample directory) code to be able to set the same code changes I'm hit with 
errors like: 
: error: 'PM_MCUBOOT_SECONDARY_ID' undeclared (first use in this function)
   65 | #define PM__mcuboot_secondary_ID PM_MCUBOOT_SECONDARY_ID
After investigating, I think the problem is that PM expects the app-core application to be the parent image, but in this configuration it is the child image and thus downstream settings get confused and  the image does not compile.

Could you please assist me in creating a DTM project, that is updatable via dfu mode?

Thank you very much, 
simeg
Parents
  • Hi Edvin, 

    thank you for looking in to this. 
    The nrf5340 will be part of another product and enable new features for our users. 
    We want to have various apps that the user can cycle through on our products: the user will select an "app" and it will be pushed to the nrf5340 in the background via USB dfe from a linux host.
    The DTM mode will be one such application, which will only be available for a select view users (mainly internal testing, production chain, certification labs, etc.). 
    We have this workflow working for other applications, but the DTM applications does not yet work.

    We use the Ublox Nora B - I've included the boards directory for this board. 
    I've also included the modified sample code.
    Please do not hesitate to contact me, if you have any further questions. 
    If you send me a DM I can also give you my company contact informations. 

     dtm_and_dfe_together.tar.gz

  • Just to be clear, it is the direct_test_mode, and not the sample_code_remote_shell we are trying to build?

    What is your build command? "west build -b ubc_evknorab10_nrf5340/nrf5340/cpuapp" ? or some additional build flags?

    Best regards,

    Edvin

  • Yes, exactly, the direct_test_mode is the project we are trying to build. 
    If I copy the sample_code in to the nrf/samples/nrf5340/remote_shell directory, I actually get the DTM application to show up in dfu - alas only the Ramdisk. 

    This is my west build command, as generated by VS Code nrf connect plugin: 

    west build --build-dir /home/user/workspace/nrf-bluetooth/direct_test_mode/build /home/user/workspace/nrf-bluetooth/direct_test_mode --pristine --board ubx_evknorab10/nrf5340/cpunet --sysbuild -- -DBOARD_ROOT="/home/user/workspace/nrf-bluetooth"

Reply
  • Yes, exactly, the direct_test_mode is the project we are trying to build. 
    If I copy the sample_code in to the nrf/samples/nrf5340/remote_shell directory, I actually get the DTM application to show up in dfu - alas only the Ramdisk. 

    This is my west build command, as generated by VS Code nrf connect plugin: 

    west build --build-dir /home/user/workspace/nrf-bluetooth/direct_test_mode/build /home/user/workspace/nrf-bluetooth/direct_test_mode --pristine --board ubx_evknorab10/nrf5340/cpunet --sysbuild -- -DBOARD_ROOT="/home/user/workspace/nrf-bluetooth"

Children
  • I see this:

    Parsing C:/nordic/SDKs/ncs/v3.1.1/nrf/samples/nrf5340/direct_test_mode/Kconfig.sysbuild
    C:/nordic/SDKs/ncs/v3.1.1/zephyr/scripts/kconfig/kconfig.py: C:/nordic/SDKs/ncs/v3.1.1/nrf/samples/nrf5340/direct_test_mode/Kconfig.sysbuild:67: 'C:/nordic/SDKs/ncs/v3.1.1/nrf/samples/nrf5340/direct_test_mode\../common/usb/Kconfig.sample_usbd' not found (in 'rsource "../common/usb/Kconfig.sample_usbd"')

    Outside the application folder, what "common" folder is it trying to point to? Where exactly do I need to place the direct_test_mode folder?

    You said you place it in the nrf\samples\nrf5340\remote_shell directory, but this does not have a "common" folder in it's parent folder.

    Best regards,

    Edvin

  • Ah, sorry - I missed the "common" directory. 
    It is however just some effort on my side to try to get all files that the project needs out of the SDK folder and in to the repository. 
    This came together, because I had problem described in this ticket and I tried to "copy" all files in to the repo, that the original direct_test_mode project needs.

    Please find attached the an archive with this common directory included.

    I am very sorry to have missed this the first round...dtm_and_dfe_together_v2.tar.gz

  • No worries. I didn't get the time to look into these today, but I will try next week.

    Best regards,

    Edvin

  • Ok, just tried building the sample now, using NVS v3.1.1 (and toolchain 3.1.1), and it built without any errors.

    I used the command:

    west build -b ubx_evknorab10/nrf5340/cpunet -d build -- -DBOARD_ROOT="../."

    Can you try to update the toolchain to v3.1.1 as well? 

    Best regards,

    Edvin

  • Hi Edvin, 

    Thank you again for looking in to this .
    YES, the project - as is -  builds successfully. 
    This was however not the issue or the question I was trying to ask:
    the problem is how to get DTM and DFU working together. 

    I am unclear how we can modify the DTM code to add USB-DFU functionality to it. 
    Also, how we can get west to use local sources, e.g. while building I get a warning: 

    57/242] Building C object CMakeFiles/app.dir/src/main.c.obj
    /home/user/ncs/v3.1.1/nrf/samples/nrf5340/remote_shell/src/main.c: In function 'main':
    /home/user/ncs/v3.1.1/nrf/samples/nrf5340/remote_shell/src/main.c:138:15: warning: implicit declaration of function 'dfu_init' [-Wimplicit-function-declaration]
      138 |         err = dfu_init();
          |               ^~~~~~~~

    Here you see that nrf connect uses "main.c" from the "samples" directory, I would however like that this code would exist locally in our git repository and that west does use source code from other folders. 

    ---

    After flashing the project it shows up in the "dfu-util" utility: 

    user:~/workspace/nrf-bluetooth/direct_test_mode(user.dfu_and_dtm)$ sudo dfu-util -l
    dfu-util 0.11
    
    Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
    Copyright 2010-2021 Tormod Volden and Stefan Schmidt
    This program is Free Software and has ABSOLUTELY NO WARRANTY
    Please report bugs to http://sourceforge.net/p/dfu-util/tickets/
    
    Found Runtime: [2fe3:0001] ver=0401, devnum=35, cfg=1, intf=2, path="3-7.4.5", alt=0, name="UNKNOWN", serial="8924B12F028AA082"

    However, the chip can not successfully be flashed: 

    user:~/workspace/nrf-bluetooth/direct_test_mode(user.dfu_and_dtm)$ sudo dfu-util --alt 0 --download build/direct_test_mode/zephyr/zephyr.signed.bin 
    dfu-util 0.11
    
    Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
    Copyright 2010-2021 Tormod Volden and Stefan Schmidt
    This program is Free Software and has ABSOLUTELY NO WARRANTY
    Please report bugs to http://sourceforge.net/p/dfu-util/tickets/
    
    dfu-util: Warning: Invalid DFU suffix signature
    dfu-util: A valid DFU suffix will be required in a future dfu-util release
    Opening DFU capable USB device...
    Device ID 2fe3:0001
    Run-Time device DFU version 0110
    Claiming USB DFU (Run-Time) Interface...
    Setting Alternate Interface zero...
    Determining device status...
    DFU state(0) = appIDLE, status(0) = No error condition is present
    Device really in Run-Time Mode, send DFU detach request...
    Device will detach and reattach...
    Opening DFU USB Device...
    Claiming USB DFU Interface...
    Setting Alternate Interface #0 ...
    Determining device status...
    DFU state(2) = dfuIDLE, status(0) = No error condition is present
    DFU mode device DFU version 0110
    Device returned transfer size 512
    Copying data from PC to DFU device
    Download        [                         ]   0%            0 bytesdfu-util: Error during download (LIBUSB_ERROR_PIPE)

    It seems that the dfu functionality is not "present" once the device is detached.

    Could you please assist us in getting DTM working together with DFU mode?

Related