This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF9160-DK - Make Application From Scratch

Hi,

I have nRF9160-DK kit and its environment is set such as nRF Connect SDK and Segger Embedded Studio.

I want to build a simple application from scratch for example toggling LEDs on the board or anything else.

I have tried some sample application supplied with and they are running fine.

Could you provide any tutorial or documentation which shows how to build application from scratch for nRF9160-DK?

Thanks,

Aakash.

  • Hi  and. I think CMakeList.txt file is useful when working with SEGGER Embedded Studio for building purposes. See: cmake.org/.../ and wiki.ros.org/.../CMakeLists.txt. In my cmakelist.txt file, I include one file and specify sources to use when compiling a given target. You will not have to update this file every time you add or edit the code. But, if you want to include external files, this is the space to use.

    Regarding sample.yaml and prj.conf, I have no experience with these files. I am with this board from last one week. As I said before, I tried to make similar example by following given sample application files. However, I tried to run above application without these two files, sample.yaml and prj.conf, and it worked perfectly. Therefore, these two files may not be mandatory.

    Regarding the GPIO ports, see my new code. It references the pins now therefore it will remain same or change according to hardware pinouts.

    #include <zephyr.h>
    #include <device.h>
    #include <gpio.h>
    
    #define LED_PORT0 LED0_GPIO_CONTROLLER
    
    #define LED0    2
    #define LED1    3
    #define LED2    4
    #define LED3    5
    
    /* 1000 msec = 1 sec */
    #define SLEEP_TIME    1000
    
    void main(void)
    {
    	int cnt = 0;
    	struct device *dev0, *dev1, *dev2, *dev3;
    
    	dev0 = device_get_binding(LED_PORT0);
    	dev1 = device_get_binding(LED_PORT0);
    	dev2 = device_get_binding(LED_PORT0);
    	dev3 = device_get_binding(LED_PORT0);
    	/* Set LED pin as output */
    	gpio_pin_configure(dev0, LED0, GPIO_DIR_OUT);
    	gpio_pin_configure(dev1, LED1, GPIO_DIR_OUT);
    	gpio_pin_configure(dev2, LED2, GPIO_DIR_OUT);
    	gpio_pin_configure(dev3, LED3, GPIO_DIR_OUT);
    
    	while (1) {
    		/* Set pin to HIGH/LOW every 1 second */
    		gpio_pin_write(dev0, LED0, cnt % 2);
    		gpio_pin_write(dev1, LED1, cnt % 2);
    		gpio_pin_write(dev2, LED2, cnt % 2);
    		gpio_pin_write(dev3, LED3, cnt % 2);
    		cnt++;
    		k_sleep(SLEEP_TIME);
    	}        
    }

    If you want to change the port, you will have to use this:

    /* change this to use another GPIO port */
    #ifndef LED0_GPIO_CONTROLLER
    #ifdef LED0_GPIO_PORT
    #define LED0_GPIO_CONTROLLER LED0_GPIO_PORT
    #else
    #error LED0_GPIO_PORT or LED0_GPIO_CONTROLLER needs to be set in board.h
    #endif
    #endif
    #define PORT	LED0_GPIO_CONTROLLER

  • I'm quite new with the environment as well, as I understand;

    prj.conf = you setup which drivers you would like to use in your application such as I2C, Spi or sensor drivers that you want to add like lis2dhl. Other than you can create and setup threads. You can see the accepted values from this link.

    sample.yaml is for documentation I believe so.

    Other than these ones you can add overlay files like "nrf9160_pca10090ns.overlay". in this file you can edit dts file of board, that will allow you to assign different pin for peripherals.

    &i2c2 {
    	status = "ok";
    	sda-pin = <21>;
    	scl-pin = <22>;
    };

  • would be so much easier if there was a GUI for choosing the libraries and drivers, as well as config

  • Hi, thanks for the link and explanation. Regarding this .overlay file, do I have to write this manually such as text file or it generates automatically when we build the programme?

Related