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

nRF52840 custom board zephyr blink sample

Hi. I need some help to change blink led's on zephyr.
I'm using
NRF Connect SDK v1.5.0
SEGGER Embedded Studio for ARM
Release 5.34a  Build 2021011401.44914
Nordic Edition
macOS x64 High Sierra v10.13.6


I build my own custom board with a nRF52840 module. These boards is working correctly as I have already tested it with before starting using Zephyr.
I have configured the custom board files on /opt/nordic/ncs/v1.5.0/zephyr/boards/arm, blink example is compiling correctly and I can debug and download.
I can change sleep time which also works correctly.

In .dts file I have configured pins as follow

...
leds {
		compatible = "gpio-leds";
		led0: led_0 {
			gpios = <&gpio0 7 GPIO_ACTIVE_LOW>;
			label = "Green LED 0";
		};
		led1: led_1 {
			gpios = <&gpio0 12 GPIO_ACTIVE_LOW>;
			label = "Green LED 1";
		};

	};
	
...
/* These aliases are provided for compatibility with samples */
	aliases {
		led0 = &led0;
		led1 = &led1;
		pwm-led0 = &pwm_led0;
		sw0 = &button0;
		sw1 = &button1;
		sw2 = &button2;
	};


I have changed blink as follow

/*
 * Copyright (c) 2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

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

//#include "CustomBoard.h"

//#define LF_SRC_RC CLOCK_LFCLKSRC_SRC_RC

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS   100

/* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led0)

#if DT_NODE_HAS_STATUS(LED0_NODE, okay)
#define LED0	DT_GPIO_LABEL(LED0_NODE, gpios)
#define PIN_0	DT_GPIO_PIN(LED0_NODE, gpios)
#define FLAGS_0	DT_GPIO_FLAGS(LED0_NODE, gpios)
#else
/* A build error here means your board isn't set up to blink an LED. */
#error "Unsupported board: led0 devicetree alias is not defined"
#define LED0	""
#define PIN	0
#define FLAGS_0	0
#endif

/* The devicetree node identifier for the "led1" alias. */
#define LED1_NODE DT_ALIAS(led1)

#if DT_NODE_HAS_STATUS(LED1_NODE, okay)
#define LED1	DT_GPIO_LABEL(LED1_NODE, gpios)
#define PIN_1	DT_GPIO_PIN(LED1_NODE, gpios)
#define FLAGS_1	DT_GPIO_FLAGS(LED1_NODE, gpios)
#else
/* A build error here means your board isn't set up to blink an LED. */
#error "Unsupported board: led1 devicetree alias is not defined"
#define LED1	""
#define PIN	0
#define FLAGS_1	0
#endif

void main(void)
{
	const struct device *dev_led_0, *dev_led_1;
	//bool led_is_on = true;
	int ret;

        dev_led_0 = device_get_binding(LED0);
        dev_led_1 = device_get_binding(LED1);

	if (dev_led_1 == NULL && dev_led_1 == NULL) { return; }
	
        ret = gpio_pin_configure(dev_led_0, PIN_0, GPIO_OUTPUT_ACTIVE | FLAGS_0);
	if (ret < 0) { return; }

	ret = gpio_pin_configure(dev_led_1, PIN_1, GPIO_OUTPUT_ACTIVE | FLAGS_1);
	if (ret < 0) { return; }


	while (1) {
		//gpio_pin_set(dev_1, PIN_1, (int)led_is_on);
                //gpio_pin_set(dev_0, PIN_0, !((int)led_is_on));
                gpio_pin_toggle(dev_led_0, PIN_1);
                gpio_pin_toggle(dev_led_1, PIN_0);
		//led_is_on = !led_is_on;
		k_msleep(SLEEP_TIME_MS);
	}
}


But just the first led is blinking.
How can I make both led to blink?

Thanks

Parents Reply Children
No Data
Related