Setup:
- nrf connect sdk version v2.1.2
- board: nrf52840DK
- Trying to send a beacons for half a second whenever I get some specific data on uart, and also send data over ble connection to the connected device.
Problem:
- Inside uart callback function the event UART_RX_RDY: does not happen as often as it should (I assume it should happen for every received byte).
- If I comment out all the beacon releated parts I still miss UART_RX_RDY events.
- If I comment out all the beacon releated parts and change CONFIG_BT_EXT_ADV_MAX_ADV_SET from 2 to 1, I start getting all the UART_RX_RDY events.
- If I comment out all the connectable advertisment releated parts, i.e disable ble connection and only advertise a beacon whenever I get specific data on uart
I start getting all the UART_RX_RDY events.
some parts of uart callback relevant part (uart callback function is almost the same as in peripheral_uart sample):
case UART_RX_RDY:
LOG_DBG("UART_RX_RDY");
buf = CONTAINER_OF(evt->data.rx.buf, struct uart_data_t, data);
buf->len += evt->data.rx.len;
if (disable_req) {
return;
}
if (
(evt->data.rx.buf[buf->len - 1] == '\n') ||
(evt->data.rx.buf[buf->len - 1] == '\r')
)
{
disable_req = true;
uart_rx_disable(uart);
}
break;
case UART_RX_BUF_RELEASED:
LOG_DBG("UART_RX_BUF_RELEASED");
buf = CONTAINER_OF(evt->data.rx_buf.buf, struct uart_data_t,
data);
if (buf->len > 0) {
k_fifo_put(&fifo_uart_rx_data, buf);
} else {
k_free(buf);
}
break;
Thread taking care of forwarding the data to beacon or ble nus:
void ble_write_thread(void)
{
/* Don't go any further until BLE is initialized */
k_sem_take(&ble_init_ok, K_FOREVER);
for (;;) {
/* Wait indefinitely for data to be sent over bluetooth */
struct uart_data_t *buf = k_fifo_get(&fifo_uart_rx_data,
K_FOREVER);
int err = send_beacon();
if (err)
{
printk("failed to send beacon");
}
if (bt_nus_send(NULL, buf->data, buf->len))
{
LOG_WRN("Failed to send data over BLE connection");
printf("Failed to send data over BLE connection");
}
k_free(buf);
}
}
K_THREAD_DEFINE(ble_write_thread_id, STACKSIZE, ble_write_thread, NULL, NULL,
NULL, PRIORITY, 0, 0);
NOTE:
Even if I don't get the expected events for what ever reason, once the uart buffer fills up, UART_RX_BUF_REQUEST event happens and I can see all the data including the data for which UART_RX_RDY did not happen. So looks like the data actually gets to the uart buffer only repective event is not sent.
I was wondering it could be because of interrupt priorities, but I could not find documentation or any samples where interrupt priorities are modified, but I have tried the following in app.overlay without any changes in the outcome:
&uart1 {
interrupts = <40 0>;
};