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?

  • 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

  • Just have a go replicating what I describe. I'm sure a zephyr expert could get this working in 5 minutes. If there is an issue in how the nordic sdk handles the build process, it should become apparent for you as it has for me. Equally, if I've missed an obvious step, it might be worth documenting it for future. 

  • Ok, so I tested now, copied a snippet (used the hw-flow-control found in NCS\nrf\snippets), created a folder named "snippets" in my application folder, and pasted the snippet in there. I renamed the folder "my-hw-flow-control" (from hw-flow-control), and changed the name of the snippet inside snippet.yml from:

    name: hw-flow-control
    to
    name: my-hw-flow-control

    After this, you need to restart VS Code for it to reload the snippets in your applications (or you can use the reload window option by pressing ctrl+shift+p, and enter the command "reload window" and hit enter).

    Then the custom snippet "my-hw-flow-control" should appear in the list.

    Best regards,

    Edvin

  • OK. Must be the reload window that was missing... Couldn't you make it so that this step is not necessary. In my frustration to make progress, I spent time figuring out how to bring in conf files directly through cmake instead. Which works fine as it happens. I think I 'll stick with that as it does not require that I remember any magic steps or incantations to work. 

Related