nRF5340Dk configuration for Unicast Audio server with External I2S CODEC

Hi, 
I am using nRF5340 for my unicast Audio server example where the nRF5340DK is the headset and my mobile device is the audio source. I have taken the unicast audio server example from the Zephyr. Since this DK do not have a I2S Decoder I am using an external I2S DAC (CJMCU-1334 UDA1334A I2S DAC Audio Stereo Decoder Module) . I have added overlay file for configuring the I2S peripheral as follows. I am using SDK 2.7.0

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
&pinctrl {
i2s0_default: i2s0_default {
group1 {
psels = <NRF_PSEL(I2S_SCK_M, 0, 15)>,
<NRF_PSEL(I2S_LRCK_M, 0, 12)>,
<NRF_PSEL(I2S_SDOUT, 0, 13)>,
<NRF_PSEL(I2S_SDIN, 0, 14)>;
};
};
};
&clock {
hfclkaudio-frequency = <11289600>;
};
&i2s0 {
status = "okay";
pinctrl-0 = <&i2s0_default>;
pinctrl-names = "default";
};
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I have also made some changes in the main.c and also for initializing the I2S. The changed portions are also attaching .

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#if defined(CONFIG_LIBLC3)
static void stream_recv_lc3_codec(struct bt_bap_stream *stream,
const struct bt_iso_recv_info *info,
struct net_buf *buf)
{
const uint8_t *in_buf;
uint8_t err = -1;
const int octets_per_frame = buf->len / frames_per_sdu;
void *tx_block;
size_t tx_size;
if (lc3_decoder == NULL) {
printk("LC3 decoder not setup, cannot decode data.\n");
return;
}
if ((info->flags & BT_ISO_FLAGS_VALID) == 0) {
printk("Bad packet: 0x%02X\n", info->flags);
in_buf = NULL;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <zephyr/device.h>
#include <zephyr/drivers/i2s.h>
#include <zephyr/drivers/gpio.h>
#include <nrf.h>
/* Add these global variables for I2S */
static const struct device *i2s_dev;
#define NUM_SAMPLES 32
#define NUM_BLOCKS 8
static bool i2s_configured = false;
K_MEM_SLAB_DEFINE(i2s_tx_mem_slab, BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU) * 2, NUM_BLOCKS, NUM_SAMPLES);
static int init_i2s(void)
{
/* Configure I2S */
struct i2s_config i2s_cfg;
int ret;
/* Get I2S device */
i2s_dev = DEVICE_DT_GET(DT_NODELABEL(i2s0));
if (!device_is_ready(i2s_dev)) {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

with these changes I am able to build and flash the code to the nRF5340 Dk.  I am able to connect with the mobile device with the DK as a audio device, but i have faced some errors at the starting. The errors are also attached.

Ignoring the first error I connected the device and when I played  audio in the source , the error in the below screenshot happened causing the system halt.

I understand the errors happened due to some memory buffer issues. But couldn't able to point out the exact point.