Own snippets in nRF Connect for VS Code

I have created a Zephyr Snippet (derived from the cdc-acm-console sample).

I am unable to select it in the Build Configuration. It is listed in the dropbox where the sample snippets are listed. When I add it via Browse, I can only select files, not a directory. Thus I am selecting the snippet.yml in my directory. This adds the file to the snippets:

Which is given as is to west:


west build --build-dir /home/markus/ncs/v2.6.1/zephyr/samples/hello_world/build /home/markus/ncs/v2.6.1/zephyr/samples/hello_world --pristine --board nrf52840dk_nrf52840 -- -DNCS_TOOLCHAIN_VERSION=NONE -DSNIPPET=snippets/oppo-serial/snippet.yml
[...]
CMake Error at /home/markus/ncs/v2.6.1/zephyr/cmake/modules/snippets.cmake:93 (message):
snippets: error: snippets not found: snippets/oppo-serial/snippet.yml
Please choose from among the following snippets:
cdc-acm-console
nordic-ppr
nordic-ppr-ram
nrf70-debug
nrf70-fw-patch-ext-flash
nrf91-modem-trace-ext-flash
nrf91-modem-trace-uart
oppo-serial
tfm-enable-share-uart
xen_dom0

West ist able to see the snippet under its name, but complains that it is given as snippet.yml

I am unable to change this via the pen:

Since that is not editable.

Custom snippets are thus broken currently.

Options:

* List custom snippets in application directory.

* Allow selecting the snippet directory and strip snippets/ from it

* Allow editing in the dropbox so that it can be manually selected

Work-arounds:
* build manually

* copy snippet into global directory and restart extension, then it is listed.

Are snippets in the application supposed to be supported?

Parents
  • Hello,

    Yes, I see what you are seeing. I will ask our developers how this is supposed to work, and how you can add snippets outside the NCS folder. 

    Q1: Where are you currently storing your snippet? In a folder inside NCS or outside?

    Q2: Can you try storing it either in ncs\nrf\snippets, or in ncs\zephyr\snippets, and then use the the additional "Extra CMake argument":

    -DSNIPPET="oppo-serial"

    Like this:

    Does that work with your snippet?

    I know it is not ideal, but in the meantime I will try to figure out if it is possible to add snippets from outside the SDK folder, and how to do it in VS Code.

    Best regards,

    Edvin

  • Just putting the snippet into ncs\zephyr\snippets makes it available in the selection box. Might require a restart of VScode. Did not verify.

Reply Children
  • Yes, I saw. It is also possible to add it to your application root folder (the application that you are working in). 

    I found it by looking in the ncs\zephyr\cmake\modules\snippets.cmake, and saw that it mentioned "APPLICATION_SOURCE_DIR".

    I guess the question is how to use this outside the application folder (because I imagine you would want to have a folder where you keep all your snippets), and outside the SDK (to keep it pristine). That is where it becomes a little more tricky.

    If your application is part of a Zephyr Module, then it is possible to add your own snippet root when including it in your build system:

    https://docs.zephyrproject.org/latest/develop/modules.html#build-settings

    Best regards,

    Edvin

  • I should mention that discussing this with our extension developers, they realized that the browse functionality that you referred to isn't working as intended. They will try to fix it for the next version Slight smile If that works as intended, you should be able to store your snippets anywhere, and select them from that menu.

    Best regards,

    Edvin

  • Would I be right in saying this still doesn't work?

    In my case, I'm even happy to accept putting snippets directly in the applcation folder. But that's not working for me either. 

    Based on reading the zephyr docs on the subject of snippets and the SNIPPET_ROOT, I would expect to be save snippets as eg - {app folder}/snippets/{board}/snippets.yml.  I even went to the trouble of explicitly adding the app root to the SNIPPET_ROOT variable (which Ithink whould actually be set by default), and verified that it was correct. But even with all of that, my custom snippets do NOT appear in the build configuration drop down. 

    I have no idea whether it's relevant, but the snippets list is empty in .vscode-nrf-connect.json file inside the build folder. Obviously this is a generated file, so only mention as evidence. 

    Searching around the build folder, I actually notice that my custom snippet appears in the snippets_generated.json in {build}/{app}/zephyr/      However, obviously this has no effect on the nrf connect's ability to correctly pick this up and add it to the build configuration drop down. 

    Would be great if this stuff was easier. 

    UPDATE

    ------------

    Adding -DSNIPPET=mysnippet adds the snippet - but it breaks due to multi-image build.

    -D1-air_SNIPPET=mysnippet works. And limits the application 

    After I get it working, mysnippet appears from that point on in the drop down! Which is just priceless. Could you put your heads together and fix this. The whole point of your extension is so that developers don't need to be experts in zephyr and cmake. 

  • Hello,

    Monkeytronics said:
    After I get it working, mysnippet appears from that point on in the drop down! Which is just priceless.

    Can you please describe what exactly you needed to get working in order to do this? I agree that it shouldn't be that troublesome to add this, but if you can guide me to get this working locally, it would be easier to point our developers in the right direction. 

    Is it possible to upload an application with a custom snippet that appears in the drop down? And some guide to hhow you got it to work? (I have not tried this since the last time there was activity in this ticket, which was back in October 2024).

    Best regards,

    Edvin

Related