Using nRF connect for vs code on bare metal

Hi Nordic!

I'm a fan of your products and usually work in Segger Embedded Studio (used it with nRF Connect SDK v1.9.1).

In that application you can create a "blank" project/application. It creates some folders, like the CMSIS_5 and nRF. I can include my own headers/sources (need to be added to the preprocessor) and everything works fine!

Upgrading to nRF Connect SDK v2.1.0 I don't get the option to start it with Segger anymore, only Open VS Code is possible. Don't get me wrong here.. I much rather use VS Code if I can use it the way I want.

But here is where the problems start.. After installing it all I do the following (in VS Code).

1. Create a new application, freestanding, 2.1.0 as SDK and toolchain.
2. Application template is when I get confused... I would like to find a "blank"-template or something similar! One that is not dependent on Zephyr!
3. Since I can't find one I chose zephyr/samples/hello_world

4. Let's say I want to set the baudrate of UARTE to 115200 bps, I would just include "nrf52.h" and write NRF_UARTE0->BAUDRATE = 0x01D60000;
5. Setting a build target (nRF52 DK NRF52832) and everything builds fine and I get an .elf file.

6. But what if I want to be a little more modular..  I create a "inc" folder with some headers in it, add some .c files to the src folder.
7. In the main.c file I need to include them with "../inc/myheader.h" and VS Code finds the files and functions and reports no errors.
8. But when I build I get the errors that the functions (located in my c and h files) are "undefined reference to 'my_foo'"
9. I assume I need to include the folders somehow? But here I'm lost.. I can click on the Kconfig and I get a trillion of options.

What should I do to make this work?

Best regards

  • Hi

    I believe hello world is about the most minimal template you'll get in NCS. Of course you can program your nRF52840 without Zephyr using the MDK and nrfx drivers, but once you're not using Zephyr you're not really using NCS at all.

    To help the build system find your custom headers, you should simply add your source files to CMakeLists.txt with the target_sources macro.

    Best regards,

    Einar

Related