Defining preprocessor options using Visual Studio Code

I'm transitioning from SES to Visual Studio Code.

In SES, I can define multiple builds and then define preprocessor options (eg. -DOPTION1) for each build definition

I don't see a way to do this when using the nRF Connect SDK and Visual Studio Code.

(Note:  I know how to specify defines using the CMakeLists.txt file for all builds (using add_definitions(-DOPTION1) , but not on a "per-build" basis).

I'm using the NRF CONNECT extension in Visual Studio Code.

Thanks!

Parents
  • Really, I have the latest version of VS code and the nRF Connect extension as well. What nRF Connect SDK version are you working on, and have you opened it through the Toolchain manager app or set it up manually?

    Best regards,

    Simon

  • How odd.  No I do not have "Save Configuration as Preset" - I have seen it in Nordic documentation but assumed it had been deprecated. Full versions:

    nRF Connect for Desktop v4.2.1

    Toolchain Manager v1.2.6

    nRF Connect SDK v2.4.1 (current project, not updating, v2.3.0 also installed)

    VS Code v1.83.1 (see below for about box copy)

    Extensions are all the latest, checked for updates at time of writing (see below again for full copies)

    I usually dont launch from Toolchain manager but did just now and still no option to save the build configuration.

    VS Code about:

    Version: 1.83.1 (user setup)
    Commit: f1b07bd25dfad64b0167beb15359ae573aecd2cc
    Date: 2023-10-10T23:48:05.904Z
    Electron: 25.8.4
    ElectronBuildId: 24154031
    Chromium: 114.0.5735.289
    Node.js: 18.15.0
    V8: 11.4.183.29-electron.0
    OS: Windows_NT x64 10.0.22621

    Nordic extensions:

    Name: nRF Connect for VS Code
    Id: nordic-semiconductor.nrf-connect
    Description: Develop applications based on nRF Connect SDK with ease!
    Version: 2023.10.49
    Publisher: Nordic Semiconductor
    VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=nordic-semiconductor.nrf-connect

    Name: nRF DeviceTree
    Id: nordic-semiconductor.nrf-devicetree
    Description: Full DeviceTree language support for the Zephyr project
    Version: 2023.10.22
    Publisher: Nordic Semiconductor
    VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=nordic-semiconductor.nrf-devicetree

    Name: nRF Kconfig
    Id: nordic-semiconductor.nrf-kconfig
    Description: Kconfig language support for the Zephyr Project
    Version: 2023.10.27
    Publisher: Nordic Semiconductor
    VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=nordic-semiconductor.nrf-kconfig

    Name: nRF Terminal
    Id: nordic-semiconductor.nrf-terminal
    Description: A serial terminal for VS Code
    Version: 2023.10.17
    Publisher: Nordic Semiconductor
    VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=nordic-semiconductor.nrf-terminal

    CMake extensions:

    Name: CMake
    Id: twxs.cmake
    Description: CMake langage support for Visual Studio Code
    Version: 0.0.17
    Publisher: twxs
    VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=twxs.cmake

    Name: CMake Tools
    Id: ms-vscode.cmake-tools
    Description: Extended CMake support in Visual Studio Code
    Version: 1.15.31
    Publisher: Microsoft
    VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools

  • Thanks Simon.  I have looked at that page before, thought I was going crazy trying to find that option! Looks like it is exactly what I want though.  Makes a nice JSON file I can put into the repo for future devs to recreate the build env.  I also have those same extensions, full listing below.

  • Hi

    I just got word from one of the developers that the Save Configuration As Preset action is not available on sysbuild and TFM builds, which is likely the difference between mine and your projects.

    Best regards,

    Simon

  • Thanks Simon.  Not a sysbuild and also not a board with _ns base - thats TFM isnt it?  It is a nRF5340 project and it does use a custom board but it is based on your nrf5340dk_nrf5340_cpuapp with just devicetree changes. 

    HOWEVER, I just loaded an old project (one of your examples) from many months ago that was last built using a different version of the extensions and SDK and I CAN see the Save Configuration option!  But the extension was asking to pristine build as it is stale and after that the option is gone, no other changes.  Is it possible my IDE/projects have some kind of stale setting in it? My setup has been through several SDK and extenstion updates by this point (currently on SDK 2.4.1).

    To confirm I just made a brand new project+build (non _ns and non sysbuild) using one of your examples against nrf5340dk_nrf5340_cpuapp and no Save Configuratiton option, so don't think it is as simple as not working with sysbuild and TFM.

  • Hi Geoff

    That sounds strange indeed. Just to make sure, your projects don't have this config (or any of its dependencies) enabled by chance, do they? CONFIG_BUILD_WITH_TFM, as TFM is indeed non-secure samples, but are not limited to just those.

    It could also be something with your Visual Studio Code or SDK setup. If so I'd recommend trying to uninstall the extensions, VS Code, and remove the SDK from the toolchain manager before reinstalling to see if that helps. Alternatively if you have another computer you can install a fresh SDK and VSCode instance and see if you have the same issue with your project(s) there.

    Best regards,

    Simon

  • No TFM. Indeed very odd - the fact that old sample projects last built on the SDK/Extension available 6 months ago show the "Save Configuration" option when loaded today, but when they are rebuilt on current tools it disappears. FYI these where projects from your excellent BLE fundamentals course which I did at the time.

    I'll try the other options you suggest when able.

Reply
  • No TFM. Indeed very odd - the fact that old sample projects last built on the SDK/Extension available 6 months ago show the "Save Configuration" option when loaded today, but when they are rebuilt on current tools it disappears. FYI these where projects from your excellent BLE fundamentals course which I did at the time.

    I'll try the other options you suggest when able.

Children
Related