Toggle LED in custom application

I'm trying to do something extremely simple but can't get it to work. Through the dev academy, I successfully loaded up and executed exercise 1. However, when I then try to "Create a New Application" (rather than "Add and existing appliction), running the exact same main.c code, I am not able to toggle the LEDs and none of the GPIOs seem to be configured. I'm guessing this has something to do with the generated files, but I don't know where to start looking. Please help!

BTW - I am able to attach with the debugger and see that the initialization seems to be completing without error and function call to the gpio toggle also returns with no error. main.c code for both applications is the following:

const struct device *dev0;
    const int PIN=29;
    bool led_is_on = true;
    int ret;

    dev0 = DEVICE_DT_GET(DT_NODELABEL(gpio0));

    if (dev0==NULL) {
        printk("device not found");
        return;
    }

    if (!device_is_ready(dev0)) {
        printk("GPIO controller not ready");
        return -ENODEV;
    }
    gpio_pin_configure(dev0, PIN, GPIO_OUTPUT);
    while(1) {
        gpio_pin_toggle(dev0, PIN);
        k_msleep(SLEEP_TIME_MS);
    }
Parents
  • Update - I have recreated the application three different ways using different Application templates.

    1. Created with nrf/samples/nrf5340/empty_app_core - LED toggle does not work.
    2. Created with zephry/samples/hello_world - LED does not work.
    3. Created with zephyr/samples/basic/blinky - LED works.

    I should note that it is not just the LED that doesn't toggle, I also have SPI transciever code and I can see that the GPIOs associated with clock, chip select, and data lines also do not work (i.e. they are always held low) in 1 and 2 above, but work in 3 above. 

    So my pins are under control now, which is great. But so that I can understand, what is going on "behind the scenes" that causes the first two applications to fail and the third to work? What options or configurations do I need to enable to make 1 and 2 work?

    Thanks,

    Jamie

Reply
  • Update - I have recreated the application three different ways using different Application templates.

    1. Created with nrf/samples/nrf5340/empty_app_core - LED toggle does not work.
    2. Created with zephry/samples/hello_world - LED does not work.
    3. Created with zephyr/samples/basic/blinky - LED works.

    I should note that it is not just the LED that doesn't toggle, I also have SPI transciever code and I can see that the GPIOs associated with clock, chip select, and data lines also do not work (i.e. they are always held low) in 1 and 2 above, but work in 3 above. 

    So my pins are under control now, which is great. But so that I can understand, what is going on "behind the scenes" that causes the first two applications to fail and the third to work? What options or configurations do I need to enable to make 1 and 2 work?

    Thanks,

    Jamie

Children
No Data
Related