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.

  • 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

Reply Children
Related