2

I have recently picked up NRF52DK development board with NRF52832 https://www.nordicsemi.com/Products/Development-hardware/nrf52-dk

I have setup my development environment using VSCode NRF Connect extension.

I have been reading and learning a little bit about the NRF52 and realized that all the example projects use device trees.

For example, the code to toggle the GPIO:

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

#define LED0_NODE DT_ALIAS(led0) // LED0_NODE = led0 defined in the .dts file

int main(void)
{
    static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

    if (!device_is_ready(led.port))
    {
        return;
    }
    int ret;

    ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
    if (ret < 0)
    {
        return;
    }

    printf("Hello World! %s\n", CONFIG_BOARD);
    k_sleep(K_MSEC(1000));
    printf("Bye World! %s\n", CONFIG_BOARD);

    while (1)
    {
        ret = gpio_pin_toggle_dt(&led);
        if (ret < 0)
        {
            return;
        }
        k_msleep(1000);
    }

    return 0;
}

I dont like device trees at all and I have a couple of questions:

  1. wonder if there is a way to write code without using device trees at all? Could you please provide GPIO initialization and toggling example code without using device trees as I could not find a single example without device trees at all.

  2. device tree relies on having the dts as described here: enter image description here

What if I have my own custom nrf52 board and not a development board. Would I need to define my own device tree?

2 Answers 2

0

Device trees are used by the Zephyr framework. Other frameworks don't use them.

Alternatives you could look into are:

Sign up to request clarification or add additional context in comments.

Comments

0

Although I would HIGHLY recommend learning and embracing the use of Zephyr and its devicetrees, You can look into these alternatives.

  • You can use the framework Nordic had before adapting Zephyr and nRF Connect SDK, called the nRF5 SDK, combined with their nrfx drivers. This is, as far as I know, completely baremetal.
  • You can work around the devicetrees while still making your application on Zephyr by using the nrfx drivers, because they are available in the nRF Connect SDK.
  • You can write your own drivers or use 3rd party drivers for stuff.

1 Comment

If you have a custom nrf52 board and not a development board, you can either make your own devicetree file (very difficult), or you can use the devicetree overlay files to overwrite and extend the default devicetree. I think Nordic has some tutorials on how to write overlays.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.