<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Problem configuring devicetree nRF5340 new board</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/118559/problem-configuring-devicetree-nrf5340-new-board</link><description>Hello Everyone, 
 
 I am new to nordic devices, but i have been for the past 2 weeks trying to build something. First I have created a new board &amp;quot;Holyiot_21069&amp;quot; with Visual Studio code with &amp;quot;Create a new board&amp;quot;, and checked all configurations to nrf5340</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 04 Feb 2025 09:50:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/118559/problem-configuring-devicetree-nrf5340-new-board" /><item><title>RE: Problem configuring devicetree nRF5340 new board</title><link>https://devzone.nordicsemi.com/thread/521256?ContentTypeID=1</link><pubDate>Tue, 04 Feb 2025 09:50:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b0792973-da40-48cf-85cd-62847a51a10a</guid><dc:creator>Sigurd</dc:creator><description>[quote user="franciscopinho"]&lt;p&gt;Thanks, a lot Sigurd. That worked for me.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;Great!&lt;/p&gt;
[quote user="franciscopinho"]By the way, i managed to build the hci_ipc project on cpunet under my new board. For sending and receiving data, the functions presented in cpuapp will be running on the cpuapp core or in the cpu net. As you can see in my main cpuapp I have an interrupt for reading a sensor, and i dont want the transmission to mess up with the sampling frequency of the readings. Can you advise please.&amp;nbsp;[/quote]
&lt;p&gt;Please open a new case for any new questions, as keeping cases separate makes it easier to maintain an overview:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/support/add"&gt;https://devzone.nordicsemi.com/support/add&lt;/a&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem configuring devicetree nRF5340 new board</title><link>https://devzone.nordicsemi.com/thread/521222?ContentTypeID=1</link><pubDate>Tue, 04 Feb 2025 07:49:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e31ca2cb-fac5-4e88-ad4f-f583f406fa59</guid><dc:creator>franciscopinho</dc:creator><description>&lt;p&gt;Thanks, a lot Sigurd. That worked for me.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;By the way, i managed to build the hci_ipc project on cpunet under my new board. For sending and receiving data, the functions presented in cpuapp will be running on the cpuapp core or in the cpu net. As you can see in my main cpuapp I have an interrupt for reading a sensor, and i dont want the transmission to mess up with the sampling frequency of the readings. Can you advise please.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem configuring devicetree nRF5340 new board</title><link>https://devzone.nordicsemi.com/thread/521178?ContentTypeID=1</link><pubDate>Mon, 03 Feb 2025 16:58:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2c657ac9-6fe0-452a-8743-e093cb481b0d</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
[quote user="franciscopinho"]in function &amp;#39;configure_gpios&amp;#39;: C:\ncs\Apps\test5\src\main.c:124: undifined reference to &amp;#39;__device_dts_ord_12&amp;#39;[/quote]
&lt;p&gt;Looking at&amp;nbsp;zephyr\app\build\app\zephyr\include\generated\zephyr\devicetree_generated.h , we see that we have this at 12:&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp;* &amp;nbsp; 12 &amp;nbsp;/buttons/drdy_input&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;we also see in the error code it&amp;#39;s releated to&amp;nbsp;gpio_pin_configure() usage.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Try this main.c&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;// src/main.c
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;zephyr/drivers/spi.h&amp;gt;
#include &amp;lt;zephyr/logging/log.h&amp;gt;
#include &amp;lt;zephyr/sys/printk.h&amp;gt;
#include &amp;lt;zephyr/bluetooth/bluetooth.h&amp;gt;
#include &amp;lt;zephyr/bluetooth/gatt.h&amp;gt;
#include &amp;lt;zephyr/sys/byteorder.h&amp;gt;

LOG_MODULE_REGISTER(test5);
// Define the device labels for SPI and GPIOs
#define SPI1_NODE DT_NODELABEL(spi1)
/* The devicetree node identifier for the &amp;quot;led0&amp;quot; alias. */
#define LED0_NODE DT_ALIAS(gpioled)
#define START_NODE DT_ALIAS(gpiostart)
#define RESET_NODE DT_ALIAS(gpioreset)
#define DRDY_NODE DT_ALIAS(gpiodrdy)
#define GPIO_DRDY_PIN DT_PHA(DRDY_NODE, gpios, pin)



//#define GPIO_DRDY_PIN 3

static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
static const struct gpio_dt_spec start = GPIO_DT_SPEC_GET(START_NODE, gpios);
static const struct gpio_dt_spec reset = GPIO_DT_SPEC_GET(RESET_NODE, gpios);


// SPI configuration
#define SPI_OPERATION (SPI_OP_MODE_MASTER | SPI_TRANSFER_MSB | SPI_WORD_SET(8))
 const struct device *spi_dev;
 const struct device *gpio_dev;
 /* SPI configuration */
static const struct spi_config spi_cfg = {
    .frequency = 3000000, /* 1 MHz */
    .operation = SPI_OPERATION,
    .slave = 0,
};
#define BNO086_ROTATION_VECTOR_REPORT_ID 0x05

/* Callback structure */
static struct gpio_callback drdy_cb;

// Task thread stack sizes
#define STACK_SIZE 1024
#define BUFFER_SIZE 224      // Sending buffer size: 224 bytes
#define SAMPLE_SIZE 16       // Fused data sample size: 16 bytes (4 floats)
// Double buffers
static uint8_t buffer1[BUFFER_SIZE];
static uint8_t buffer2[BUFFER_SIZE];
static uint8_t *active_buffer = buffer1;
static uint8_t *processing_buffer = buffer2;
int contador=0;
// Shared variables
static struct k_thread producer_thread;
static struct k_thread consumer_thread;
static K_THREAD_STACK_DEFINE(producer_stack, 2048);
static K_THREAD_STACK_DEFINE(consumer_stack, 2048);
// BLE connection and characteristic handles
static struct bt_conn *current_conn;
static uint16_t gatt_handle = 0x0012; // &amp;lt;-- Set correct handle for BLE characteristic


// Forward declarations
/* Callback function prototype */
/* Function Prototypes */
static void drdy_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins);
static void producer_task(void *arg1, void *arg2, void *arg3);
static void consumer_task(void *arg1, void *arg2, void *arg3);
void configure_gpios(void);
void configure_bno086(void);
void start_ble(void);
void send_data(uint8_t *data);



static void drdy_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins) {
    k_wakeup(&amp;amp;producer_thread);
}


void configure_gpios(void) {

    
   int ret;
   spi_dev = DEVICE_DT_GET(SPI1_NODE);
   if (!device_is_ready(spi_dev)) {
    printk(&amp;quot;Error: SPI1 device is not ready\n&amp;quot;);
    return;
    }

	ret = gpio_pin_configure_dt(&amp;amp;led, GPIO_OUTPUT_ACTIVE);
	if (ret &amp;lt; 0) {
		return;
	}

      // Configure GPIOs
    ret = gpio_pin_configure_dt(&amp;amp;start, GPIO_OUTPUT_ACTIVE);
    if (ret &amp;lt; 0) {
        printk(&amp;quot;Failed to configure LED GPIO\n&amp;quot;);
        return;
    }

    ret = gpio_pin_configure_dt(&amp;amp;reset, GPIO_OUTPUT_ACTIVE);
    if (ret &amp;lt; 0) {
        printk(&amp;quot;Failed to configure START GPIO\n&amp;quot;);
        return;
    }

    gpio_dev = DEVICE_DT_GET(DT_PHANDLE(DT_ALIAS(gpiodrdy), gpios));
    if (gpio_dev == NULL) {
        printk(&amp;quot;Failed to get SPI device binding\n&amp;quot;);
        return;
    }
    ret = gpio_pin_configure(gpio_dev, GPIO_DRDY_PIN, GPIO_INPUT | GPIO_PULL_UP);
    if (ret != 0) {
        printk(&amp;quot;Error: Failed to configure DRDY pin\n&amp;quot;);
        return;
    }
    // Set up GPIO callback for DRDY pin
   gpio_init_callback(&amp;amp;drdy_cb, drdy_callback, BIT(GPIO_DRDY_PIN));
    gpio_add_callback(gpio_dev, &amp;amp;drdy_cb);
    gpio_pin_interrupt_configure(gpio_dev, GPIO_DRDY_PIN, GPIO_INT_EDGE_TO_INACTIVE);
    gpio_pin_set_dt(&amp;amp;start, 0);
    
}

void configure_bno086(void){
     uint8_t set_feature_cmd[] = {
        0xFD, // Set Feature Command
        BNO086_ROTATION_VECTOR_REPORT_ID, // Rotation Vector Report ID
        0x00, // Reserved
        0x90, 0x01, 0x00, 0x00, // Sample Rate = 400 Hz (in microseconds)
    };

    struct spi_buf tx_buf = { .buf = set_feature_cmd, .len = sizeof(set_feature_cmd) };
    struct spi_buf_set tx = { .buffers = &amp;amp;tx_buf, .count = 1 };

    spi_write(spi_dev, &amp;amp;spi_cfg, &amp;amp;tx);
    LOG_INF(&amp;quot;BNO086 configured for 400 Hz Rotation Vector&amp;quot;);
}

/* BLE Connection Callback */
static void connected(struct bt_conn *conn, uint8_t err) {
    if (err) {
        LOG_ERR(&amp;quot;Failed to connect (err: %d)&amp;quot;, err);
        return;
    }
    LOG_INF(&amp;quot;Connected&amp;quot;);
    current_conn = conn;
}

/* BLE Disconnection Callback */
static void disconnected(struct bt_conn *conn, uint8_t reason) {
    LOG_INF(&amp;quot;Disconnected (reason: %d)&amp;quot;, reason);
    current_conn = NULL;
}

/* Send Data via BLE */
void send_data(uint8_t *data) {
    if (!current_conn) {
        LOG_WRN(&amp;quot;Not connected&amp;quot;);
        return;
    }
    int err = bt_gatt_write_without_response(current_conn, gatt_handle, data, BUFFER_SIZE, false);
    if (err) {
        LOG_ERR(&amp;quot;Failed to send data (err: %d)&amp;quot;, err);
    } else {
        LOG_INF(&amp;quot;Data sent&amp;quot;);
    }
}



/* BLE Initialization */
void start_ble(void) {
    int err = bt_enable(NULL);
    if (err) {
        LOG_ERR(&amp;quot;Bluetooth init failed (err %d)&amp;quot;, err);
        return;
    }
    LOG_INF(&amp;quot;Bluetooth initialized&amp;quot;);

    static struct bt_conn_cb conn_callbacks = {
        .connected = connected,
        .disconnected = disconnected,
    };
    bt_conn_cb_register(&amp;amp;conn_callbacks);

    struct bt_le_adv_param adv_params = BT_LE_ADV_PARAM_INIT(
        BT_LE_ADV_OPT_CONNECTABLE,
        BT_GAP_ADV_FAST_INT_MIN_2,
        BT_GAP_ADV_FAST_INT_MAX_2,
        NULL
    );

    err = bt_le_adv_start(&amp;amp;adv_params, NULL, 0, NULL, 0);
    if (err) {
        LOG_ERR(&amp;quot;Advertising failed (err: %d)&amp;quot;, err);
    } else {
        LOG_INF(&amp;quot;Advertising started&amp;quot;);
    }
}

// Producer task: Reads data from bno086
/* Producer Thread */
static void producer_task(void *arg1, void *arg2, void *arg3) {
    uint8_t read_data[16];

    while (1) {
        k_sleep(K_FOREVER);

        /* Read Rotation Vector Data */
        struct spi_buf tx_buf = { .buf = NULL, .len = 0 };
        struct spi_buf rx_buf = { .buf = read_data, .len = sizeof(read_data) };
        struct spi_buf_set tx = { .buffers = &amp;amp;tx_buf, .count = 1 };
        struct spi_buf_set rx = { .buffers = &amp;amp;rx_buf, .count = 1 };

        spi_transceive(spi_dev, &amp;amp;spi_cfg, &amp;amp;tx, &amp;amp;rx);

        /* Copy data into active buffer */
        memcpy(active_buffer, read_data, sizeof(read_data));
        contador+=16;
        if (contador &amp;gt;= BUFFER_SIZE) {
        /* Swap buffers if full */
        uint8_t *temp = active_buffer;
        active_buffer = processing_buffer;
        processing_buffer = temp;
        contador=0;
        k_wakeup(&amp;amp;consumer_thread);
        }
    }
}

// BLE Send task: Sends data to the server via notifications
/* Consumer Thread */
static void consumer_task(void *arg1, void *arg2, void *arg3) {
    while (1) {
        k_sleep(K_FOREVER);

        /* Send data via BLE */
        send_data(processing_buffer);
        LOG_INF(&amp;quot;Data sent.&amp;quot;);
    }
}


int main(void)
{
    // Initialize Bluetooth
    configure_gpios();
    configure_bno086();

    // Initialize BLE
    start_ble();
   
    
    // Create threads
    k_thread_create(&amp;amp;producer_thread, producer_stack, STACK_SIZE,
                    producer_task, NULL, NULL, NULL, 5, 0, K_NO_WAIT);
    k_thread_create(&amp;amp;consumer_thread, consumer_stack, STACK_SIZE,
                    consumer_task, NULL, NULL, NULL, 5, 0, K_NO_WAIT);
 return 0;
}
&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem configuring devicetree nRF5340 new board</title><link>https://devzone.nordicsemi.com/thread/521156?ContentTypeID=1</link><pubDate>Mon, 03 Feb 2025 14:40:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32394b59-db5f-4e49-8675-e7ea7dad794c</guid><dc:creator>franciscopinho</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/holyiot_5F00_21069.zip"&gt;devzone.nordicsemi.com/.../holyiot_5F00_21069.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem configuring devicetree nRF5340 new board</title><link>https://devzone.nordicsemi.com/thread/521154?ContentTypeID=1</link><pubDate>Mon, 03 Feb 2025 14:34:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:509c2846-ad40-4763-bc86-4fb2e1d8c5f2</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Could you zip the folder where these files are in ? and then upload the zip file?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem configuring devicetree nRF5340 new board</title><link>https://devzone.nordicsemi.com/thread/521147?ContentTypeID=1</link><pubDate>Mon, 03 Feb 2025 14:23:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86df01ae-9c6c-40c4-8def-56ad8d91dac9</guid><dc:creator>franciscopinho</dc:creator><description>&lt;p&gt;When building the project I got an error saying that:&lt;/p&gt;
&lt;p&gt;in function &amp;#39;configure_gpios&amp;#39;: C:\ncs\Apps\test5\src\main.c:124: undifined reference to &amp;#39;__device_dts_ord_12&amp;#39;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem configuring devicetree nRF5340 new board</title><link>https://devzone.nordicsemi.com/thread/521144?ContentTypeID=1</link><pubDate>Mon, 03 Feb 2025 14:15:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e73e727-d82e-41b5-b4f5-7bfc8dc05106</guid><dc:creator>franciscopinho</dc:creator><description>&lt;p&gt;Today I have already made some modifications. I based my board files into nrf5340dk cpuapp.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;//holyiot_21069_common.dtsi

*
 * Copyright (c) 2020 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

 / {
	leds {
		compatible = &amp;quot;gpio-leds&amp;quot;;
        gpio_led: gpio_led {
            gpios = &amp;lt;&amp;amp;gpio0 20 GPIO_ACTIVE_HIGH&amp;gt;;
            label = &amp;quot;LED 0&amp;quot;;
//            zephyr,code=&amp;lt;OUTPUT_LED_0&amp;gt;;
        };
    
        start_signal: start_signal {
            gpios = &amp;lt;&amp;amp;gpio0 22 GPIO_ACTIVE_HIGH&amp;gt;;
            label = &amp;quot;Start Button&amp;quot;;
//            zephyr,code=&amp;lt;OUTPUT_LED_1&amp;gt;;
        };
    
        reset_signal: reset_signal {
            gpios = &amp;lt;&amp;amp;gpio0 29 GPIO_ACTIVE_HIGH&amp;gt;;
            label = &amp;quot;Reset Button&amp;quot;;
 //           zephyr,code=&amp;lt;OUTPUT_LED_2&amp;gt;;
           
        };
    
        };
    

    buttons {
        compatible = &amp;quot;gpio-keys&amp;quot;;
        drdy_input: drdy_input {
            gpios = &amp;lt;&amp;amp;gpio0 3 GPIO_ACTIVE_HIGH&amp;gt;;
            label = &amp;quot;DRDY Input&amp;quot;;
        };
    };

	/* These aliases are provided for compatibility with samples */
	aliases {
		gpioled = &amp;amp;gpio_led;
		gpiostart = &amp;amp;start_signal;
		gpioreset = &amp;amp;reset_signal;
		gpiodrdy = &amp;amp;drdy_input;
	};

};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;//holyiot_21069_cpuapp_common.dtsi

/*
 * Copyright (c) 2019-2020 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */
 #include &amp;quot;holyiot_21069_common.dtsi&amp;quot;
 #include &amp;quot;holyiot_21069-pinctrl.dtsi&amp;quot;
 #include &amp;lt;zephyr/dt-bindings/input/input-event-codes.h&amp;gt;
 
 / {
 
     chosen {
         zephyr,console = &amp;amp;uart0;
         zephyr,shell-uart = &amp;amp;uart0;
         zephyr,uart-mcumgr = &amp;amp;uart0;
         zephyr,bt-mon-uart = &amp;amp;uart0;
         zephyr,bt-c2h-uart = &amp;amp;uart0;
         zephyr,bt-hci = &amp;amp;bt_hci_ipc0;
         nordic,802154-spinel-ipc = &amp;amp;ipc0;
         zephyr,ieee802154 = &amp;amp;ieee802154;
     };
 
     pwmleds {
         compatible = &amp;quot;pwm-leds&amp;quot;;
         pwm_led0: pwm_led_0 {
             pwms = &amp;lt;&amp;amp;pwm0 0 PWM_MSEC(20) PWM_POLARITY_INVERTED&amp;gt;;
         };
     };
 
 
 //	gpio_fwd: nrf-gpio-forwarder {
 //		compatible = &amp;quot;nordic,nrf-gpio-forwarder&amp;quot;;
 //		status = &amp;quot;okay&amp;quot;;
 //		uart {
 //			gpios = &amp;lt;&amp;amp;gpio1 1 0&amp;gt;, &amp;lt;&amp;amp;gpio1 0 0&amp;gt;, &amp;lt;&amp;amp;gpio0 11 0&amp;gt;, &amp;lt;&amp;amp;gpio0 10 0&amp;gt;;
 //		};
 //	};
 
     /* These aliases are provided for compatibility with samples */
     aliases {
         pwm-led0 = &amp;amp;pwm_led0;
     };
 };
 
 &amp;amp;vregmain {
     regulator-initial-mode = &amp;lt;NRF5X_REG_MODE_DCDC&amp;gt;;
 };
 
 &amp;amp;vregradio {
     regulator-initial-mode = &amp;lt;NRF5X_REG_MODE_DCDC&amp;gt;;
 };
 
 &amp;amp;vregh {
     status = &amp;quot;okay&amp;quot;;
 };
 
 &amp;amp;adc {
     status = &amp;quot;okay&amp;quot;;
 };
 
 &amp;amp;gpiote {
     status = &amp;quot;okay&amp;quot;;
 };
 
 &amp;amp;gpio0 {
     status = &amp;quot;okay&amp;quot;;
 };
 
 &amp;amp;gpio1 {
     status = &amp;quot;okay&amp;quot;;
 };
 
 &amp;amp;spi1 {
    compatible = &amp;quot;nordic,nrf-spim&amp;quot;;
    pinctrl-0 = &amp;lt;&amp;amp;spi1_default&amp;gt;;
	pinctrl-1 = &amp;lt;&amp;amp;spi1_sleep&amp;gt;;
    pinctrl-names = &amp;quot;default&amp;quot;, &amp;quot;sleep&amp;quot;;
    status = &amp;quot;okay&amp;quot;;
    cs-gpios = &amp;lt;&amp;amp;gpio0 4 GPIO_ACTIVE_LOW&amp;gt;;  /* Optional CS pin (P0.15) */
};

 &amp;amp;ieee802154 {
     status = &amp;quot;okay&amp;quot;;
 };
 
 zephyr_udc0: &amp;amp;usbd {
     compatible = &amp;quot;nordic,nrf-usbd&amp;quot;;
     status = &amp;quot;okay&amp;quot;;
 };
 
 /* Include default memory partition configuration file */
 #include &amp;lt;common/nordic/nrf5340_cpuapp_partition.dtsi&amp;gt;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;//holyiot_21069_nrf5340_cpuapp.dts

/dts-v1/;
#include &amp;lt;nordic/nrf5340_cpuapp_qkaa.dtsi&amp;gt;
#include &amp;quot;holyiot_21069_cpuapp_common.dtsi&amp;quot;

/ {
	model = &amp;quot;Holyiot 21069 nRF5340 Application Core&amp;quot;;
	compatible = &amp;quot;nordic,holyiot-21069-cpuapp&amp;quot;;

	chosen {
		zephyr,sram = &amp;amp;sram0_image;
		zephyr,flash = &amp;amp;flash0;
		zephyr,code-partition = &amp;amp;slot0_partition;
		zephyr,sram-secure-partition = &amp;amp;sram0_s;
		zephyr,sram-non-secure-partition = &amp;amp;sram0_ns;
		
	};
};

#include &amp;quot;holyiot_21069-cpuapp_partitioning.dtsi&amp;quot;
#include &amp;quot;holyiot_21069-shared_sram.dtsi&amp;quot;


&amp;amp;adc {
	status = &amp;quot;disabled&amp;quot;;
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2023 Your Name
 * SPDX-License-Identifier: Apache-2.0
 */
//holyiot_21069-pinctrl.dtsi

 &amp;amp;pinctrl {
     spi1_default: spi1_default {
         group1 {
             psels = &amp;lt;NRF_PSEL(SPIM_SCK, 0, 7)&amp;gt;,
                     &amp;lt;NRF_PSEL(SPIM_MOSI, 0, 5)&amp;gt;,
                     &amp;lt;NRF_PSEL(SPIM_MISO, 0, 6)&amp;gt;;
         };
     };
 
     spi1_sleep: spi1_sleep {
         group1 {
             psels = &amp;lt;NRF_PSEL(SPIM_SCK, 0, 7)&amp;gt;,
                     &amp;lt;NRF_PSEL(SPIM_MOSI, 0, 5)&amp;gt;,
                     &amp;lt;NRF_PSEL(SPIM_MISO, 0, 6)&amp;gt;;
             low-power-enable;
         };
     };
 };&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// src/main.c
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;zephyr/drivers/spi.h&amp;gt;
#include &amp;lt;zephyr/logging/log.h&amp;gt;
#include &amp;lt;zephyr/sys/printk.h&amp;gt;
#include &amp;lt;zephyr/bluetooth/bluetooth.h&amp;gt;
#include &amp;lt;zephyr/bluetooth/gatt.h&amp;gt;
#include &amp;lt;zephyr/sys/byteorder.h&amp;gt;

LOG_MODULE_REGISTER(test5);
// Define the device labels for SPI and GPIOs
#define SPI1_NODE DT_NODELABEL(spi1)
/* The devicetree node identifier for the &amp;quot;led0&amp;quot; alias. */
#define LED0_NODE DT_ALIAS(gpioled)
#define START_NODE DT_ALIAS(gpiostart)
#define RESET_NODE DT_ALIAS(gpioreset)
#define DRDY_NODE DT_ALIAS(gpiodrdy)
#define GPIO_DRDY_PIN 3

static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
static const struct gpio_dt_spec start = GPIO_DT_SPEC_GET(START_NODE, gpios);
static const struct gpio_dt_spec reset = GPIO_DT_SPEC_GET(RESET_NODE, gpios);


// SPI configuration
#define SPI_OPERATION (SPI_OP_MODE_MASTER | SPI_TRANSFER_MSB | SPI_WORD_SET(8))
 const struct device *spi_dev;
 const struct device *gpio_dev;
 /* SPI configuration */
static const struct spi_config spi_cfg = {
    .frequency = 3000000, /* 1 MHz */
    .operation = SPI_OPERATION,
    .slave = 0,
};
#define BNO086_ROTATION_VECTOR_REPORT_ID 0x05

/* Callback structure */
static struct gpio_callback drdy_cb;

// Task thread stack sizes
#define STACK_SIZE 1024
#define BUFFER_SIZE 224      // Sending buffer size: 224 bytes
#define SAMPLE_SIZE 16       // Fused data sample size: 16 bytes (4 floats)
// Double buffers
static uint8_t buffer1[BUFFER_SIZE];
static uint8_t buffer2[BUFFER_SIZE];
static uint8_t *active_buffer = buffer1;
static uint8_t *processing_buffer = buffer2;
int contador=0;
// Shared variables
static struct k_thread producer_thread;
static struct k_thread consumer_thread;
static K_THREAD_STACK_DEFINE(producer_stack, 2048);
static K_THREAD_STACK_DEFINE(consumer_stack, 2048);
// BLE connection and characteristic handles
static struct bt_conn *current_conn;
static uint16_t gatt_handle = 0x0012; // &amp;lt;-- Set correct handle for BLE characteristic


// Forward declarations
/* Callback function prototype */
/* Function Prototypes */
static void drdy_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins);
static void producer_task(void *arg1, void *arg2, void *arg3);
static void consumer_task(void *arg1, void *arg2, void *arg3);
void configure_gpios(void);
void configure_bno086(void);
void start_ble(void);
void send_data(uint8_t *data);



static void drdy_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins) {
    k_wakeup(&amp;amp;producer_thread);
}


void configure_gpios(void) {

    
   int ret;
   spi_dev = DEVICE_DT_GET(SPI1_NODE);
   if (!device_is_ready(spi_dev)) {
    printk(&amp;quot;Error: SPI1 device is not ready\n&amp;quot;);
    return;
    }

	ret = gpio_pin_configure_dt(&amp;amp;led, GPIO_OUTPUT_ACTIVE);
	if (ret &amp;lt; 0) {
		return;
	}

      // Configure GPIOs
    ret = gpio_pin_configure_dt(&amp;amp;start, GPIO_OUTPUT_ACTIVE);
    if (ret &amp;lt; 0) {
        printk(&amp;quot;Failed to configure LED GPIO\n&amp;quot;);
        return;
    }

    ret = gpio_pin_configure_dt(&amp;amp;reset, GPIO_OUTPUT_ACTIVE);
    if (ret &amp;lt; 0) {
        printk(&amp;quot;Failed to configure START GPIO\n&amp;quot;);
        return;
    }

    gpio_dev=DEVICE_DT_GET(DRDY_NODE);
    if (gpio_dev == NULL) {
        printk(&amp;quot;Failed to get SPI device binding\n&amp;quot;);
        return;
    }
    ret = gpio_pin_configure(gpio_dev, GPIO_DRDY_PIN, GPIO_INPUT | GPIO_PULL_UP);
    if (ret != 0) {
        printk(&amp;quot;Error: Failed to configure DRDY pin\n&amp;quot;);
        return;
    }
    // Set up GPIO callback for DRDY pin
   gpio_init_callback(&amp;amp;drdy_cb, drdy_callback, BIT(GPIO_DRDY_PIN));
    gpio_add_callback(gpio_dev, &amp;amp;drdy_cb);
    gpio_pin_interrupt_configure(gpio_dev, GPIO_DRDY_PIN, GPIO_INT_EDGE_TO_INACTIVE);
    gpio_pin_set_dt(&amp;amp;start, 0);
    
}

void configure_bno086(void){
     uint8_t set_feature_cmd[] = {
        0xFD, // Set Feature Command
        BNO086_ROTATION_VECTOR_REPORT_ID, // Rotation Vector Report ID
        0x00, // Reserved
        0x90, 0x01, 0x00, 0x00, // Sample Rate = 400 Hz (in microseconds)
    };

    struct spi_buf tx_buf = { .buf = set_feature_cmd, .len = sizeof(set_feature_cmd) };
    struct spi_buf_set tx = { .buffers = &amp;amp;tx_buf, .count = 1 };

    spi_write(spi_dev, &amp;amp;spi_cfg, &amp;amp;tx);
    LOG_INF(&amp;quot;BNO086 configured for 400 Hz Rotation Vector&amp;quot;);
}

/* BLE Connection Callback */
static void connected(struct bt_conn *conn, uint8_t err) {
    if (err) {
        LOG_ERR(&amp;quot;Failed to connect (err: %d)&amp;quot;, err);
        return;
    }
    LOG_INF(&amp;quot;Connected&amp;quot;);
    current_conn = conn;
}

/* BLE Disconnection Callback */
static void disconnected(struct bt_conn *conn, uint8_t reason) {
    LOG_INF(&amp;quot;Disconnected (reason: %d)&amp;quot;, reason);
    current_conn = NULL;
}

/* Send Data via BLE */
void send_data(uint8_t *data) {
    if (!current_conn) {
        LOG_WRN(&amp;quot;Not connected&amp;quot;);
        return;
    }
    int err = bt_gatt_write_without_response(current_conn, gatt_handle, data, BUFFER_SIZE, false);
    if (err) {
        LOG_ERR(&amp;quot;Failed to send data (err: %d)&amp;quot;, err);
    } else {
        LOG_INF(&amp;quot;Data sent&amp;quot;);
    }
}



/* BLE Initialization */
void start_ble(void) {
    int err = bt_enable(NULL);
    if (err) {
        LOG_ERR(&amp;quot;Bluetooth init failed (err %d)&amp;quot;, err);
        return;
    }
    LOG_INF(&amp;quot;Bluetooth initialized&amp;quot;);

    static struct bt_conn_cb conn_callbacks = {
        .connected = connected,
        .disconnected = disconnected,
    };
    bt_conn_cb_register(&amp;amp;conn_callbacks);

    struct bt_le_adv_param adv_params = BT_LE_ADV_PARAM_INIT(
        BT_LE_ADV_OPT_CONNECTABLE,
        BT_GAP_ADV_FAST_INT_MIN_2,
        BT_GAP_ADV_FAST_INT_MAX_2,
        NULL
    );

    err = bt_le_adv_start(&amp;amp;adv_params, NULL, 0, NULL, 0);
    if (err) {
        LOG_ERR(&amp;quot;Advertising failed (err: %d)&amp;quot;, err);
    } else {
        LOG_INF(&amp;quot;Advertising started&amp;quot;);
    }
}

// Producer task: Reads data from bno086
/* Producer Thread */
static void producer_task(void *arg1, void *arg2, void *arg3) {
    uint8_t read_data[16];

    while (1) {
        k_sleep(K_FOREVER);

        /* Read Rotation Vector Data */
        struct spi_buf tx_buf = { .buf = NULL, .len = 0 };
        struct spi_buf rx_buf = { .buf = read_data, .len = sizeof(read_data) };
        struct spi_buf_set tx = { .buffers = &amp;amp;tx_buf, .count = 1 };
        struct spi_buf_set rx = { .buffers = &amp;amp;rx_buf, .count = 1 };

        spi_transceive(spi_dev, &amp;amp;spi_cfg, &amp;amp;tx, &amp;amp;rx);

        /* Copy data into active buffer */
        memcpy(active_buffer, read_data, sizeof(read_data));
        contador+=16;
        if (contador &amp;gt;= BUFFER_SIZE) {
        /* Swap buffers if full */
        uint8_t *temp = active_buffer;
        active_buffer = processing_buffer;
        processing_buffer = temp;
        contador=0;
        k_wakeup(&amp;amp;consumer_thread);
        }
    }
}

// BLE Send task: Sends data to the server via notifications
/* Consumer Thread */
static void consumer_task(void *arg1, void *arg2, void *arg3) {
    while (1) {
        k_sleep(K_FOREVER);

        /* Send data via BLE */
        send_data(processing_buffer);
        LOG_INF(&amp;quot;Data sent.&amp;quot;);
    }
}


int main(void)
{
    // Initialize Bluetooth
    configure_gpios();
    configure_bno086();

    // Initialize BLE
    start_ble();
   
    
    // Create threads
    k_thread_create(&amp;amp;producer_thread, producer_stack, STACK_SIZE,
                    producer_task, NULL, NULL, NULL, 5, 0, K_NO_WAIT);
    k_thread_create(&amp;amp;consumer_thread, consumer_stack, STACK_SIZE,
                    consumer_task, NULL, NULL, NULL, 5, 0, K_NO_WAIT);
 return 0;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Could you help me please, I really don&amp;#39;t know how to fix this...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem configuring devicetree nRF5340 new board</title><link>https://devzone.nordicsemi.com/thread/521123?ContentTypeID=1</link><pubDate>Mon, 03 Feb 2025 13:32:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a633a9d-0452-4bfb-a29e-941b19b08a66</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;Could you post your boards files?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>