soonisys
www.soonisys.comdocs.soonisys.com
nRF9160 M.2 Module
nRF9160 M.2 Module
  • PRODUCTS DETAIL
    • nRF9160 M.2 Module
    • nRF9160 M.2 Development Kit
  • DEVELOPMENT
    • Getting Started-SDK v2.3.0
    • Getting Started-Legacy
      • Installation
      • Hello World - Sample
      • Create Project
      • Cat-M1 + UDP
      • Serial LTE Modem
    • Resources
    • Sim Cards
Powered by GitBook
On this page
  • 1. Create Folder and Files
  • 2. Source Codes
  • 2.1 src/main.c
  • 2.2 CMakeLists.txt
  • 2.3 prj.conf
  • 3. Open as Segger Project
  • 3.1 Open Segger IDE
  • 3.2 File->Open nRF Connect SDK Project...
  • 3.3 Select Project and Board
  • 3.4 Build and Run
  1. DEVELOPMENT
  2. Getting Started-Legacy

Create Project

Create New Project - Simple LED Blink and Print Serial Message

PreviousHello World - SampleNextCat-M1 + UDP

Last updated 3 years ago

Let's create a new custom project.

1. Create Folder and Files

Let's create project named "mySooniLED" at C:\ncs\workspace\mySooniLED

You need 3 files for your first project.

  • mySooniLED\ (project folder)

    1. src\main.c

    2. CMakeLists.txt

    3. prj.conf

So, It should look like this.

2. Source Codes

This is a simple led blink example codes.

2.1 src/main.c

We get gpio device and control directly instead of alias name such as led-0

src/main.c
#include <zephyr.h>
#include <zephyr/types.h>
#include <sys/printk.h>

#include <device.h>
#include <devicetree.h>
#include <drivers/gpio.h>

#include <stdint.h>
#include <stdbool.h>

#define LED_HEAD_PIN    7
#define LED_RESET_PIN   6
#define LED_BOOT_PIN    5

void main(void)
{    
    struct device *dev;
    int ret;
    int count = 0;

    printk("mySooniLED start\n");
    
    // get gpio0 device
    dev = device_get_binding("GPIO_0");
    if(dev == NULL)
    {
        printk("device_get_binding:error, GPIO_0\n");
        return;
    }    
    printk("device_get_binding:ok, GPIO_0\n");
    
    // config led pin
    ret = gpio_pin_configure(dev, LED_HEAD_PIN, GPIO_OUTPUT_HIGH);
    if(ret != 0)
    {
        printk("gpio_pin_configure:error, %d\n", ret);
        return;
    }

    ret = gpio_pin_configure(dev, LED_RESET_PIN, GPIO_OUTPUT_HIGH);
    if(ret != 0)
    {
        printk("gpio_pin_configure:error, %d\n", ret);
        return;
    }
    ret = gpio_pin_configure(dev, LED_BOOT_PIN, GPIO_OUTPUT_HIGH);
    if(ret != 0)
    {
        printk("gpio_pin_configure:error, %d\n", ret);
        return;
    }

    printk("gpio_pin_configure:ok\n");

    // blink and printk
    while(true)
    {                
        count++;
        printk("count=%d, time=%u\n", count, k_uptime_get_32());

        gpio_pin_set_raw(dev, LED_HEAD_PIN, 0); // turn on
        gpio_pin_set_raw(dev, LED_RESET_PIN, 1); // turn off
        gpio_pin_set_raw(dev, LED_BOOT_PIN, 1); // turn off
        k_msleep(200);
        
        gpio_pin_set_raw(dev, LED_HEAD_PIN, 1); // turn off
        gpio_pin_set_raw(dev, LED_RESET_PIN, 0); // turn on
        gpio_pin_set_raw(dev, LED_BOOT_PIN, 1); // turn off
        k_msleep(200);

        gpio_pin_set_raw(dev, LED_HEAD_PIN, 1); // turn off
        gpio_pin_set_raw(dev, LED_RESET_PIN, 1); // turn off
        gpio_pin_set_raw(dev, LED_BOOT_PIN, 0); // turn on
        k_msleep(200);
    }
}

2.2 CMakeLists.txt

CMakeLists.txt
#
# Copyright (c) 2020 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.13.1)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(mySooniLED)

# SOURCE FILES
target_sources(app PRIVATE src/main.c)

2.3 prj.conf

prj.conf
#
# Copyright (c) 2020 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# General config
CONFIG_NEWLIB_LIBC=y
CONFIG_HW_STACK_PROTECTION=y
CONFIG_SERIAL=y

# GPIO
CONFIG_GPIO=y

# Heap and stacks
CONFIG_HEAP_MEM_POOL_SIZE=2048
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

3. Open as Segger Project

3.3 Select Project and Board

  1. Select "C:\ncs\workspace\mySooniLED" project folder by use "..." button.

  2. Check '3rd party kits'.

  3. Select 'soonisys_sldev_nrf9160ns'.

  4. OK.

3.1

3.2

3.4

Open Segger IDE
File->Open nRF Connect SDK Project...
Build and Run
project folder
source folder