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!

  • 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.

  • Thanks, I've forwarded this information to the devs as well and will let you know if they have further suggestions. In the meantime I think you should try reinstalling what I mentioned in my last reply to see if it has something to do with your installation.

    And just for reference. Was this project built on a 6 month old SDK and VSCode environment on the same computer you're using now or a separate computer?

    Best regards,

    Simon

  • All the same computer.  It started on SDK 2.3.0 and later had 2.4.1 installed (both via toolchain manager). VS Code extensions were all set to auto update during that time.

Related