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:
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.
What if I have my own custom nrf52 board and not a development board. Would I need to define my own device tree?
Although I would HIGHLY recommend learning and embracing the use of Zephyr and its devicetrees, You can look into these alternatives.