nRF5 SDK is not maintained anymore
More Info: Consider nRF Connect SDK for new designs
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

k_sem_take failed UART interrupts Bluetooth

Hello together,

Im currently doing my bachelor thesis and my task is to develop a user interface that can control a NRF52840 and write some parameters over UART.

Im able receive data that I sent from a python script, but if I want to start advertising it gets interrupted and the error message says: ASSERTION FAIL [error == 0] @ WEST_TOPDIR/zephyr/subsys/bluetooth/host/hci_core.c:305 k_sem_take failed with error -11

I already looked at everything I found relating to that error message. It seems like the UART, which is interrupt driven and fifo, interrupts the bluetooth hci core. I dont have any idea how to fix that, since Im not really experienced with zephyr or embedde programming.

In general: I need some code that reads the UART and does not interrupt the bluetooth functionality of the board. I didn't find a different UART solution that worked, it doesn't has to be interrupt driven or fifo! I hope some of you may help me :)


Thank you in advance for your answers!

The code is as following:

#include <zephyr.h>
#include <zephyr/types.h>
#include <sys/byteorder.h>
#include <stddef.h>
#include <errno.h>
#include <sys/printk.h>
#include <drivers/uart.h>
#include <stdio.h>
#include <string.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/gatt.h>
#include <bluetooth/gatt_dm.h>
#include <bluetooth/conn.h>
#include <bluetooth/uuid.h>

static uint8_t uart_buf[1024];

static uint8_t  mfg_data[] = {0x23,0x66,0x61,0x75,0x38,0xC5,0xAB,0xA9,0xF1,0x47,0x26,0xF7,0x44,0x73,0x2A,0xE2};
static const struct bt_data ad[] = {
  BT_DATA(BT_DATA_UUID128_ALL, mfg_data, 16)
};


static void start_adv(void)
{
  int err;

  err = bt_le_adv_start(BT_LE_ADV_NCONN, ad, ARRAY_SIZE(ad) ,NULL, 0);
  if (err) {
      printk("Advertising failed to start (err %d)\n", err);
      return;
  }
  printk("Advertising successfully started \n");
}

static void uart_cb(const struct device *x, void *user_data)
{
    //printk("*");

  uart_irq_update(x);
  int data_length = 0;

  if (uart_irq_rx_ready(x)) {
    data_length = uart_fifo_read(x, uart_buf, sizeof(uart_buf));
    uart_buf[data_length] = 0;
  }
  char cmp_str[] = "a";
  printk("%s\n", uart_buf);
  if(!strcmp(uart_buf,cmp_str)){

    start_adv();
  }
}

void main(void)
{


  const struct device *uart = device_get_binding("UART_0");

  //uart_irq_callback_set(uart, uart_cb);
  int uart1_data = 0;
  uart_irq_callback_user_data_set(uart, uart_cb, &uart1_data);
  uart_irq_rx_enable(uart);
  printk("UART loopback start!\n");
  int err;

  printk("Starting Scanner/Advertiser Demo\n");

  /* Initialize the Bluetooth Subsystem */

  err = bt_enable(NULL);
  if (err) {
    printk("Bluetooth init failed (err %d)\n", err);
    return;
  }
  if (IS_ENABLED(CONFIG_SETTINGS)) {
      settings_load();
    }

  printk("\nBluetooth initialized \n");
 

   


}
The .conf file is the following:
CONFIG_BT=y
CONFIG_BT_CENTRAL=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_BROADCASTER=y
CONFIG_BT_OBSERVER=y
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_GATT_DM=y
CONFIG_NVS=y
CONFIG_SETTINGS=y

CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_SERIAL=y
CONFIG_UART_ASYNC_API=y
CONFIG_RTT_CONSOLE=y
CONFIG_USE_SEGGER_RTT=y


Parents Reply Children
No Data
Related