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

Build application from main.c

Hi everyone!

I'm new using Nordic Semiconductor products, I have a Nordic Thingy 91  running Asset Tracker application by default.

I want to test only specific things first, this case I want to run this main.c file in order to toggle the NMOS pins.  

#include <zephyr.h>
#include <misc/printk.h>
#include <gpio.h>

static struct device *gpio_dev;
static bool nmos_state = false;

void toggle_nmos() {
    nmos_state = !nmos_state;

    if (nmos_state) {
        // turn on 
        printk("Setting GPIO pin to 1, %d\n", gpio_pin_write(gpio_dev, 13, 1));
    }
    else {
        // turn off
        printk("Setting GPIO pin to 0, %d\n", gpio_pin_write(gpio_dev, 13, 0));
    }
}

void main(void)
{
    gpio_dev = device_get_binding("GPIO_0");
    gpio_pin_configure(gpio_dev, 16, GPIO_DIR_OUT);

    while (true) {
        toggle_nmos();
        k_sleep(2000);
    }
}

What other files or libraries I have to write in order to correctly build this application? The idea is to generate the app_signed.hex file, flash and test.

Thanks in advance,

Alejandro Ch.

Parents
  • Hi!

    Mainly you need to add a CMakeLists.txt file that looks like this:

    cmake_minimum_required(VERSION 3.13.1)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(case_260461_project_name)
    
    target_sources(app PRIVATE src/main.c)

    and a prj.conf file that looks like this:

    CONFIG_GPIO=y

    I can test and run it all for you, but which NCS tag would you like to work on? 


    Best regards,

    Heidi

Reply
  • Hi!

    Mainly you need to add a CMakeLists.txt file that looks like this:

    cmake_minimum_required(VERSION 3.13.1)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(case_260461_project_name)
    
    target_sources(app PRIVATE src/main.c)

    and a prj.conf file that looks like this:

    CONFIG_GPIO=y

    I can test and run it all for you, but which NCS tag would you like to work on? 


    Best regards,

    Heidi

Children
Related