This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Adding existing code to current VS code application

This should be so easy, but it isn't.  I started with the Dev Academy Lesson 6 I2C example.  I wired up a little board with an I2C eeprom, created an overlay file to map the I2C pins to other port pins and everything worked great.  

Now I want to add an existing c source file to the application.

VS Code Version: 1.65.2 (user setup)
nRF Connect SDK Version:  1.9.1

1. I copy the file into the windows explorer folder.

2.  Close and re-open VS Code to ensure it reads in everything.

3.  Select Explorer and the new file (parse.c) is there

4. Select NRF Connect, but the file isn't there.  

 Myself and another developer have searched through the menu system, tried context menus, searched devzone and searched the web for some example that works but with no luck.   This should be very simple.

Parents
  • I also wonder how this is supposed to work. I added the file to CMakeLists.txt and it works. Not sure if there is some integrated way to do it.

  • UPDATE: I noticed after submitting this answer, that the person replying was different from the person behind the initial post. But I think I (and Wayne) have answered the questions from the initial post as well


    flaik-wayne said:
    I also wonder how this is supposed to work. I added the file to CMakeLists.txt and it works. Not sure if there is some integrated way to do it.

    Yes, you need to add the .c files to CMakeLists.txt. I'm not aware of any ways to do it through the GUI.

    A trick is to add the following to the CMakeLists.txt: https://github.com/nrfconnect/sdk-nrf/blob/v2.0.0/samples/bluetooth/throughput/CMakeLists.txt#L14-L18 

    Then all the .c files in src will automatically get included in the build.

    flaik-wayne said:
    I just watched some of the walkthrough videos - in video 3 https://youtu.be/3yi6kuxgdPg he mentions doing a pristine build if you have edited CMakeLists.txt or the application configuration files.

    Actually, it seems like it is enough to run a normal build after editing CMakeLists. I tried modifying the CMakeList.txt and built the app and got this result:

    Building hello_world
    west build --build-dir c:\v2.0.0\zephyr\samples\hello_world\build_53 c:\v2.0.0\zephyr\samples\hello_world
    
    [0/1] Re-running CMake...
    .
    .
    .
    .
    .

    So it seems like the cmake changes are detected, and it will re-run cmake. I think the same applies if you modify Kconfigs (e.g. prj.conf) or the Device tree (.overlay files), the changes will be detected and cmake wil re-run. 

    pristine build directory is essentially a new build directory. All byproducts from previous builds have been removed. As mentioned here.

    I don't know exactly how west works in details and in what circumstances it wil re-run cmake or not, but I can ask internally if you would like a more certain answer.


    Learn more about west build/pristine builds here: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/zephyr/guides/west/build-flash-debug.html#pristine-builds 

    Take a look at the page below to learn about the build and configuration phase:

    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/zephyr/guides/build/index.html

    In short the configuration phase wil run cmake and go through the dts/dts/.overlay files, Kconfig files and generate the build system. The build phase will run ninja (similar to make) and generate the .hex/.elf files. If you only modify .h/.c files, it is only the build phase that will run.

    Best regards,

    Simon

Reply
  • UPDATE: I noticed after submitting this answer, that the person replying was different from the person behind the initial post. But I think I (and Wayne) have answered the questions from the initial post as well


    flaik-wayne said:
    I also wonder how this is supposed to work. I added the file to CMakeLists.txt and it works. Not sure if there is some integrated way to do it.

    Yes, you need to add the .c files to CMakeLists.txt. I'm not aware of any ways to do it through the GUI.

    A trick is to add the following to the CMakeLists.txt: https://github.com/nrfconnect/sdk-nrf/blob/v2.0.0/samples/bluetooth/throughput/CMakeLists.txt#L14-L18 

    Then all the .c files in src will automatically get included in the build.

    flaik-wayne said:
    I just watched some of the walkthrough videos - in video 3 https://youtu.be/3yi6kuxgdPg he mentions doing a pristine build if you have edited CMakeLists.txt or the application configuration files.

    Actually, it seems like it is enough to run a normal build after editing CMakeLists. I tried modifying the CMakeList.txt and built the app and got this result:

    Building hello_world
    west build --build-dir c:\v2.0.0\zephyr\samples\hello_world\build_53 c:\v2.0.0\zephyr\samples\hello_world
    
    [0/1] Re-running CMake...
    .
    .
    .
    .
    .

    So it seems like the cmake changes are detected, and it will re-run cmake. I think the same applies if you modify Kconfigs (e.g. prj.conf) or the Device tree (.overlay files), the changes will be detected and cmake wil re-run. 

    pristine build directory is essentially a new build directory. All byproducts from previous builds have been removed. As mentioned here.

    I don't know exactly how west works in details and in what circumstances it wil re-run cmake or not, but I can ask internally if you would like a more certain answer.


    Learn more about west build/pristine builds here: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/zephyr/guides/west/build-flash-debug.html#pristine-builds 

    Take a look at the page below to learn about the build and configuration phase:

    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/zephyr/guides/build/index.html

    In short the configuration phase wil run cmake and go through the dts/dts/.overlay files, Kconfig files and generate the build system. The build phase will run ninja (similar to make) and generate the .hex/.elf files. If you only modify .h/.c files, it is only the build phase that will run.

    Best regards,

    Simon

Children
No Data
Related